   Perlin Noise?
  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 + Z;<span class="cpp-keyword">return</span> _lerp(w, _lerp(v, _lerp(u, grad(ms_p[AA], x, y, z), grad(ms_p[BA],    x - <span class="cpp-number">1</span>, y, z)),_lerp(u, grad(ms_p[AB], x, y - <span class="cpp-number">1</span>, z),    grad(ms_p[BB], x - <span class="cpp-number">1</span>, y - <span class="cpp-number">1</span>, z))),   _lerp(v, _lerp(u, grad(ms_p[AA + <span class="cpp-number">1</span>], x, y, z - <span class="cpp-number">1</span>),    grad(ms_p[BA + <span class="cpp-number">1</span>], x - <span class="cpp-number">1</span>, y, z - <span class="cpp-number">1</span>)),   _lerp(u, grad(ms_p[AB + <span class="cpp-number">1</span>], x, y - <span class="cpp-number">1</span>, z - <span class="cpp-number">1</span>),   grad(ms_p[BB + <span class="cpp-number">1</span>], x - <span class="cpp-number">1</span>, y - <span class="cpp-number">1</span>, z - <span class="cpp-number">1</span>))));</pre></div><!–ENDSCRIPT–>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.<!–EDIT–><span class=editedby><!–/EDIT–>[Edited by - godsenddeath on April 25, 2010 5:20:53 PM]<!–EDIT–></span><!–/EDIT–>
  I'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;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.htmOne disclaimer for the second link: While Hugo Elias does a great job at explaining noise, it is actually value noise, not Perlin noise.   ;  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];  These are some good slides about perlin noice.http://www.noisemachine.com/talk1/index.html