Add an effect for Lanczos resampling.
[movit] / resample_effect.frag
1 // DIRECTION_VERTICAL will be #defined to 1 if we are scaling vertically,
2 // and 0 otherwise.
3
4 uniform sampler2D PREFIX(sample_tex);
5 uniform int PREFIX(num_samples);
6 uniform float PREFIX(sample_x_scale);
7 uniform float PREFIX(sample_x_offset);
8
9 // Sample a single weight. First fetch information about where to sample
10 // and the weight from sample_tex, and then read the pixel itself.
11 vec4 PREFIX(do_sample)(vec2 tc, int i)
12 {
13         vec2 sample_tc;
14         sample_tc.x = float(i) * PREFIX(sample_x_scale) + PREFIX(sample_x_offset);
15 #if DIRECTION_VERTICAL
16         sample_tc.y = tc.y;
17 #else
18         sample_tc.y = tc.x;
19 #endif
20         vec2 sample = texture2D(PREFIX(sample_tex), sample_tc).rg;
21
22 #if DIRECTION_VERTICAL
23         tc.y = sample.g;
24 #else
25         tc.x = sample.g;
26 #endif
27         return vec4(sample.r) * INPUT(tc);
28 }
29
30 vec4 FUNCNAME(vec2 tc) {
31         vec4 sum = PREFIX(do_sample)(tc, 0);
32         for (int i = 1; i < PREFIX(num_samples); ++i) {
33                 sum += PREFIX(do_sample)(tc, i);
34         }
35         return sum;
36 }
37
38 #undef DIRECTION_VERTICAL