画圆

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

posted @ 2025-10-12 21:26  MrZivChu  阅读(2)  评论(0)    收藏  举报
分享按钮