Skip to content

Commit 6ea25fa

Browse files
committed
Add zoom_blur_transition.shader
1 parent 39425c0 commit 6ea25fa

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//based on https://www.shadertoy.com/view/Ml3XR2
2+
3+
uniform texture2d image_a;
4+
uniform texture2d image_b;
5+
uniform float transition_time = 0.5;
6+
uniform bool convert_linear = true;
7+
8+
//modified zoom blur from http://transitions.glsl.io/transition/b86b90161503a0023231
9+
uniform float strength<
10+
string label = "Strength (0.3)";
11+
string widget_type = "slider";
12+
float minimum = 0.00;
13+
float maximum = 1.50;
14+
float step = 0.01;
15+
> = 0.3;
16+
#define PI 3.141592653589793
17+
18+
float Linear_ease(in float begin, in float change, in float duration, in float time) {
19+
return change * time / duration + begin;
20+
}
21+
22+
float Exponential_easeInOut(in float begin, in float change, in float duration, in float time) {
23+
if (time == 0.0)
24+
return begin;
25+
else if (time == duration)
26+
return begin + change;
27+
time = time / (duration / 2.0);
28+
if (time < 1.0)
29+
return change / 2.0 * pow(2.0, 10.0 * (time - 1.0)) + begin;
30+
return change / 2.0 * (-pow(2.0, -10.0 * (time - 1.0)) + 2.0) + begin;
31+
}
32+
33+
float Sinusoidal_easeInOut(in float begin, in float change, in float duration, in float time) {
34+
return -change / 2.0 * (cos(PI * time / duration) - 1.0) + begin;
35+
}
36+
37+
float random(in float3 scale, in float seed) {
38+
return frac(sin(dot(0 + seed, scale)) * 43758.5453 + seed);
39+
}
40+
41+
float3 crossFade(in float2 uv, in float dissolve) {
42+
return lerp(image_a.Sample(textureSampler, uv).rgb, image_b.Sample(textureSampler, uv).rgb, dissolve);
43+
}
44+
45+
float4 mainImage(VertData v_in) : TARGET {
46+
float2 texCoord = v_in.uv;
47+
float progress = transition_time;
48+
// Linear interpolate center across center half of the image
49+
float2 center = float2(Linear_ease(0.5, 0.0, 1.0, progress),0.5);
50+
float dissolve = Exponential_easeInOut(0.0, 1.0, 1.0, progress);
51+
52+
// Mirrored sinusoidal loop. 0->strength then strength->0
53+
float strength2 = Sinusoidal_easeInOut(0.0, strength, 0.5, progress);
54+
55+
float3 color = float3(0.0,0.0,0.0);
56+
float total = 0.0;
57+
float2 toCenter = center - texCoord;
58+
59+
/* randomize the lookup values to hide the fixed float of samples */
60+
float offset = random(float3(12.9898, 78.233, 151.7182), 0.0)*0.5;
61+
62+
for (float t = 0.0; t <= 20.0; t++) {
63+
float percent = (t + offset) / 20.0;
64+
float weight = 1.0 * (percent - percent * percent);
65+
color += crossFade(texCoord + toCenter * percent * strength2, dissolve) * weight;
66+
total += weight;
67+
}
68+
float4 rgba = float4(color / total, 1.0);
69+
if (convert_linear)
70+
rgba.rgb = srgb_nonlinear_to_linear(rgba.rgb);
71+
return rgba;
72+
}

0 commit comments

Comments
 (0)