]> git.sesse.net Git - movit/blob - resample_effect.frag
a31df17edb1007f5f9a76d6a5dbf1888087a214a
[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(num_loops);
7 uniform float PREFIX(sample_x_scale);
8 uniform float PREFIX(sample_x_offset);
9 uniform float PREFIX(slice_height);
10
11 // Sample a single weight. First fetch information about where to sample
12 // and the weight from sample_tex, and then read the pixel itself.
13 vec4 PREFIX(do_sample)(vec2 tc, int i)
14 {
15         vec2 sample_tc;
16         sample_tc.x = float(i) * PREFIX(sample_x_scale) + PREFIX(sample_x_offset);
17 #if DIRECTION_VERTICAL
18         sample_tc.y = tc.y * PREFIX(num_loops);
19 #else
20         sample_tc.y = tc.x * PREFIX(num_loops);
21 #endif
22         vec2 sample = texture2D(PREFIX(sample_tex), sample_tc).rg;
23
24 #if DIRECTION_VERTICAL
25         tc.y = sample.g + floor(sample_tc.y) * PREFIX(slice_height);
26 #else
27         tc.x = sample.g + floor(sample_tc.y) * PREFIX(slice_height);
28 #endif
29         return vec4(sample.r) * INPUT(tc);
30 }
31
32 vec4 FUNCNAME(vec2 tc) {
33         vec4 sum = PREFIX(do_sample)(tc, 0);
34         for (int i = 1; i < PREFIX(num_samples); ++i) {
35                 sum += PREFIX(do_sample)(tc, i);
36         }
37         return sum;
38 }
39
40 #undef DIRECTION_VERTICAL