raylib: fix shader antialiasing (#36176)

* fix

* np
This commit is contained in:
Shane Smiskol
2025-09-18 17:11:53 -07:00
committed by GitHub
parent d05cb31e2e
commit 2a5de8e0f8
+5 -11
View File
@@ -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);
float sd = -distanceToEdge(pixel);
float alpha = smoothstep(-aaWidth, aaWidth, sd);
// ~1 pixel wide anti-aliasing
float w = max(0.75, fwidth(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);