Page 1 of 1

Perlin Noise (Tileable)?!

Posted: 18 Jul 2008, 19:27
by Crisium
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

Re: Perlin Noise (Tileable)?!

Posted: 19 Jul 2008, 01:10
by dasapfe
Sådan som jeg forstår det, så burde det være PerlinNoise1D i stedet for IntNoise der skal kaldes:

-code
float f = ( (1.0f-x)*PerlinNoise1D(x)+x*PerlinNoise1D(x-1.0f) );
--code

Re: Perlin Noise (Tileable)?!

Posted: 19 Jul 2008, 08:12
by Crisium
dasapfe wrote:Sådan som jeg forstår det, så burde det være PerlinNoise1D i stedet for IntNoise

der skal kaldes:

-code
float f = ( (1.0f-x)*PerlinNoise1D(x)+x*PerlinNoise1D(x-1.0f) );
--code
PerlineNoise1D is your "main" point for getting the data. Its the method that adds the different
"layers" of noise together.

I have actually fixed the problem by using:

-code
float f = ( (w-x)*IntNoise(x)+x*IntNoise(x-w) ) / w;
--code

where w is the width or in my case the frequency (because I have a range of 0-1)
this works, so I have "kinda" solved the problem.

The only remaining bit is getting the SmoothNoise1 to work, this seems mess up the
repeatability of the noise when I use:

-code
return IntNoise(x)/2.0f + IntNoise(x-1)/4.0f + IntNoise(x+1)/4.0f;
--code

of cousre the frequency is also supplied (it's just temporary hardcoded to a globabl value in my

test)

regards,
Peter