From e49313202c759f70f6cf1113c8b53471122eb7da Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 29 Jul 2012 20:15:03 +0000 Subject: DistortedVoronoi BiomeGen now uses 4x4 linear interpolation for distortion, 50 % speed increase in the chunk generator with a hardly noticeable change in biome shapes. git-svn-id: http://mc-server.googlecode.com/svn/trunk@708 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/BioGen.cpp | 17 ++++++++++--- source/cNoise.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- source/cNoise.h | 11 +++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/BioGen.cpp b/source/BioGen.cpp index 73529abb6..a43d995df 100644 --- a/source/BioGen.cpp +++ b/source/BioGen.cpp @@ -258,14 +258,25 @@ void cBioGenDistortedVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::B { int BaseZ = cChunkDef::Width * a_ChunkZ; int BaseX = cChunkDef::Width * a_ChunkX; + + // Distortions for linear interpolation: + int DistortX[cChunkDef::Width + 1][cChunkDef::Width + 1]; + int DistortZ[cChunkDef::Width + 1][cChunkDef::Width + 1]; + for (int x = 0; x <= 4; x++) for (int z = 0; z <= 4; z++) + { + Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z]); + } + + IntArrayLinearInterpolate2D(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); + IntArrayLinearInterpolate2D(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); + for (int z = 0; z < cChunkDef::Width; z++) { int AbsoluteZ = BaseZ + z; for (int x = 0; x < cChunkDef::Width; x++) { - int DistX, DistZ; - Distort(BaseX + x, AbsoluteZ, DistX, DistZ); - cChunkDef::SetBiome(a_BiomeMap, x, z, VoronoiBiome(DistX, DistZ)); + // Distort(BaseX + x, AbsoluteZ, DistX, DistZ); + cChunkDef::SetBiome(a_BiomeMap, x, z, VoronoiBiome(DistortX[x][z], DistortZ[x][z])); } // for x } // for z } diff --git a/source/cNoise.cpp b/source/cNoise.cpp index 2dd26e5aa..b4e7a5752 100644 --- a/source/cNoise.cpp +++ b/source/cNoise.cpp @@ -183,6 +183,10 @@ float cNoise::SSE_CubicNoise2D( float a_X, float a_Y ) const } #endif + + + + /****************** * Interpolated (and 1 smoothed) noise in 3-dimensions **/ @@ -216,6 +220,10 @@ float cNoise::CosineNoise3D( float a_X, float a_Y, float a_Z ) const return CosineInterpolate( interp1, interp2, FracZ ); } + + + + float cNoise::CubicNoise3D( float a_X, float a_Y, float a_Z ) const { const int BaseX = FAST_FLOOR( a_X ); @@ -281,6 +289,10 @@ float cNoise::CubicNoise3D( float a_X, float a_Y, float a_Z ) const return CubicInterpolate( yinterp1, yinterp2, yinterp3, yinterp4, FracZ ); } + + + + /****************** * Private **/ @@ -300,6 +312,66 @@ __m128 cNoise::CubicInterpolate4( const __m128 & a_A, const __m128 & a_B, const } #endif + + + + +void IntArrayLinearInterpolate2D( + int * a_Array, + int a_SizeX, int a_SizeY, // Dimensions of the array + int a_AnchorStepX, int a_AnchorStepY // Distances between the anchor points in each direction +) +{ + // First interpolate columns where the anchor points are: + int LastYCell = a_SizeY - a_AnchorStepY; + for (int y = 0; y < LastYCell; y += a_AnchorStepY) + { + int Idx = a_SizeX * y; + for (int x = 0; x < a_SizeX; x += a_AnchorStepX) + { + int StartValue = a_Array[Idx]; + int EndValue = a_Array[Idx + a_SizeX * a_AnchorStepY]; + int Diff = EndValue - StartValue; + for (int CellY = 1; CellY < a_AnchorStepY; CellY++) + { + a_Array[Idx + a_SizeX * CellY] = StartValue + CellY * Diff / a_AnchorStepY; + } // for CellY + Idx += a_AnchorStepX; + } // for x + } // for y + + // Now interpolate in rows, each row has values in the anchor columns + int LastXCell = a_SizeX - a_AnchorStepX; + for (int y = 0; y < a_SizeY; y++) + { + int Idx = a_SizeX * y; + for (int x = 0; x < LastXCell; x += a_AnchorStepX) + { + int StartValue = a_Array[Idx]; + int EndValue = a_Array[Idx + a_AnchorStepX]; + int Diff = EndValue - StartValue; + for (int CellX = 1; CellX < a_AnchorStepX; CellX++) + { + a_Array[Idx + CellX] = StartValue + CellX * Diff / a_AnchorStepX; + } // for CellY + Idx += a_AnchorStepX; + } + } +} + + + + + + + + + + #if NOISE_USE_INLINE # include "cNoise.inc" -#endif \ No newline at end of file +#endif + + + + diff --git a/source/cNoise.h b/source/cNoise.h index 74c2cdd02..6d0a69483 100644 --- a/source/cNoise.h +++ b/source/cNoise.h @@ -74,6 +74,17 @@ private: +/// Linearly interpolates values in the array between the anchor points +extern void IntArrayLinearInterpolate2D( + int * a_Array, + int a_SizeX, int a_SizeY, // Dimensions of the array + int a_AnchorStepX, int a_AnchorStepY // Distances between the anchor points in each direction +); + + + + + #if NOISE_USE_INLINE # include "cNoise.inc" #endif -- cgit v1.2.3