-
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathcircle-reveal.frag
More file actions
54 lines (39 loc) · 1.95 KB
/
Copy pathcircle-reveal.frag
File metadata and controls
54 lines (39 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#version 300 es
precision highp float;
in vec2 v_texcoord;
uniform sampler2D tex1; // Start frame (fit pre-resolved in C++)
uniform sampler2D tex2; // End frame (fit pre-resolved in C++)
uniform float progress; // 0.0 = fully start, 1.0 = fully end
uniform float alpha;
uniform vec2 fullSize; // Output size in pixels
uniform vec2 randomPixel; // Circle center (0-1 normalized)
uniform float u_duration; // Host transition duration in seconds (from hyprland config)
// Shader-defined visual duration override: the circle effect completes in 0.5s
// regardless of the host's transition duration. The host's u_duration is used
// to remap progress so the effect fits within this window.
const float SHADER_DURATION = 0.5;
layout(location = 0) out vec4 fragColor;
void main() {
// Remap progress so the effect completes in SHADER_DURATION seconds.
float p = (u_duration > 0.0)
? clamp(progress * (u_duration / SHADER_DURATION), 0.0, 1.0)
: progress;
vec4 startColor = texture(tex1, v_texcoord);
vec4 endColor = texture(tex2, v_texcoord);
// Circle reveal: a radial mask expanding from randomPixel.
vec2 pixelPos = v_texcoord * fullSize;
vec2 centerPixel = randomPixel * fullSize;
float dist = distance(pixelPos, centerPixel);
// Farthest corner from the center, in pixel space (aspect-ratio correct).
float maxDist = 0.0;
maxDist = max(maxDist, distance(vec2(0.0, 0.0), centerPixel));
maxDist = max(maxDist, distance(vec2(fullSize.x, 0.0), centerPixel));
maxDist = max(maxDist, distance(vec2(0.0, fullSize.y), centerPixel));
maxDist = max(maxDist, distance(fullSize, centerPixel));
float normalizedDist = dist / maxDist;
// circleMask: 0 = show start, 1 = show end.
float edgeWidth = 0.02;
float circleMask = smoothstep(p - edgeWidth, p + edgeWidth, normalizedDist);
vec4 blended = mix(endColor, startColor, circleMask);
fragColor = blended * alpha;
}