1 // DIRECTION_VERTICAL will be #defined to 1 if we are scaling vertically,
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);
11 // We put the fractional part of the offset (-0.5 to 0.5 pixels) in the weights
12 // because we have to (otherwise they'd do nothing). However, the support texture
13 // has limited numerical precision and we'd need as much of it as we can for
14 // getting the subpixel sampling right, and adding a large constant to each value
15 // will reduce the precision further. Thus, the non-fractional part of the offset
16 // is sent in through a uniform that we simply add in the beginning of the shader.
17 uniform float PREFIX(whole_pixel_offset);
19 // Sample a single weight. First fetch information about where to sample
20 // and the weight from sample_tex, and then read the pixel itself.
21 vec4 PREFIX(do_sample)(vec2 tc, int i)
24 sample_tc.x = float(i) * PREFIX(sample_x_scale) + PREFIX(sample_x_offset);
25 #if DIRECTION_VERTICAL
26 sample_tc.y = tc.y * PREFIX(num_loops);
28 sample_tc.y = tc.x * PREFIX(num_loops);
30 vec2 sample = tex2D(PREFIX(sample_tex), sample_tc).rg;
32 #if DIRECTION_VERTICAL
33 tc.y = sample.g + floor(sample_tc.y) * PREFIX(slice_height);
35 tc.x = sample.g + floor(sample_tc.y) * PREFIX(slice_height);
37 return vec4(sample.r) * INPUT(tc);
40 vec4 FUNCNAME(vec2 tc) {
41 #if DIRECTION_VERTICAL
42 tc.y += PREFIX(whole_pixel_offset);
44 tc.x += PREFIX(whole_pixel_offset);
46 vec4 sum = PREFIX(do_sample)(tc, 0);
47 for (int i = 1; i < PREFIX(num_samples); ++i) {
48 sum += PREFIX(do_sample)(tc, i);
53 #undef DIRECTION_VERTICAL