跳到主要内容
← Math

Math

Vector Translation

向量位移

实时渲染 · 2D 片段 GLSL

第 2 课:Vector Translation

我的解:向量位移

我的解

uniform vec2 iResolution;

float circle(vec2 c, vec2 uv, float r) {
  return 1.0 - smoothstep(r * 0.9, r, distance(c, uv));
}

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

  vec2 start = vec2(-0.9, -0.5);

  vec2 move = vec2(1.5, 0.75);
  vec2 pos = start + move; // FIX IT

  vec3 result = mix(vec3(0.12), vec3(1.0, 0.3, 0.3), circle(pos, uv, 0.3));

  gl_FragColor = vec4(result, 1.0);
}

复盘笔记

  • 向量位移