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