1
0
Fork 0

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
This commit is contained in:
madmaxoft@gmail.com 2012-07-29 20:15:03 +00:00
parent 41e7452dcc
commit e49313202c
3 changed files with 98 additions and 4 deletions

View File

@ -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
}

View File

@ -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
#endif

View File

@ -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