raylib: fix shader antialiasing (#36176)

* fix

* np
master
Shane Smiskol 16 hours ago committed by GitHub
parent d05cb31e2e
commit 2a5de8e0f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      system/ui/lib/shader_polygon.py

@ -99,19 +99,13 @@ float distanceToEdge(vec2 p) {
void main() { void main() {
vec2 pixel = fragTexCoord * resolution; 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); bool inside = isPointInsidePolygon(pixel);
if (inside) { float sd = (inside ? 1.0 : -1.0) * distanceToEdge(pixel);
finalColor = useGradient == 1 ? getGradientColor(pixel) : fillColor;
return; // ~1 pixel wide anti-aliasing
} float w = max(0.75, fwidth(sd));
float sd = -distanceToEdge(pixel); float alpha = smoothstep(-w, w, sd);
float alpha = smoothstep(-aaWidth, aaWidth, sd);
if (alpha > 0.0){ if (alpha > 0.0){
vec4 color = useGradient == 1 ? getGradientColor(pixel) : fillColor; vec4 color = useGradient == 1 ? getGradientColor(pixel) : fillColor;
finalColor = vec4(color.rgb, color.a * alpha); finalColor = vec4(color.rgb, color.a * alpha);

Loading…
Cancel
Save