Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perlin noise gradient function

Tags:

perlin-noise

I'm looking to adapt the 3D Perlin noise algorithm to lower dimensions, but I'm having trouble with the gradient function, since I don't fully understand the reasoning.

The original Perlin gradient function takes four arguments: a hash and a three-dimensional coordinate (x, y, z). The result of the function is returned based on the value of hash mod 16, as listed below.

  • 0: x + y
  • 1: -x + y
  • 2: x - y
  • 3: -x - y
  • 4: x + z
  • 5: -x + z
  • 6: x - z
  • 7: -x - z
  • 8: y + z
  • 9: -y + z
  • 10: y - z
  • 11: -y - z
  • 12: y + x
  • 13: -y + z
  • 14: y - x
  • 15: -y - z

The return values from 0 to 11 make a kind of pattern, since every combination is represented once. The last four, however, are duplicates. Why were they chosen to fit the last four return values? And what would be the analagous cases with two (x, y) and one (x) dimensions?

like image 572
Matthew Piziak Avatar asked May 24 '12 01:05

Matthew Piziak


People also ask

What is the function for Perlin noise?

Perlin noise can be used to generate various effects with natural qualities, such as clouds, landscapes, and patterned textures like marble. Perlin noise has a more organic appearance because it produces a naturally ordered (“smooth”) sequence of pseudo-random numbers.

What is the algorithm for Perlin noise?

floor(y); let topRight = new Vector2(xf-1.0, yf-1.0); let topLeft = new Vector2(xf, yf-1.0); let bottomRight = new Vector2(xf-1.0, yf); let bottomLeft = new Vector2(xf, yf); Generally, in Perlin noise implementations, the noise will “wrap” after every multiple of 256 (let's call this number w), meaning it will repeat.

Does Minecraft use Perlin or simplex noise?

Minecraft is specifically using Perlin noise calculations, like the kind you'd use to create a rough-looking texture for a 3D model. It starts out on a very broad level, painting a basic topographical map, and adds "noise" through finer terrain details like lakes, shrubbery and animals.

Is simplex noise better than Perlin noise?

The advantages of simplex noise over Perlin noise: Simplex noise has lower computational complexity and requires fewer multiplications. Simplex noise scales to higher dimensions (4D, 5D) with much less computational cost: the complexity is.


1 Answers

... is late answer better than none? ;-)

The grad function in the "improved noise" implementation calculates a dot product between the vector x, y, z and a pseudo random gradient vector.

In this implementation, the gradient vector is selected from 12 options. They drop uniformity of the selection and add numbers 12 to 15, because it is faster to do hash & 15 than hash % 12

For a 2D perlin noise I have used only 4 gradient vectors without any visible problems like this:

return ((hash & 1) ? x : -x) + ((hash & 2) ? y : -y);
like image 184
cube Avatar answered Oct 01 '22 23:10

cube