tab.frag
2256 bytes
1precision highp float;
2
3uniform highp vec2 pixelSize;
4uniform float opacity;
5uniform highp vec4 fillColor;
6uniform highp vec4 borderColor;
7uniform float outerRadius;
8uniform float borderWidth;
9
10uniform bool applyBlur;
11uniform sampler2D blurTex;
12
13varying highp vec2 pixCoord;
14varying highp vec2 monitorTexCoord;
15
16void main() {
17 float opacityMul = opacity;
18 highp vec2 cornerDist = min(pixCoord, pixelSize - pixCoord);
19
20 gl_FragColor = fillColor;
21
22 if (cornerDist.x <= outerRadius && cornerDist.y <= outerRadius) {
23 highp vec2 vcornerDist = vec2(outerRadius) - cornerDist;
24 float distSq = vcornerDist.x * vcornerDist.x + vcornerDist.y * vcornerDist.y;
25
26 // See https://github.com/hyprwm/Hyprland/blob/e75e2cdac79417ffdbbbe903f72668953483a4e7/src/render/shaders/SharedValues.hpp#L3
27 const float SMOOTHING_CONSTANT = 0.58758063398831095317;
28 const float SMOOTHING_CONSTANT_2X = SMOOTHING_CONSTANT * 2.0;
29
30 float innerRadius = outerRadius - borderWidth;
31 float outerTest1 = outerRadius + SMOOTHING_CONSTANT_2X;
32 float outerTest2 = outerRadius - SMOOTHING_CONSTANT_2X;
33 float innerTest1 = innerRadius + SMOOTHING_CONSTANT_2X;
34 float innerTest2 = innerRadius - SMOOTHING_CONSTANT_2X;
35
36 float dist;
37 bool calculatedDist = false;
38
39 if (distSq > outerTest1 * outerTest1) {
40 discard;
41 } else if (distSq > outerTest2 * outerTest2) {
42 dist = sqrt(distSq);
43 calculatedDist = true;
44 float normalized = 1.0 - smoothstep(0.0, 1.0, (dist - outerRadius + SMOOTHING_CONSTANT) / (SMOOTHING_CONSTANT_2X));
45 gl_FragColor = borderColor;
46 opacityMul *= normalized;
47 } else if (distSq > innerTest2 * innerTest2) {
48 gl_FragColor = borderColor;
49 }
50
51 if (distSq > innerTest2 * innerTest2 && distSq <= innerTest1 * innerTest1) {
52 if (!calculatedDist) dist = sqrt(distSq);
53 float normalized = 1.0 - smoothstep(0.0, 1.0, (dist - innerRadius + SMOOTHING_CONSTANT) / (SMOOTHING_CONSTANT_2X));
54 gl_FragColor = gl_FragColor * (1.0 - normalized) + fillColor * normalized;
55 }
56 } else if (cornerDist.x <= borderWidth || cornerDist.y <= borderWidth) {
57 gl_FragColor = borderColor;
58 }
59
60 if (applyBlur && gl_FragColor.a != 1.0) {
61 gl_FragColor = gl_FragColor + texture2D(blurTex, monitorTexCoord) * (1.0 - gl_FragColor.a);
62 }
63
64 gl_FragColor *= opacityMul;
65}