Sign in to follow this  
manhaeve

Perlin noise returning negative values

Recommended Posts

manhaeve    100
Hi there, Yesterday I tried to create a Perlin Noise renderer (not just smoothing some non-coherent noise, the real Perlin Noise). But I've got one problem (I think). It returns negatives values too, I get this:
-0.531430 -0.304296 -0.453411 -0.269242 -0.348075 -0.503428 0.162178 -0.853760 0.247756 -0.927743 
-0.518449 0.030829 -0.497464 -0.031799 -0.600330 -0.083220 -0.552453 -0.381019 0.211970 -0.879312 
0.096631 -0.452728 -0.145538 -0.362615 -0.451238 0.194150 -0.877699 0.743735 -1.205960 0.704199 
-0.326923 -0.070512 -0.067368 -0.565217 0.314513 -0.956321 0.429882 -0.969025 0.146509 0.005914 
0.083092 -0.307873 -0.260689 -0.063186 -0.633486 -0.046595 -0.202329 -0.331819 0.158357 -0.670215 
-0.639073 0.159417 -0.448775 -0.011413 -0.479511 -0.078879 -0.514521 -0.319014 -0.172277 -0.798408 
0.353502 -0.768281 0.221719 -0.665387 -0.260234 -0.273335 -0.925923 0.706970 -1.555708 1.119143 
-0.933424 0.269768 -0.646367 -0.258085 0.113905 -1.259128 0.589676 -1.712595 0.559414 -1.247891 
0.292917 -0.661902 -0.034259 -0.260702 -0.865456 -0.055030 -1.028565 -0.163953 -0.290148 -0.504978 
-1.118300 0.350244 -0.884967 0.360857 -0.797072 -0.060024 -0.732539 -0.505994 -0.416523 -1.003069 


This is my code:
double noise(int getx, int gety,int seed, int w)
{
 double x,y;
 double addx=((double)(rand()%99))/100;
 double addy=((double)(rand()%99))/100;
 x=(double) getx+addx;
 y=(double) gety+addy;
 double x00,y00;
 g(getx,gety,x00,y00,w);
 double x01,y01;
 g(getx,gety+1,x01,y01,w);
 double x10,y10;
 g(getx+1,gety,x10,y10,w);
 double x11,y11;
 g(getx+1,gety+1,x11,y11,w);
 double s,t,u,v;
 s=(x00*(x-(double)getx))+(y00*(y-(double)gety)); 
 t=(x10*(x-(double)(getx+1)))+(y10*(y-(double)gety));
 u=(x01*(x-(double)getx))+(y01*(y-(double)(gety+1)));
 v=(x11*(x-(double)(getx+1)))+(y11*(y-(double)(gety+1)));
 double Sx = (3*pow(addx,2.0))-(2*pow(addx,3.0));
 double Sy = (3*pow(addy,2.0))-(2*pow(addy,3.0));
 double a=s+Sx*(t-s);
 double b=u+Sx*(v-u);
 double z=a+Sy*(b-a);
 return z;
}

Am I doing something wrong? Greetings Robin

Share this post


Link to post
Share on other sites
wodinoneeye    1689


Isnt it supposed to make smaller and smaller changes as its called recursively???

I see w (weight?) being passed but not used??

The magnitude of the random variances is supposed to get smaller and smaller...

Share this post


Link to post
Share on other sites
manhaeve    100
W gets used at the G function to ensure pseudorandom gradients.

You talk about the magnituded getting smaller, but I didn't see anything like that at the Perlin Math FAQ. I've gotten it into RGB values but it doesn't look like Perlin Noise. And while I'm typing this I get an euraka moment. I thing I've found my problem.

Greetings

Robin

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this