diff options
author | UbitUmarov | 2015-09-01 14:54:35 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 14:54:35 +0100 |
commit | 371c9dd2af01a2e7422ec901ee1f80757284a78c (patch) | |
tree | 058d2a513cacb12efcce0c0df0ae14ad135dbfe2 /OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs | |
parent | remove lixo (diff) | |
parent | dont change camera on crossings (diff) | |
download | opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.zip opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.gz opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.bz2 opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.xz |
bad merge?
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs index 9534ad3..77c10b8 100644 --- a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs +++ b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs | |||
@@ -79,9 +79,13 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
79 | /// <remarks>Based on the algorithm described at http://opensimulator.org/wiki/Terrain_Splatting | 79 | /// <remarks>Based on the algorithm described at http://opensimulator.org/wiki/Terrain_Splatting |
80 | /// Note we create a 256x256 dimension texture even if the actual terrain is larger. | 80 | /// Note we create a 256x256 dimension texture even if the actual terrain is larger. |
81 | /// </remarks> | 81 | /// </remarks> |
82 | <<<<<<< HEAD | ||
82 | public static Bitmap Splat(ITerrainChannel terrain, | 83 | public static Bitmap Splat(ITerrainChannel terrain, |
83 | UUID[] textureIDs, float[] startHeights, float[] heightRanges, | 84 | UUID[] textureIDs, float[] startHeights, float[] heightRanges, |
84 | Vector3d regionPosition, IAssetService assetService, bool textureTerrain) | 85 | Vector3d regionPosition, IAssetService assetService, bool textureTerrain) |
86 | ======= | ||
87 | public static Bitmap Splat(ITerrainChannel terrain, UUID[] textureIDs, float[] startHeights, float[] heightRanges, Vector3d regionPosition, IAssetService assetService, bool textureTerrain) | ||
88 | >>>>>>> avn/ubitvar | ||
85 | { | 89 | { |
86 | Debug.Assert(textureIDs.Length == 4); | 90 | Debug.Assert(textureIDs.Length == 4); |
87 | Debug.Assert(startHeights.Length == 4); | 91 | Debug.Assert(startHeights.Length == 4); |
@@ -195,12 +199,74 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
195 | using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i])) | 199 | using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i])) |
196 | gfx.FillRectangle(brush, 0, 0, 256, 256); | 200 | gfx.FillRectangle(brush, 0, 0, 256, 256); |
197 | } | 201 | } |
202 | else | ||
203 | { | ||
204 | if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) | ||
205 | { | ||
206 | detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256); | ||
207 | } | ||
208 | } | ||
198 | } | 209 | } |
210 | <<<<<<< HEAD | ||
199 | else | 211 | else |
212 | ======= | ||
213 | |||
214 | #region Layer Map | ||
215 | |||
216 | float[,] layermap = new float[256 , 256]; | ||
217 | |||
218 | int xFactor = terrain.Width / 256; | ||
219 | int yFactor = terrain.Height / 256; | ||
220 | |||
221 | for (int y = 0; y < 256; y++) | ||
222 | >>>>>>> avn/ubitvar | ||
200 | { | 223 | { |
201 | if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) | 224 | if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) |
202 | { | 225 | { |
226 | <<<<<<< HEAD | ||
203 | detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256); | 227 | detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256); |
228 | ======= | ||
229 | float height = (float)terrain[x * xFactor, y * yFactor]; | ||
230 | |||
231 | float pctX = (float)x / 255f; | ||
232 | float pctY = (float)y / 255f; | ||
233 | |||
234 | // Use bilinear interpolation between the four corners of start height and | ||
235 | // height range to select the current values at this position | ||
236 | float startHeight = ImageUtils.Bilinear( | ||
237 | startHeights[0], | ||
238 | startHeights[2], | ||
239 | startHeights[1], | ||
240 | startHeights[3], | ||
241 | pctX, pctY); | ||
242 | startHeight = Utils.Clamp(startHeight, 0f, 255f); | ||
243 | |||
244 | float heightRange = ImageUtils.Bilinear( | ||
245 | heightRanges[0], | ||
246 | heightRanges[2], | ||
247 | heightRanges[1], | ||
248 | heightRanges[3], | ||
249 | pctX, pctY); | ||
250 | heightRange = Utils.Clamp(heightRange, 0f, 255f); | ||
251 | |||
252 | // Generate two frequencies of perlin noise based on our global position | ||
253 | // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting | ||
254 | Vector3 vec = new Vector3 | ||
255 | ( | ||
256 | ((float)regionPosition.X + (x * xFactor)) * 0.20319f, | ||
257 | ((float)regionPosition.Y + (y * yFactor)) * 0.20319f, | ||
258 | height * 0.25f | ||
259 | ); | ||
260 | |||
261 | float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f; | ||
262 | float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f; | ||
263 | float noise = (lowFreq + highFreq) * 2f; | ||
264 | |||
265 | // Combine the current height, generated noise, start height, and height range parameters, then scale all of it | ||
266 | float layer = ((height + noise - startHeight) / heightRange) * 4f; | ||
267 | if (Single.IsNaN(layer)) layer = 0f; | ||
268 | layermap[x,y] = Utils.Clamp(layer, 0f, 3f); | ||
269 | >>>>>>> avn/ubitvar | ||
204 | } | 270 | } |
205 | } | 271 | } |
206 | } | 272 | } |
@@ -220,6 +286,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
220 | { | 286 | { |
221 | for (int x = 0; x < 256; x++) | 287 | for (int x = 0; x < 256; x++) |
222 | { | 288 | { |
289 | <<<<<<< HEAD | ||
223 | float height = (float)terrain[x * xFactor, y * yFactor]; | 290 | float height = (float)terrain[x * xFactor, y * yFactor]; |
224 | 291 | ||
225 | float pctX = (float)x / 255f; | 292 | float pctX = (float)x / 255f; |
@@ -261,6 +328,58 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
261 | if (Single.IsNaN(layer)) | 328 | if (Single.IsNaN(layer)) |
262 | layer = 0f; | 329 | layer = 0f; |
263 | layermap[x, y] = Utils.Clamp(layer, 0f, 3f); | 330 | layermap[x, y] = Utils.Clamp(layer, 0f, 3f); |
331 | ======= | ||
332 | // Get handles to all of the texture data arrays | ||
333 | BitmapData[] datas = new BitmapData[] | ||
334 | { | ||
335 | detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat), | ||
336 | detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat), | ||
337 | detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat), | ||
338 | detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat) | ||
339 | }; | ||
340 | |||
341 | int[] comps = new int[] | ||
342 | { | ||
343 | (datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, | ||
344 | (datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, | ||
345 | (datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, | ||
346 | (datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3 | ||
347 | }; | ||
348 | |||
349 | for (int y = 0; y < 256; y++) | ||
350 | { | ||
351 | for (int x = 0; x < 256; x++) | ||
352 | { | ||
353 | float layer = layermap[x, y]; | ||
354 | |||
355 | // Select two textures | ||
356 | int l0 = (int)Math.Floor(layer); | ||
357 | int l1 = Math.Min(l0 + 1, 3); | ||
358 | |||
359 | byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0]; | ||
360 | byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1]; | ||
361 | byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3; | ||
362 | |||
363 | float aB = *(ptrA + 0); | ||
364 | float aG = *(ptrA + 1); | ||
365 | float aR = *(ptrA + 2); | ||
366 | |||
367 | float bB = *(ptrB + 0); | ||
368 | float bG = *(ptrB + 1); | ||
369 | float bR = *(ptrB + 2); | ||
370 | |||
371 | float layerDiff = layer - l0; | ||
372 | |||
373 | // Interpolate between the two selected textures | ||
374 | *(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB)); | ||
375 | *(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG)); | ||
376 | *(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR)); | ||
377 | } | ||
378 | } | ||
379 | |||
380 | for (int i = 0; i < 4; i++) | ||
381 | detailTexture[i].UnlockBits(datas[i]); | ||
382 | >>>>>>> avn/ubitvar | ||
264 | } | 383 | } |
265 | } | 384 | } |
266 | 385 | ||
@@ -352,7 +471,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
352 | b.Dispose(); | 471 | b.Dispose(); |
353 | return result; | 472 | return result; |
354 | } | 473 | } |
474 | <<<<<<< HEAD | ||
355 | 475 | ||
476 | ======= | ||
477 | >>>>>>> avn/ubitvar | ||
356 | public static Bitmap SplatSimple(float[] heightmap) | 478 | public static Bitmap SplatSimple(float[] heightmap) |
357 | { | 479 | { |
358 | const float BASE_HSV_H = 93f / 360f; | 480 | const float BASE_HSV_H = 93f / 360f; |