# Perlin Noise?

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

## Recommended Posts

I've been looking at perlin noise for the last couple days, but I can't find an example that I can fully understand. This is the best explanation I've found, but I've got a couple questions. 1) What exactly is the lattice grid and gradient values? EDIT: I figured it out. 2) What is the reason for this function? Is it just to add more randomness? EDIT: Figured this out, this function selects one of 16 gradient vectors based on the low 4 bits of the bash value static double grad(int hash, double x, double y, double z) { int h = hash & 15; double u = h < 8 ? x : y; double v = h < 4 ? y : h == 12 || h == 14 ? x : z; return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); } 3) I fully understand the permutation table, and most of the noise code, but what does this code section accomplish?

int A = ms_p[X    ] + Y, AA = ms_p[A] + Z, AB = ms_p[A + 1] + Z;
int B = ms_p[X + 1] + Y, BA = ms_p + Z, BB = ms_p[B + 1] + Z;

return _lerp(w, _lerp(v, _lerp(u, grad(ms_p[AA], x, y, z), grad(ms_p[BA],
x - 1, y, z)),_lerp(u, grad(ms_p[AB], x, y - 1, z),
grad(ms_p[BB], x - 1, y - 1, z))),
_lerp(v, _lerp(u, grad(ms_p[AA + 1], x, y, z - 1),
grad(ms_p[BA + 1], x - 1, y, z - 1)),
_lerp(u, grad(ms_p[AB + 1], x, y - 1, z - 1),
grad(ms_p[BB + 1], x - 1, y - 1, z - 1))));


4)For those of you familiar with Perlin's code, is the constant size he uses for the perm table (512) significant? Or can it be any even number or power of 2? I've been staring at it for far too long and it's just not clicking. Thanks. [Edited by - godsenddeath on April 25, 2010 5:20:53 PM]

##### Share on other sites
Quote:
 Original post by Ron AF GreveI've found these articles very helpfulhttp://www.devmag.org.za/articles/48-HOW-TO-USE-PERLIN-NOISE-IN-YOUR-GAMES/#top1http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

One disclaimer for the second link: While Hugo Elias does a great job at explaining noise, it is actually value noise, not Perlin noise.

##### Share on other sites
It was a long time I analyzed this code. But all the lerps there basically interpolates the gradients from the 8 corners of a cell to the point of interest within the cell.

Easiest to understand if you think about the 1D case there you randomize the gradient at regular intervals and fit (interpolate) a function that goes through each point with the gradient at each point. And then you go in and read your values from this function.

[Edited by - mrr on April 25, 2010 2:56:11 PM]

##### Share on other sites
These are some good slides about perlin noice.

http://www.noisemachine.com/talk1/index.html

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 9
• 9
• 9
• 46
• ### Forum Statistics

• Total Topics
631751
• Total Posts
3002077
×