Perlin Noise (Tileable)?!
Posted: 18 Jul 2008, 19:27
Hi Users,
I'm currently try to create a simple 1D perlin noise function. Works ok, but I would like to take
it
to the next step (and thats not 2D yet).. and make it tileable (repeatable)..
So we have a frame of refrence I will post some code here:
-code
float CSulPerlinNoise1D::LinearInterpolate( float a, float b, float t )
{
return a*(1.0f-t) + b*t;
}
float CSulPerlinNoise1D::IntNoise( Sigma::int32 x )
{
x = (x<<13) ^ x;
return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}
float CSulPerlinNoise1D::InterpolatedNoise( float x )
{
Sigma::int32 integer_X = int(x);
float fractional_X = x - integer_X;
/*
v1 = SmoothedNoise1(integer_X)
v2 = SmoothedNoise1(integer_X + 1)
*/
float v1 = IntNoise(integer_X );
float v2 = IntNoise(integer_X+1 );
return LinearInterpolate( v1 , v2 , fractional_X );
}
float CSulPerlinNoise1D::PerlinNoise1D( float x )
{
float total = 0.0f;
Sigma::uint32 i;
for ( i=0; i<m_iOctaves; i++ )
{
float frequency = pow( 2.0f,(Sigma::int32)i );
float amplitude = pow( m_fPersistence,(Sigma::int32)i );
total = total + InterpolatedNoise( x*frequency ) * amplitude;
}
return total;
}
--code
I have researched a lot on the internet at places like:
http://www.cs.cmu.edu/~mzucker/code/per ... h-faq.html
http://freespace.virgin.net/hugo.elias/ ... perlin.htm
and as I understand they information to make it loopable I should implement something like:
-code
float f = ( (1.0f-x)*IntNoise(x)+x*IntNoise(x-1.0f) );
--code]
I assume this method should be in a function that should be called instead of the IntNoise routine
in the InterpolatedNoise method. . . but his doesn't make sense nor does it work because the value
being
used for x in the above formula is outside the -1 - +1 range when using more than one octave.
It does become repeatable if I only use 1 octave! but I want it repeatable on with any amount.
Am I so lucky that we have an expert here?
regards,
Peter
I'm currently try to create a simple 1D perlin noise function. Works ok, but I would like to take
it
to the next step (and thats not 2D yet).. and make it tileable (repeatable)..
So we have a frame of refrence I will post some code here:
-code
float CSulPerlinNoise1D::LinearInterpolate( float a, float b, float t )
{
return a*(1.0f-t) + b*t;
}
float CSulPerlinNoise1D::IntNoise( Sigma::int32 x )
{
x = (x<<13) ^ x;
return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}
float CSulPerlinNoise1D::InterpolatedNoise( float x )
{
Sigma::int32 integer_X = int(x);
float fractional_X = x - integer_X;
/*
v1 = SmoothedNoise1(integer_X)
v2 = SmoothedNoise1(integer_X + 1)
*/
float v1 = IntNoise(integer_X );
float v2 = IntNoise(integer_X+1 );
return LinearInterpolate( v1 , v2 , fractional_X );
}
float CSulPerlinNoise1D::PerlinNoise1D( float x )
{
float total = 0.0f;
Sigma::uint32 i;
for ( i=0; i<m_iOctaves; i++ )
{
float frequency = pow( 2.0f,(Sigma::int32)i );
float amplitude = pow( m_fPersistence,(Sigma::int32)i );
total = total + InterpolatedNoise( x*frequency ) * amplitude;
}
return total;
}
--code
I have researched a lot on the internet at places like:
http://www.cs.cmu.edu/~mzucker/code/per ... h-faq.html
http://freespace.virgin.net/hugo.elias/ ... perlin.htm
and as I understand they information to make it loopable I should implement something like:
-code
float f = ( (1.0f-x)*IntNoise(x)+x*IntNoise(x-1.0f) );
--code]
I assume this method should be in a function that should be called instead of the IntNoise routine
in the InterpolatedNoise method. . . but his doesn't make sense nor does it work because the value
being
used for x in the above formula is outside the -1 - +1 range when using more than one octave.
It does become repeatable if I only use 1 octave! but I want it repeatable on with any amount.
Am I so lucky that we have an expert here?
regards,
Peter