Noise function optimization (chunk generation now about 1.5x faster :)
git-svn-id: http://mc-server.googlecode.com/svn/trunk@317 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
a40ed8bd0d
commit
1cb756cbf2
@ -129,18 +129,21 @@ float cNoise::CosineNoise2D( float a_X, float a_Y ) const
|
|||||||
return CosineInterpolate( interp1, interp2, FracY );
|
return CosineInterpolate( interp1, interp2, FracY );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float cNoise::CubicNoise2D( float a_X, float a_Y ) const
|
float cNoise::CubicNoise2D( float a_X, float a_Y ) const
|
||||||
{
|
{
|
||||||
const int BaseX = FAST_FLOOR( a_X );
|
const int BaseX = FAST_FLOOR( a_X );
|
||||||
const int BaseY = FAST_FLOOR( a_Y );
|
const int BaseY = FAST_FLOOR( a_Y );
|
||||||
|
|
||||||
const float points[4][4] = {
|
const float points[4][4] =
|
||||||
|
{
|
||||||
IntNoise2D( BaseX-1, BaseY-1 ), IntNoise2D( BaseX, BaseY-1 ), IntNoise2D( BaseX+1, BaseY-1 ), IntNoise2D( BaseX+2, BaseY-1 ),
|
IntNoise2D( BaseX-1, BaseY-1 ), IntNoise2D( BaseX, BaseY-1 ), IntNoise2D( BaseX+1, BaseY-1 ), IntNoise2D( BaseX+2, BaseY-1 ),
|
||||||
IntNoise2D( BaseX-1, BaseY ), IntNoise2D( BaseX, BaseY ), IntNoise2D( BaseX+1, BaseY ), IntNoise2D( BaseX+2, BaseY ),
|
IntNoise2D( BaseX-1, BaseY ), IntNoise2D( BaseX, BaseY ), IntNoise2D( BaseX+1, BaseY ), IntNoise2D( BaseX+2, BaseY ),
|
||||||
IntNoise2D( BaseX-1, BaseY+1 ), IntNoise2D( BaseX, BaseY+1 ), IntNoise2D( BaseX+1, BaseY+1 ), IntNoise2D( BaseX+2, BaseY+1 ),
|
IntNoise2D( BaseX-1, BaseY+1 ), IntNoise2D( BaseX, BaseY+1 ), IntNoise2D( BaseX+1, BaseY+1 ), IntNoise2D( BaseX+2, BaseY+1 ),
|
||||||
IntNoise2D( BaseX-1, BaseY+2 ), IntNoise2D( BaseX, BaseY+2 ), IntNoise2D( BaseX+1, BaseY+2 ), IntNoise2D( BaseX+2, BaseY+2 ),
|
IntNoise2D( BaseX-1, BaseY+2 ), IntNoise2D( BaseX, BaseY+2 ), IntNoise2D( BaseX+1, BaseY+2 ), IntNoise2D( BaseX+2, BaseY+2 ),
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const float FracX = (a_X) - BaseX;
|
const float FracX = (a_X) - BaseX;
|
||||||
@ -154,6 +157,10 @@ float cNoise::CubicNoise2D( float a_X, float a_Y ) const
|
|||||||
return CubicInterpolate( interp1, interp2, interp3, interp4, FracY );
|
return CubicInterpolate( interp1, interp2, interp3, interp4, FracY );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if NOISE_USE_SSE
|
#if NOISE_USE_SSE
|
||||||
float cNoise::SSE_CubicNoise2D( float a_X, float a_Y ) const
|
float cNoise::SSE_CubicNoise2D( float a_X, float a_Y ) const
|
||||||
{
|
{
|
||||||
|
@ -6,15 +6,23 @@
|
|||||||
|
|
||||||
// Do not touch
|
// Do not touch
|
||||||
#if NOISE_USE_INLINE
|
#if NOISE_USE_INLINE
|
||||||
# define __NOISE_INLINE__ inline
|
#ifdef _MSC_VER
|
||||||
|
#define __NOISE_INLINE__ __forceinline
|
||||||
|
#else
|
||||||
|
#define __NOISE_INLINE__ inline
|
||||||
|
#endif // _MSC_VER
|
||||||
#else
|
#else
|
||||||
# define __NOISE_INLINE__
|
#define __NOISE_INLINE__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NOISE_USE_SSE
|
#if NOISE_USE_SSE
|
||||||
# include <emmintrin.h>
|
# include <emmintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cNoise
|
class cNoise
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -55,6 +63,14 @@ private:
|
|||||||
unsigned int m_Seed;
|
unsigned int m_Seed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if NOISE_USE_INLINE
|
#if NOISE_USE_INLINE
|
||||||
# include "cNoise.inc"
|
# include "cNoise.inc"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ float cNoise::CubicInterpolate( float a_A, float a_B, float a_C, float a_D, floa
|
|||||||
float R = a_C - a_A;
|
float R = a_C - a_A;
|
||||||
float S = a_B;
|
float S = a_B;
|
||||||
|
|
||||||
return P*(a_Pct*a_Pct*a_Pct) + Q*(a_Pct*a_Pct) + R*a_Pct + S;
|
return ((P * a_Pct + Q) * a_Pct + R) * a_Pct + S;
|
||||||
}
|
}
|
||||||
|
|
||||||
float cNoise::CosineInterpolate( float a_A, float a_B, float a_Pct ) const
|
float cNoise::CosineInterpolate( float a_A, float a_B, float a_Pct ) const
|
||||||
|
Loading…
Reference in New Issue
Block a user