跳到主要内容
← Built-In functions

Built-In functions

Distance/Length

忘了其实已经标准化了,中心坐标就是vec(0.5)。

实时渲染 · 2D 片段 GLSL

第 29 课:Distance/Length

我的解:忘了其实已经标准化了,中心坐标就是vec(0.5)。

我的解

uniform vec2 iResolution;

void main() {
  vec2 uv = gl_FragCoord.xy / iResolution.xy;
  vec2 centerPoint = vec2(iResolution.x/2.0,iResolution.y/2.0)/iResolution;

  float dist = distance(centerPoint, uv);
  float result = 1.0 - step(0.25, dist);

  gl_FragColor = vec4(result, 0.0, 0.0, 1.0);
}

复盘笔记

  • 忘了其实已经标准化了,中心坐标就是vec(0.5)。