Skip to content

Instantly share code, notes, and snippets.

@Makio64
Last active May 15, 2016 13:08
Show Gist options
  • Save Makio64/47bff747021d55718185025991c4e1b7 to your computer and use it in GitHub Desktop.
Save Makio64/47bff747021d55718185025991c4e1b7 to your computer and use it in GitHub Desktop.
Optimized version of the Ashima simplex noise 2D
// Optimized by @makio64 - FabriceNeyret2
// Original post on shadertoy: https://www.shadertoy.com/view/4sdGD8
// Original : https://github.com/ashima/webgl-noise/blob/master/src/noise2D.glsl
vec3 permute(vec3 x) { return mod( x*x*34.+x, 289.); }
float snoise(vec2 v) {
vec2 i = floor(v + (v.x+v.y)*.36602540378443),
x0 = v - i + (i.x+i.y)*.211324865405187,
j = step(x0.yx,x0),
x1 = x0-j+.211324865405187,
x3 = x0-.577350269189626;
i = mod(i,289.);
vec3 p = permute( permute( i.y + vec3(0., j.y, 1.))
+ i.x + vec3(0., j.x, 1.)),
m = max( .5 - vec3(dot(x0,x0), dot(x1,x1), dot(x3,x3)), 0.),
x = 2. * fract(p * .024390243902439) - 1.,
h = abs(x) - .5,
a0 = x - floor(x + .5),
g = a0 * vec3(x0.x,x1.x,x3.x)
+ h * vec3(x0.y,x1.y,x3.y);
m = m*m*m*m* ( 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ) );
return .5 + 65. * dot(m, g);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment