ZaStoGram_desktop/Telegram/shaders/rounded_corners.frag
Ilya Fedin ce36ff3140 [qrhi] Fixed the gl_FragCoord origin difference on OpenGL.
The fragment shaders converted gl_FragCoord.y to the bottom-left based
system of the rectangle uniforms unconditionally, which only holds for
Vulkan, Metal and D3D, where gl_FragCoord.y counts from the top. On
OpenGL it counts from the bottom, so the media viewer and PiP fades,
the content rounding and the incoming call shadow came out mirrored
there. The conversion is now driven by a fragCoordYUp uniform, kept at
offset 8 in every block that needs it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 16:50:35 +03:00

30 lines
880 B
GLSL

#version 450
layout(location = 0) out vec4 fragColor;
layout(std140, binding = 0) uniform Params {
vec2 viewport;
// 1.0 when gl_FragCoord.y counts from the bottom (OpenGL).
float fragCoordYUp;
vec4 roundRect;
float roundRadius;
};
float roundedCorner() {
float fragY = (fragCoordYUp > 0.0)
? gl_FragCoord.y
: (viewport.y - gl_FragCoord.y);
vec2 fragCoord = vec2(gl_FragCoord.x, fragY);
vec2 rectHalf = roundRect.zw / 2.0;
vec2 rectCenter = roundRect.xy + rectHalf;
vec2 fromRectCenter = abs(fragCoord - rectCenter);
vec2 vectorRadius = vec2(roundRadius + 0.5);
vec2 fromCenterWithRadius = fromRectCenter + vectorRadius;
vec2 fromRoundingCenter = max(fromCenterWithRadius, rectHalf) - rectHalf;
float rounded = length(fromRoundingCenter) - roundRadius;
return 1.0 - smoothstep(0.0, 1.0, rounded);
}
void main() {
fragColor = vec4(1.0) * roundedCorner();
}