This repository was archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathYUCICrossZoomTransition.cikernel
executable file
·58 lines (47 loc) · 2.2 KB
/
YUCICrossZoomTransition.cikernel
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
55
56
57
58
const float PI = 3.141592653589793;
float linearEase(float begin, float change, float duration, float time) {
return change * time / duration + begin;
}
float exponentialEaseInOut(float begin, float change, float duration, float time) {
if (time == 0.0) {
return begin;
} else if (time == duration) {
return begin + change;
}
time = time / (duration / 2.0);
if (time < 1.0) {
return change / 2.0 * pow(2.0, 10.0 * (time - 1.0)) + begin;
} else {
return change / 2.0 * (-pow(2.0, -10.0 * (time - 1.0)) + 2.0) + begin;
}
}
float sinusoidalEaseInOut(float begin, float change, float duration, float time) {
return -change / 2.0 * (cos(PI * time / duration) - 1.0) + begin;
}
/* random number between 0 and 1 */
float random(vec3 scale, float seed) {
/* use the fragment position for randomness */
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
}
kernel vec4 filterKernel(sampler inputImage, sampler inputTargetImage, float inputStrength, vec4 inputExtent, float progress) {
// Linear interpolate center across center half of the image
vec2 center = vec2(linearEase(0.25, 0.5, 1.0, progress), 0.5);
float dissolve = exponentialEaseInOut(0.0, 1.0, 1.0, progress);
// Mirrored sinusoidal loop. 0->strength then strength->0
float strength = sinusoidalEaseInOut(0.0, inputStrength, 0.5, progress);
vec4 color = vec4(0.0);
float total = 0.0;
vec2 textureCoordinate = ((destCoord() - inputExtent.xy)/inputExtent.zw);
vec2 toCenter = center - textureCoordinate;
/* randomize the lookup values to hide the fixed number of samples */
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
for (float t = 0.0; t <= 10.0; t++) {
float percent = (t + offset) / 10.0;
float weight = 4.0 * (percent - percent * percent);
vec2 uv = (textureCoordinate + toCenter * percent * strength) * inputExtent.zw + inputExtent.xy;
vec4 crossFade = mix(sample(inputImage, samplerTransform(inputImage,uv)), sample(inputTargetImage, samplerTransform(inputTargetImage,uv)), dissolve);
color += crossFade * weight;
total += weight;
}
return color/total;
}