Sign in to follow this  
godsenddeath

Perlin Noise?

Recommended Posts

godsenddeath    182
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[B] + 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 this post


Link to post
Share on other sites
Ron AF Greve    900
I've found these articles very helpful

[url]http://www.devmag.org.za/articles/48-HOW-TO-USE-PERLIN-NOISE-IN-YOUR-GAMES/#top1[/url]
[url]http://freespace.virgin.net/hugo.elias/models/m_perlin.htm[/url]

Share this post


Link to post
Share on other sites
phresnel    953
Quote:
Original post by Ron AF Greve
I've found these articles very helpful

[url]http://www.devmag.org.za/articles/48-HOW-TO-USE-PERLIN-NOISE-IN-YOUR-GAMES/#top1[/url]
[url]http://freespace.virgin.net/hugo.elias/models/m_perlin.htm[/url]


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 this post


Link to post
Share on other sites
mrr    150
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 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