2D Perlin Noise

Started by
22 comments, last by Dmytry 19 years, 9 months ago
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?
Keys to success: Ability, ambition and opportunity.
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?
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?
Keys to success: Ability, ambition and opportunity.
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.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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.
Keys to success: Ability, ambition and opportunity.
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?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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
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^3Weight2D(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.
Keys to success: Ability, ambition and opportunity.
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.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

At this point I have to assume you intention is merely to be difficult and this is a complete waste of my time.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement