画圆
void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord/iResolution.xy; // 标准化坐标 [0,1] uv.x *= iResolution.x / iResolution.y; // 修正宽高比 vec2 center = vec2(0.5,0.5); float dist = length(uv - center); float radius = 0.3; // 有锯齿版本 //float circle = 1.0 - step(radius, dist); // 正常版本 float smoothness = 0.01; float circle = 1.0 - smoothstep(radius - smoothness, radius + smoothness, dist); // fwidth版本 // float edgeWidth = fwidth(dist); // float circle = 1.0 - smoothstep(radius - edgeWidth, radius + edgeWidth, dist); fragColor = vec4(vec3(circle),1.0); }
https://www.shadertoy.com/view/wXXyDf

浙公网安备 33010602011771号