跳到主要内容
← Math

Math

Unit Vector

shader-learning 自学第 5 课:Unit Vector

实时渲染 · 2D 片段 GLSL

第 5 课:Unit Vector

我的解

uniform float iTime;
uniform vec2 iResolution;

void main() {
  vec2 uv = gl_FragCoord.xy / iResolution.xy;
  uv *= 2.0;
  uv -= 1.0;
  uv.x *= iResolution.x / iResolution.y;

  vec2 vc1 = -normalize(vec2(0.75, 0.0) - uv);
  vec2 vc2 = -normalize(vec2(-0.75, 0.0) - uv);

  float c1 = 1.0 - smoothstep(0.59, 0.61, distance(vec2(0.75, 0.0), uv));
  float c2 = 1.0 - smoothstep(0.59, 0.61, distance(vec2(-0.75, 0.0), uv));

  gl_FragColor = vec4(vec3(c1*vc1.x + c2*vc2.y), 1.0);
}