跳到主要内容
← Built-In functions

Built-In functions

Aspect Ratio

思路一致,他的更好用

实时渲染 · 2D 片段 GLSL

第 30 课:Aspect Ratio

我的解:思路一致,他的更好用

我的解

uniform vec2 iResolution;

void main() {
  vec2 uv = gl_FragCoord.xy / iResolution.xy ;
  float ratio = iResolution.x / iResolution.y;
  vec2 adjustedUV = vec2(uv.x * ratio, uv.y);

  float dist = distance(adjustedUV, vec2(0.5* ratio,0.5));
  float t = 1.0 - step(0.25, dist);

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

复盘笔记

  • 思路一致,他的更好用
  • <2025/05/14>
  • ==记录时间: 5月18日 2025, 04:41 下午==