The OpenGL renderer takes transparentBg where the checkerboard value is one and transparentFg where it is zero, the mix arguments here were the other way round, so the pattern came out inverted. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
52 lines
1.8 KiB
GLSL
52 lines
1.8 KiB
GLSL
#version 450
|
|
|
|
layout(location = 0) in vec2 v_texcoord;
|
|
layout(location = 0) out vec4 fragColor;
|
|
|
|
layout(binding = 1) uniform sampler2D s_texture;
|
|
layout(binding = 2) uniform sampler2D f_texture;
|
|
|
|
layout(std140, binding = 0) uniform Params {
|
|
vec2 viewport;
|
|
// 1.0 when gl_FragCoord.y counts from the bottom (OpenGL).
|
|
float fragCoordYUp;
|
|
vec4 shadowTopRect;
|
|
vec4 shadowBottomSkipOpacityFullFade;
|
|
vec4 transparentBg;
|
|
vec4 transparentFg;
|
|
float transparentSize;
|
|
};
|
|
|
|
void main() {
|
|
float fragY = (fragCoordYUp > 0.0)
|
|
? gl_FragCoord.y
|
|
: (viewport.y - gl_FragCoord.y);
|
|
vec2 fragCoord = vec2(gl_FragCoord.x, fragY);
|
|
vec4 result = texture(s_texture, v_texcoord);
|
|
|
|
vec2 checkboardLadder = floor(fragCoord / transparentSize);
|
|
float checkboard = mod(checkboardLadder.x + checkboardLadder.y, 2.0);
|
|
vec4 bg = mix(transparentFg, transparentBg, checkboard);
|
|
// The texture is premultiplied already, so it composites as it is.
|
|
result = result + bg * (1.0 - result.a);
|
|
|
|
float topHeight = shadowTopRect.w;
|
|
float bottomHeight = shadowBottomSkipOpacityFullFade.x;
|
|
float bottomSkip = shadowBottomSkipOpacityFullFade.y;
|
|
float opacity = shadowBottomSkipOpacityFullFade.z;
|
|
float fullFade = shadowBottomSkipOpacityFullFade.w;
|
|
float viewportHeight = shadowTopRect.y + topHeight;
|
|
float fullHeight = topHeight + bottomHeight;
|
|
float topY = min(
|
|
(viewportHeight - fragCoord.y) / fullHeight,
|
|
topHeight / fullHeight);
|
|
float topX = (fragCoord.x - shadowTopRect.x) / shadowTopRect.z;
|
|
vec4 fadeTop = texture(f_texture, vec2(topX, topY)) * opacity;
|
|
float bottomY = max(bottomSkip + fullHeight - fragCoord.y, topHeight)
|
|
/ fullHeight;
|
|
vec4 fadeBottom = texture(f_texture, vec2(0.5, bottomY)) * opacity;
|
|
float fade = min((1.0 - fadeTop.a) * (1.0 - fadeBottom.a), fullFade);
|
|
result.rgb = result.rgb * fade;
|
|
|
|
fragColor = result;
|
|
}
|