跳到主要内容
← Noise

Noise

Random 2D

shader-learning 自学第 3 课:Random 2D

实时渲染 · 2D 片段 GLSL

第 3 课:Random 2D

实现

uniform vec2 iResolution;

float random(vec2 point){
  float r = dot(point, vec2(12.34, 56.78));
  return fract(sin(r)* 1234.5678) * 2.0 - 1.0;
}

void main() {
  vec2 uv = gl_FragCoord.xy / iResolution.xy;

  float noiseValue = random(uv);
  noiseValue = noiseValue * 0.5 + 0.5;

  gl_FragColor = vec4(vec3(noiseValue), 1.0);
}