diff --git a/sway/desktop/shaders/corner.frag b/sway/desktop/shaders/corner.frag index 7540d446..a8465d60 100644 --- a/sway/desktop/shaders/corner.frag +++ b/sway/desktop/shaders/corner.frag @@ -18,13 +18,14 @@ float roundedBoxSDF(vec2 center, vec2 size, float radius) { void main() { vec2 center = gl_FragCoord.xy - position - half_size; - float distance = roundedBoxSDF(center, half_size - half_thickness, radius + half_thickness); - float smoothedAlphaOuter = 1.0 - smoothstep(-1.0, 1.0, distance - half_thickness); + float dist = roundedBoxSDF(center, half_size - half_thickness, radius + half_thickness); + float smoothedAlphaOuter = 1.0 - smoothstep(-1.0, 1.0, dist - half_thickness); // Create an inner circle that isn't as anti-aliased as the outer ring - float smoothedAlphaInner = 1.0 - smoothstep(-1.0, 0.5, distance + half_thickness); + float smoothedAlphaInner = 1.0 - smoothstep(-1.0, 0.5, dist + half_thickness); gl_FragColor = mix(vec4(0), v_color, smoothedAlphaOuter - smoothedAlphaInner); - if ((v_color.a == 1.0 && gl_FragColor.a <= 0.5) || gl_FragColor.a <= 0.01) { + // Discards outside the curve and transparent pixels + if (dist > half_thickness || gl_FragColor.a == 0.0) { discard; return; } diff --git a/sway/desktop/shaders/quad.frag b/sway/desktop/shaders/quad.frag index e5eed4b6..3b2afd65 100644 --- a/sway/desktop/shaders/quad.frag +++ b/sway/desktop/shaders/quad.frag @@ -5,7 +5,7 @@ varying vec2 v_texcoord; void main() { gl_FragColor = v_color; - if (gl_FragColor.a <= 0.01){ + if (gl_FragColor.a == 0.0) { discard; } } diff --git a/sway/desktop/shaders/quad_round.frag b/sway/desktop/shaders/quad_round.frag index 390b77e1..ad486651 100644 --- a/sway/desktop/shaders/quad_round.frag +++ b/sway/desktop/shaders/quad_round.frag @@ -7,13 +7,14 @@ uniform vec2 position; uniform float radius; void main() { - vec2 half_size = size / 2.0; + vec2 half_size = size * 0.5; vec2 q = abs(gl_FragCoord.xy - position - half_size) - half_size + radius; - float distance = min(max(q.x,q.y),0.0) + length(max(q,0.0)) - radius; - float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, distance); + float dist = min(max(q.x,q.y), 0.0) + length(max(q, 0.0)) - radius; + float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, dist); gl_FragColor = mix(vec4(0), v_color, smoothedAlpha); - if (gl_FragColor.a <= 0.01){ + // Discards outside the curve and transparent pixels + if (dist > 0.0 || gl_FragColor.a == 0.0) { discard; } } diff --git a/sway/desktop/shaders/quad_round_tl.frag b/sway/desktop/shaders/quad_round_tl.frag index f7886188..76283679 100644 --- a/sway/desktop/shaders/quad_round_tl.frag +++ b/sway/desktop/shaders/quad_round_tl.frag @@ -8,11 +8,12 @@ uniform float radius; void main() { vec2 q = abs(gl_FragCoord.xy - position - size) - size + radius; - float distance = min(max(q.x,q.y),0.0) + length(max(q,0.0)) - radius; - float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, distance); + float dist = min(max(q.x,q.y), 0.0) + length(max(q, 0.0)) - radius; + float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, dist); gl_FragColor = mix(vec4(0), v_color, smoothedAlpha); - if (gl_FragColor.a <= 0.01){ + // Discards outside the curve and transparent pixels + if (dist > 0.0 || gl_FragColor.a == 0.0) { discard; } } diff --git a/sway/desktop/shaders/quad_round_tr.frag b/sway/desktop/shaders/quad_round_tr.frag index 767bf3e9..392af76e 100644 --- a/sway/desktop/shaders/quad_round_tr.frag +++ b/sway/desktop/shaders/quad_round_tr.frag @@ -8,11 +8,12 @@ uniform float radius; void main() { vec2 q = abs(gl_FragCoord.xy - position - vec2(0, size.y)) - size + radius; - float distance = min(max(q.x,q.y),0.0) + length(max(q,0.0)) - radius; - float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, distance); + float dist = min(max(q.x,q.y), 0.0) + length(max(q, 0.0)) - radius; + float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, dist); gl_FragColor = mix(vec4(0), v_color, smoothedAlpha); - if (gl_FragColor.a <= 0.01){ + // Discards outside the curve and transparent pixels + if (dist > 0.0 || gl_FragColor.a == 0.0) { discard; } } diff --git a/sway/desktop/shaders/tex_external.frag b/sway/desktop/shaders/tex_external.frag index 354aa9ec..3d953bcd 100644 --- a/sway/desktop/shaders/tex_external.frag +++ b/sway/desktop/shaders/tex_external.frag @@ -29,13 +29,18 @@ void main() { if (!has_titlebar || gl_FragCoord.y - position.y > radius) { vec2 corner_distance = min(gl_FragCoord.xy - position, size + position - gl_FragCoord.xy); if (max(corner_distance.x, corner_distance.y) < radius) { - float d = radius - distance(corner_distance, vec2(radius)); - float smooth = smoothstep(-1.0f, 0.5f, d); + float dist = radius - distance(corner_distance, vec2(radius)); + float smooth = smoothstep(-1.0f, 0.5f, dist); gl_FragColor = mix(vec4(0), gl_FragColor, smooth); + // Discards pixels outside the curve + if (dist < 0.0) { + discard; + return; + } } } - if (gl_FragColor.a <= 0.01){ + if (gl_FragColor.a == 0.0) { discard; } } diff --git a/sway/desktop/shaders/tex_rgba.frag b/sway/desktop/shaders/tex_rgba.frag index a57ad3bb..a5c21cef 100644 --- a/sway/desktop/shaders/tex_rgba.frag +++ b/sway/desktop/shaders/tex_rgba.frag @@ -27,13 +27,18 @@ void main() { if (!has_titlebar || gl_FragCoord.y - position.y > radius) { vec2 corner_distance = min(gl_FragCoord.xy - position, size + position - gl_FragCoord.xy); if (max(corner_distance.x, corner_distance.y) < radius) { - float d = radius - distance(corner_distance, vec2(radius)); - float smooth = smoothstep(-1.0f, 0.5f, d); + float dist = radius - distance(corner_distance, vec2(radius)); + float smooth = smoothstep(-1.0f, 0.5f, dist); gl_FragColor = mix(vec4(0), gl_FragColor, smooth); + // Discards pixels outside the curve + if (dist < 0.0) { + discard; + return; + } } } - if (gl_FragColor.a <= 0.01){ + if (gl_FragColor.a == 0.0) { discard; } } diff --git a/sway/desktop/shaders/tex_rgbx.frag b/sway/desktop/shaders/tex_rgbx.frag index 429ad0a7..a7297620 100644 --- a/sway/desktop/shaders/tex_rgbx.frag +++ b/sway/desktop/shaders/tex_rgbx.frag @@ -26,13 +26,18 @@ void main() { if (!has_titlebar || gl_FragCoord.y - position.y > radius) { vec2 corner_distance = min(gl_FragCoord.xy - position, size + position - gl_FragCoord.xy); if (max(corner_distance.x, corner_distance.y) < radius) { - float d = radius - distance(corner_distance, vec2(radius)); - float smooth = smoothstep(-1.0f, 0.5f, d); + float dist = radius - distance(corner_distance, vec2(radius)); + float smooth = smoothstep(-1.0f, 0.5f, dist); gl_FragColor = mix(vec4(0), gl_FragColor, smooth); + // Discards pixels outside the curve + if (dist < 0.0) { + discard; + return; + } } } - if (gl_FragColor.a <= 0.01){ + if (gl_FragColor.a == 0.0) { discard; } }