GLSL Random Generator

GLSL random / noise

Small noise / random function in GLSL:

varying vec3 v;
float rand(vec2 n)
{
  return 0.5 + 0.5 * 
     fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);
}
void main(void)
{
  float x = rand(v.xz);
  gl_FragColor = vec4(x, x, x, 1.0);
}

Noise function tested in GeeXLab (OpenGL 2):
GLSL random function

One thought on “GLSL Random Generator”

  1. kaoD

    How random is this? Can you point me somewhere for further explanation/analysis of the generator?
    Thanks, awesome trick 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *