fix: reduce shader usage

This commit is contained in:
2026-10-23 00:05:08 +02:00
parent 6781078467
commit 36cddc96c3
32 changed files with 959 additions and 84 deletions
+16 -3
View File
@@ -21,6 +21,7 @@ layout(std140, binding = 0) uniform buf {
vec4 rectData[80];
float shadowRadius;
vec4 shadowColor;
vec4 invertedOuterRadii;
};
float sdRoundedBox(vec2 p, vec2 center, vec2 halfSize, float radius) {
@@ -55,7 +56,8 @@ float smax(float a, float b, float k) {
float smaxSharpA(float a, float b, float k) {
// smax variant that keeps a's boundary sharp (no inward rounding at a = 0).
// Used for the frame outer edge so it always fills to the edges.
// Used for the frame inner side, so the outer edge keeps its own shape and
// always fills to the edges.
float h = max(k - abs(a - b), 0.0) / k;
float blend = h * h * h * k * (1.0 / 6.0);
blend *= smoothstep(0.0, k * 0.5, -a);
@@ -182,7 +184,12 @@ void main() {
}
if (hasInverted != 0) {
float dOuter = sdBox(pixel, invertedOuter.xy, invertedOuter.zw) - 1.0;
// Outer edge rounds with its own per-corner radii. With all-zero radii
// sdRoundedBox4 equals sdBox, so a frame that sets no outer radius is
// unchanged. smaxSharpA keeps this boundary authoritative for the fill.
float dOuter =
sdRoundedBox4(pixel, invertedOuter.xy, invertedOuter.zw,
invertedOuterRadii) - 1.0;
float dInner =
sdRoundedBox(pixel, invertedInner.xy, invertedInner.zw, invertedRadius);
@@ -248,7 +255,13 @@ void main() {
dInner -= sinkValue;
float dFrame = smaxSharpA(dOuter, -dInner, smoothFactor);
// dOuter is already a true circle (sdRoundedBox4). Keep it exact whenever the
// outer arc is the active boundary; a smax term added there would pull the
// arc's sides inward (curvature/tangent mismatch), so the corner would not be
// a circle. Only blend on the inner side, where the inner boundary is active.
float negInner = -dInner;
float dFrame = dOuter >= negInner ? dOuter
: smaxSharpA(dOuter, negInner, smoothFactor);
mergedSdf = smin(mergedSdf, dFrame, smoothFactor);
if (dFrame < minDist) {