forge
Explore
Log in

Don't you dare go Hollow

shaders: Optimize rounding_alpha() a little

Browse files at this commit

d020d986ed85707f72aecea78ef2235fafdcdbe1Ivan MolodetskikhParent: 5abeb92
Simplified clamping exploiting half_px + half_px = 1.0 / niri_scale.

Makes the resize shader fit on a Eee PC ALU.
src/render_helpers/shaders/rounding_alpha.fragmodified+5 -2
@@ -19,6 +19,9 @@ float niri_rounding_alpha(vec2 coords, vec2 size, vec4 corner_radius) {
1919 }
2020
2121 float dist = distance(coords, center);
22- float half_px = 0.5 / niri_scale;
23- return 1.0 - smoothstep(radius - half_px, radius + half_px, dist);
22+
23+ // Manual smoothstep() between radius - half_px and radius + half_px
24+ // to avoid a division in clamp().
25+ float t = clamp((dist - radius) * niri_scale + 0.5, 0.0, 1.0);
26+ return 1.0 - t * t * (3.0 - 2.0 * t);
2427 }