>>8082708,1
Wait, I'm actually retarded. The code is
float circle_sdf(vec2 uv, vec2 center, float radius) {
vec2 centered = uv - center;
return length(centered) - radius;
}
float circle_mask_aa(vec2 uv, vec2 center, float radius) {
float dist = circle_sdf(uv, center, radius);
float aa = fwidth(dist);
return 1.0 - smoothstep(radius - aa, radius + aa, dist);
}
but if I run
void main() {
vec2 uv = normalize_uv();
vec3 bg = vec3(0.0);
float radius = .25;
vec2 center1 = vec2(-0.5, 0.5);
vec3 color1 = vec3(1.0, 1.0, 1.0);
float mask1 = circle_mask(uv, center1, radius);
vec2 center2 = vec2(0.5, 0.5);
vec3 color2 = vec3(0.0, 1.0, 1.0);
float mask2 = circle_mask(uv, center2, radius);
vec2 center3 = vec2(0.5, -0.5);
vec3 color3 = vec3(1.0, 0.0, 1.0);
float mask3 = circle_mask(uv, center3, radius);
vec2 center4 = vec2(-0.5, -0.5);
vec3 color4 = vec3(1.0, 1.0, 0.0);
float mask4 = circle_mask(uv, center4, radius);
bg = mix(bg, color1, mask1);
bg = mix(bg, color2, mask2);
bg = mix(bg, color3, mask3);
bg = mix(bg, color4, mask4);
fragColor = vec4(bg, 1.0);
}
and make the canvas a square, I get circles covering each quadrant, but the diameter should be .5, and the coordinates are being normalized to [-1, 1], so they should only cover half the quadrant.
What am I doing wrong? I think I assumed I'd need comparatively equal values to the radius of the circle for points I wanted to fill in, but I don't need that. I'm already getting values < 0 for points inside the circle, and values > 0 for those outside, so yeah, the only values of dist I need to care about are those close to the edge to antialias them. If I put the left edge at radius - aa
, I'm actually doubling the radius of the circle. So the function shold be