mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-13 22:46:34 -04:00
Refactor shadow handling & improve connected chrome rendering
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
// (an inverted rounded rectangle) smooth-unioned with each active chrome
|
||||
// (popout/modal, dock, notification). The smooth-min radius IS the connector
|
||||
// fillet. Antialiasing is analytic via fwidth -> crisp at any scale, no FBO.
|
||||
// The elevation shadow samples the same field at the light offset, so both
|
||||
// elevation states render in this one pass.
|
||||
|
||||
layout(location = 0) in vec2 qt_TexCoord0;
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
@@ -16,19 +18,27 @@ layout(std140, binding = 0) uniform buf {
|
||||
float cutoutRadius;
|
||||
vec4 cutout; // inner cutout edges in px: x=left y=top z=right w=bottom
|
||||
vec4 surfaceColor; // straight (non-premultiplied) rgba
|
||||
// Up to four chrome slots. rect = x,y,w,h (px). corner = per-corner radii
|
||||
// (topLeft, topRight, bottomRight, bottomLeft). param = connectorR, active, 0, 0
|
||||
vec4 shadowColor; // straight rgba; a = 0 disables both shadow terms
|
||||
vec4 shadowParam; // key: x = blur px, y = spread px, z,w = offset px
|
||||
vec4 ambientParam; // ambient: x = blur px, y = spread px, z = alpha
|
||||
// Up to four chrome slots. rect = x,y,w,h (px). corner = per-corner radii,
|
||||
// k = per-corner junction fillet radii (both topLeft, topRight, bottomRight,
|
||||
// bottomLeft; a corner is sharp exactly where its k > 0). param = active, 0, 0, 0
|
||||
vec4 chromeRect0;
|
||||
vec4 chromeCorner0;
|
||||
vec4 chromeK0;
|
||||
vec4 chromeParam0;
|
||||
vec4 chromeRect1;
|
||||
vec4 chromeCorner1;
|
||||
vec4 chromeK1;
|
||||
vec4 chromeParam1;
|
||||
vec4 chromeRect2;
|
||||
vec4 chromeCorner2;
|
||||
vec4 chromeK2;
|
||||
vec4 chromeParam2;
|
||||
vec4 chromeRect3;
|
||||
vec4 chromeCorner3;
|
||||
vec4 chromeK3;
|
||||
vec4 chromeParam3;
|
||||
} ubuf;
|
||||
|
||||
@@ -64,9 +74,13 @@ float chromeDist(vec2 px, vec4 rect, vec4 corner) {
|
||||
return sdRoundBox4(px, c, rect.zw * 0.5, corner);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 px = qt_TexCoord0 * vec2(ubuf.widthPx, ubuf.heightPx);
|
||||
// Per-corner junction fillet radius, selected by chrome-rect quadrant.
|
||||
float chromeK(vec2 px, vec4 rect, vec4 ks) {
|
||||
vec2 p = px - (rect.xy + rect.zw * 0.5);
|
||||
return (p.x >= 0.0) ? (p.y >= 0.0 ? ks.z : ks.y) : (p.y >= 0.0 ? ks.w : ks.x);
|
||||
}
|
||||
|
||||
float sceneDist(vec2 px) {
|
||||
// Frame ring: inside the screen rect AND outside the rounded cutout (hole).
|
||||
vec2 sc = vec2(ubuf.widthPx, ubuf.heightPx) * 0.5;
|
||||
float dOuter = sdBox(px, sc, sc);
|
||||
@@ -75,18 +89,35 @@ void main() {
|
||||
float dCut = sdRoundBox(px, cutC, cutH, ubuf.cutoutRadius);
|
||||
float d = max(dOuter, -dCut);
|
||||
|
||||
// Smooth-union the active chrome surfaces; smin radius = connector fillet.
|
||||
if (ubuf.chromeParam0.y > 0.5)
|
||||
d = smin(d, chromeDist(px, ubuf.chromeRect0, ubuf.chromeCorner0), ubuf.chromeParam0.x);
|
||||
if (ubuf.chromeParam1.y > 0.5)
|
||||
d = smin(d, chromeDist(px, ubuf.chromeRect1, ubuf.chromeCorner1), ubuf.chromeParam1.x);
|
||||
if (ubuf.chromeParam2.y > 0.5)
|
||||
d = smin(d, chromeDist(px, ubuf.chromeRect2, ubuf.chromeCorner2), ubuf.chromeParam2.x);
|
||||
if (ubuf.chromeParam3.y > 0.5)
|
||||
d = smin(d, chromeDist(px, ubuf.chromeRect3, ubuf.chromeCorner3), ubuf.chromeParam3.x);
|
||||
// Smooth-union the active chrome surfaces; smin radius = junction fillet.
|
||||
if (ubuf.chromeParam0.x > 0.5)
|
||||
d = smin(d, chromeDist(px, ubuf.chromeRect0, ubuf.chromeCorner0), chromeK(px, ubuf.chromeRect0, ubuf.chromeK0));
|
||||
if (ubuf.chromeParam1.x > 0.5)
|
||||
d = smin(d, chromeDist(px, ubuf.chromeRect1, ubuf.chromeCorner1), chromeK(px, ubuf.chromeRect1, ubuf.chromeK1));
|
||||
if (ubuf.chromeParam2.x > 0.5)
|
||||
d = smin(d, chromeDist(px, ubuf.chromeRect2, ubuf.chromeCorner2), chromeK(px, ubuf.chromeRect2, ubuf.chromeK2));
|
||||
if (ubuf.chromeParam3.x > 0.5)
|
||||
d = smin(d, chromeDist(px, ubuf.chromeRect3, ubuf.chromeCorner3), chromeK(px, ubuf.chromeRect3, ubuf.chromeK3));
|
||||
return d;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 px = qt_TexCoord0 * vec2(ubuf.widthPx, ubuf.heightPx);
|
||||
float d = sceneDist(px);
|
||||
float fw = max(fwidth(d), 1e-4);
|
||||
float cov = 1.0 - smoothstep(-fw, fw, d);
|
||||
float a = ubuf.surfaceColor.a * cov * ubuf.qt_Opacity;
|
||||
fragColor = vec4(ubuf.surfaceColor.rgb * a, a);
|
||||
// Opaque silhouette over shadow, then the surface alpha applied to the
|
||||
// whole result — matches the old flattened-FBO + group-opacity look.
|
||||
vec4 col = vec4(ubuf.surfaceColor.rgb, 1.0) * cov;
|
||||
if (ubuf.shadowColor.a > 0.0) {
|
||||
float dk = sceneDist(px - ubuf.shadowParam.zw) - ubuf.shadowParam.y;
|
||||
float bk = max(ubuf.shadowParam.x, fw);
|
||||
float covK = 1.0 - smoothstep(-bk, bk, dk);
|
||||
// Ambient wrap reuses the field already computed for the silhouette.
|
||||
float ba = max(ubuf.ambientParam.x, fw);
|
||||
float covA = 1.0 - smoothstep(-ba, ba, d - ubuf.ambientParam.y);
|
||||
float sh = 1.0 - (1.0 - covK * ubuf.shadowColor.a) * (1.0 - covA * ubuf.ambientParam.z);
|
||||
col += vec4(ubuf.shadowColor.rgb, 1.0) * (sh * (1.0 - col.a));
|
||||
}
|
||||
fragColor = col * (ubuf.surfaceColor.a * ubuf.qt_Opacity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user