From 2a5de8e0f81cace1372b3fdf65305db15fdfc7c5 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 18 Sep 2025 17:11:53 -0700 Subject: [PATCH] raylib: fix shader antialiasing (#36176) * fix * np --- system/ui/lib/shader_polygon.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/system/ui/lib/shader_polygon.py b/system/ui/lib/shader_polygon.py index 39bc0d5aa4..d03ad5d8c6 100644 --- a/system/ui/lib/shader_polygon.py +++ b/system/ui/lib/shader_polygon.py @@ -99,19 +99,13 @@ float distanceToEdge(vec2 p) { void main() { vec2 pixel = fragTexCoord * resolution; - // Compute pixel size for anti-aliasing - vec2 pixelGrad = vec2(dFdx(pixel.x), dFdy(pixel.y)); - float pixelSize = length(pixelGrad); - float aaWidth = max(0.5, pixelSize * 1.5); - bool inside = isPointInsidePolygon(pixel); - if (inside) { - finalColor = useGradient == 1 ? getGradientColor(pixel) : fillColor; - return; - } + float sd = (inside ? 1.0 : -1.0) * distanceToEdge(pixel); + + // ~1 pixel wide anti-aliasing + float w = max(0.75, fwidth(sd)); - float sd = -distanceToEdge(pixel); - float alpha = smoothstep(-aaWidth, aaWidth, sd); + float alpha = smoothstep(-w, w, sd); if (alpha > 0.0){ vec4 color = useGradient == 1 ? getGradientColor(pixel) : fillColor; finalColor = vec4(color.rgb, color.a * alpha);