Skip to content

Instantly share code, notes, and snippets.

@joelpryde
Created March 14, 2013 16:30
Show Gist options
  • Save joelpryde/5162828 to your computer and use it in GitHub Desktop.
Save joelpryde/5162828 to your computer and use it in GitHub Desktop.
GLSL Noise 2
float rand( float n )
{
return fract(sin(n*443.23)*43758.5453);
}
float hash( float n )
{
return fract(sin(n)*43758.5453123);
}
float noise( in vec3 x )
{
vec3 p = floor(x);
vec3 f = fract(x);
f = f*f*(3.0-2.0*f);
float n = p.x + p.y*57.0 + 113.0*p.z;
float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
mix(mix( hash(n+113.0), hash(n+114.0),f.x),
mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment