Skip to content

Instantly share code, notes, and snippets.

@nicoptere
Created May 2, 2015 14:11
Show Gist options
  • Save nicoptere/9838755b90c10d740054 to your computer and use it in GitHub Desktop.
Save nicoptere/9838755b90c10d740054 to your computer and use it in GitHub Desktop.
periodic noise by Iñigo Quilez from ShaderToy
float hash( float n )
{
return fract(sin(n)*43758.5453);
}
float noise( vec3 x )
{
// The noise function returns a value in the range -1.0f -> 1.0f
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;
return mix( mix( mix( hash(n), hash(n+1.), f.x ), mix( hash(n+57.), hash(n+58.),f.x ), f.y ),
mix( mix( hash(n+113.0), hash(n+114.),f.x), mix( hash(n+170.), hash(n+171.),f.x ), f.y ),
f.z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment