]> git.sesse.net Git - movit/blob - luma_mix_effect.frag
Typo fixes.
[movit] / luma_mix_effect.frag
1 // Implicit uniforms:
2 // uniform float PREFIX(progress_mul_w_plus_one);
3 // uniform bool PREFIX(bool_inverse);
4
5 vec4 FUNCNAME(vec2 tc) {
6         vec4 first = INPUT1(tc);
7         vec4 second = INPUT2(tc);
8
9         // We treat the luma as going from 0 to w, where w is the transition width
10         // (wider means the boundary between transitioned and non-transitioned
11         // will be harder, while w=0 is essentially just a straight fade).
12         // We need to map this 0..w range in the luma image to a (clamped) 0..1
13         // range for how far this pixel has come in a fade. At the very
14         // beginning, we can visualize it like this, where every pixel is in
15         // the state 0.0 (100% first image, 0% second image):
16         //
17         //         0                     w
18         //   luma: |---------------------|
19         //   mix:                        |----|
20         //                               0    1
21         //
22         // Then as we progress, eventually the luma range should move to the right
23         // so that more pixels start moving towards higher mix value:
24         //
25         //           0                     w
26         //   luma:   |---------------------|
27         //   mix:                        |----|
28         //                               0    1
29         //
30         // and at the very end, all pixels should be in the state 1.0 (0% first image,
31         // 100% second image):
32         //
33         //                                    0                     w
34         //   luma:                            |---------------------|
35         //   mix:                        |----|
36         //                               0    1
37         //
38         // So clearly, it should move (w+1) units to the right, and apart from that
39         // just stay a simple mapping.
40         float w = PREFIX(transition_width);
41         float luma = INPUT3(tc).x;
42         if (PREFIX(bool_inverse)) {
43                 luma = 1.0 - luma;
44         }
45         float m = clamp((luma * w - w) + PREFIX(progress_mul_w_plus_one), 0.0, 1.0);
46
47         return mix(first, second, m);
48 }