跳到主要内容
← Math

Math

Axis Aligned Line

shader-learning 自学第 10 课:Axis Aligned Line

实时渲染 · 2D 片段 GLSL

第 10 课:Axis Aligned Line

我的解

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;

  float x = cos(iTime);
  float y = sin(iTime);
  float yes = 0.0;
  yes += step(x - 0.2, uv.x) * step(uv.x, x + 0.2);
 yes += step(y - 0.2, uv.y) * step(uv.y, y + 0.2);

  vec3 result = mix(vec3(0.12), vec3(1.0, 0.3, 0.3), yes);

  gl_FragColor = vec4(result, 1.0);
}