FLOAT32 CFrmPerlin::TileableNoise2D(const FLOAT32 x, const FLOAT32 y, const FLOAT32 w, const FLOAT32 h)
{
    return ( Noise2D( x,     y     ) * ( w - x )* ( h - y ) +
             Noise2D( x - w, y     ) *       x  * ( h - y ) +
             Noise2D( x,     y - h ) * ( w - x )*       y   +
             Noise2D( x - w, y - h ) *       x  *       y   ) / ( w * h );
}
Beispiel #2
0
float
vsPerlinOctave::InterpolatedNoise2D(float x, float y, int wrap)
{
	int integer_X    = vsFloor(x);
	float fractional_X = x - integer_X;

	int integer_Y    = vsFloor(y);
	float fractional_Y = y - integer_Y;

	vsAssert( fractional_X >= 0.f && fractional_X < 1.f, "Maths error:  fractional_X out of bounds!" );
	vsAssert( fractional_Y >= 0.f && fractional_Y < 1.f, "Maths error:  fractional_Y out of bounds!" );

	fractional_X = (3.0f * fractional_X * fractional_X) - (2.0f * fractional_X * fractional_X * fractional_X);
	fractional_Y = (3.0f * fractional_Y * fractional_Y) - (2.0f * fractional_Y * fractional_Y * fractional_Y);

	float v1 = Noise2D(integer_X,     integer_Y, wrap);
	float v2 = Noise2D(integer_X + 1, integer_Y, wrap);
	float v3 = Noise2D(integer_X,     integer_Y + 1, wrap);
	float v4 = Noise2D(integer_X + 1, integer_Y + 1, wrap);

	float i1 = vsInterpolate(fractional_X, v1 , v2);
	float i2 = vsInterpolate(fractional_X, v3 , v4);

	return vsInterpolate(fractional_Y, i1 , i2);
}
Beispiel #3
0
double SmoothedNoise2D (long x, long y)
{
double corners = (Noise2D (x-1, y-1) + Noise2D (x+1, y-1) + Noise2D (x-1, y+1) + Noise2D (x+1, y+1)) / 16;
double sides = (Noise2D (x-1, y) + Noise2D (x+1, y) + Noise2D (x, y-1) + Noise2D (x, y+1)) / 8;
double center = Noise2D (x, y) / 4;
return corners + sides + center;
}
Beispiel #4
0
/*
 * Tileable 2D noise
 */
float Noise::TileNoise2D(float x, float y, float width, float height)
{
    float invX = width  - x;
    float invY = height - y;
    return (
        Noise2D(x,    y)    * invX * invY +
        Noise2D(invX, y)    * x    * invY +
        Noise2D(invX, invY) * x    * y +
        Noise2D(x,    invY) * invX * y
        ) / (width * height);
}
Beispiel #5
0
float
vsPerlinOctave::SmoothedNoise2D(int x, int y, int wrap)
{
	float corners = ( Noise2D(x-1, y-1, wrap)+Noise2D(x+1, y-1, wrap)+Noise2D(x-1, y+1, wrap)+Noise2D(x+1, y+1, wrap) ) / 16.f;
	float sides   = ( Noise2D(x-1, y, wrap)  +Noise2D(x+1, y, wrap)  +Noise2D(x, y-1, wrap)  +Noise2D(x, y+1, wrap) ) /  8.f;
	float center  =  Noise2D(x, y, wrap) / 4.f;
	return corners + sides + center;
}
Beispiel #6
0
eeFloat cPerlinNoise::SmoothedNoise2D(eeFloat x, eeFloat y) {
	register Int32	tx	= static_cast<Int32>( x );
	register Int32	ty	= static_cast<Int32>( y );

	eeFloat corners = ( Noise2D( tx - 1, ty - 1	) + Noise2D( tx + 1, ty - 1	) + Noise2D( tx - 1	, ty + 1 ) + Noise2D( tx + 1, ty + 1 ) ) / 16;
	eeFloat sides   = ( Noise2D( tx - 1, ty		) + Noise2D( tx + 1, ty		) + Noise2D( tx		, ty - 1 ) + Noise2D( tx	, ty + 1 ) ) /  8;
	eeFloat center  = Noise2D( tx, ty ) / 4;

	return corners + sides + center;
}
FLOAT32 CFrmPerlin::Turbulence2D( const FLOAT32 x, const FLOAT32 y,
                                  FLOAT32 fFrequency, UINT32 nNumOctaves,
                                  FLOAT32 fAmplitude, FLOAT32 fPersistence )
{
    FLOAT32 fTotal = 0.0f;

    for( UINT32 i=0; i<nNumOctaves; i++ )
    {
        fTotal += Noise2D( fFrequency * x, fFrequency * y ) * fAmplitude;
        fFrequency *= 2.0f;
        fAmplitude *= fPersistence;
    }
    
    return fTotal;
}
Beispiel #8
0
			float ValueNoise2D(float x, float y, float amplitude, float wavelength, int octaves, float factor, int seed)
			{
				float sum = 0.0f;
				float range_adjust = 0.0f;
				float temp_amp = 1.0f;

				for(int i = 0; i < octaves; i ++)
				{
					sum += temp_amp * Noise2D(x / wavelength, y / wavelength, seed);
					wavelength *= factor;
					temp_amp *= factor;
					range_adjust += temp_amp;
				}

				return amplitude * (sum / range_adjust);
			}
double terra::PerlinNoise::Noise2D(double X, double Y, unsigned int Octaves, double Persistence, double ScalingX, double ScalingY){
	// Exit if there are no octaves to process
	if (Octaves == 0)
		return 0.;

	// Fancy math time! Now in 2D!
	int TruncatedX = static_cast<int>(X);
	int TruncatedY = static_cast<int>(Y);
	double TopLeft = GetSmooth(TruncatedX, TruncatedY);
	double TopRight = GetSmooth(TruncatedX+1, TruncatedY);
	double BottomLeft = GetSmooth(TruncatedX, TruncatedY+1);
	double BottomRight = GetSmooth(TruncatedX+1, TruncatedY+1);
	double Top = Interpolate(TopLeft, TopRight, X-TruncatedX);
	double Bottom = Interpolate(BottomLeft, BottomRight, X-TruncatedX);

	// Handle multiple octaves
	if (Octaves > 1)
		return (Interpolate(Top, Bottom, Y-TruncatedY)+Persistence*Noise2D(ScalingX*X, ScalingY*Y, Octaves-1, Persistence))/(1.+Persistence);
	else
		return Interpolate(Top, Bottom, Y-TruncatedY);
}
Beispiel #10
0
/*
 * Looping 2D noise
 */
float Noise::LoopNoise2D(float x, float y, float yPeriod)
{
    return ((yPeriod - y) * Noise2D(x,y) + 
        y * Noise2D(x, yPeriod - y)) / yPeriod;
}