Jump to content
  • Advertisement
Sign in to follow this  
LilBudyWizer

2D Perlin Noise

This topic is 5156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have trouble seeing how you ever get outside the range of +/- 1/sqrt(2) with Perlin noise. The maximum value for the dot product is going to be if the gradiant is pointing right at the point. So the displacement from the corners is the maximum corner values for a point. The weighted average of those is the maximum value the noise function could produce for that point. That allows you to create a function that returns the maximum possible Perlin noise value for a given (u,v) coordinate. Plot that height field and the maximum is at (0.5,0.5) and is 1/sqrt(2). That drops off rapidly to 0 at the corners and not so rapidly to 0.5 at the mid-points of the sides. Am I doing something wrong here?

Share this post


Link to post
Share on other sites
Advertisement
if you want a larger number, multiply by 2. or 20. or 276548.

If you want to remove the zero points, make 2 lots of perlin noise, offset one of them by 0.5,0.5, and add them together.

Sounds like you've got the noise function fine, but the question isn't really sensible?

Share this post


Link to post
Share on other sites
So if I want numbers from 0 to 255 then what do I multiply by so that it is possible to get 0 and 255, but never get numbers <0 or >255? Does that make more sense?

Share this post


Link to post
Share on other sites
If your range is +/- 1/sqrt(2), then to convert to 0-255, add 1/sqrt(2) which will move your range to 0-(2/sqrt(2)). To get to 255, just multiply by sqrt(2) * 127.5. Note that if you do this in single-precision floating point, you may end up with some rounding error; even double-precision may not work perfectly. It'd probably be in your best interests to clamp the values to 0-255 manually after the conversion just to be safe.

Share this post


Link to post
Share on other sites
The question was actually what is the range of the perlin noise function. More precisely it was whether I made any mistakes in how I concluded that the range is -1/sqrt(2) to 1/sqrt(2) since I've seen a number of papers state the range as -1 to 1.

Share this post


Link to post
Share on other sites
That depends a lot on the actual function. I've seen many, many different noise implementations that describe themselves as Perlin noise, but very few use his original function. Perhaps you could post some code?

Share this post


Link to post
Share on other sites
You are suppose to get a number between 1 and -1.

Let's suppose they are stored in a 2-dimensional array, called noisedata[100][100]. The data in this array is all between 1 and -1.

so here is what you do to get a range of 0 - 255.


// Run two "for" loops to access each variable in the array.
for(int i = 0; i < 100; i++)
{
for(int j = 0; j < 100; j++)
{
noisedata[j] += 1;
noisedata[j] = (noisedata[j]/2);
noisedata[j] *= 255;
}
}



this should give you noise in the range of 0 - 255

Sagar Indurkhya

Share this post


Link to post
Share on other sites
Well, I'm playing with this in MathCAD so there is a worksheet rather than code. The following will give you the basic idea though.

[SOURCE]

Weight1D(t) = 6t^5-15t^4+10t^3

Weight2D(u,v) = Weight1D(u)*Weight1D(v)

MaxPerlin(u,v) = Weight2D(1-u,1-v)*|(u ,v )| +
Weight2D(u ,1-v)*|(1-u,v )| +
Weight2D(1-u,v )*|(u ,1-v)| +
Weight2D(u ,v )*|(1-u,1-v)|

[/SOURCE]


Now, in code I wouldn't use the easing functions that way since it is eight evaluations of a fifth order polynomial instead of two. MathCAD carries expressions so it isn't fast no matter what thus it makes little differance there. It is the same as a bilinear interpolation modified to use this weighting function. I have expanded that out, collected terms and factored the coefficents on terms to verify they are equivalent.

Also this is intended to calculate the maximum possible noise at a given (u,v) coordinate within a cell. An actual Perlin noise function would use G.(P-Q) where G is a random unit gradiant assigned to a corner, Q is the coordinates of the corner and P is the point being evaluated. I want the max so G points in the direction of P from Q and since G is a unit vector the dot product is |P-Q|, i.e. |1||P-Q|cos(0).

I am fairly confident of the calculation. Just because I am absolutely, positively, beyond any doubt certain it is correct does not mean it is correct though. I am not that certain it is correct and a lot of papers say it produces noise in the range of -1 to 1 which is my main source of doubt.

Share this post


Link to post
Share on other sites
Perhaps I'm just not seeing it because I've never used MathCAD, but I'm really not sure how this blurb is Perlin noise. Perlin noise relies on having a set of randomly generated seed points; beyond that it's really just an interpolation function and a lookup into the seed table.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!