]> git.sesse.net Git - nageru/blob - derivatives.frag
Calculate I_x and I_y for variational refinement.
[nageru] / derivatives.frag
1 #version 450 core
2
3 in vec2 tc;
4 out vec2 derivatives;
5
6 uniform sampler2D tex;
7 uniform vec2 inv_image_size;
8
9 void main()
10 {
11         float x_m2 = texture(tex, vec2(tc.x - 2.0 * inv_image_size.x), tc.y).x;
12         float x_m1 = texture(tex, vec2(tc.x -       inv_image_size.x), tc.y).x;
13         float x_p1 = texture(tex, vec2(tc.x +       inv_image_size.x), tc.y).x;
14         float x_p2 = texture(tex, vec2(tc.x + 2.0 * inv_image_size.x), tc.y).x;
15
16         float y_m2 = texture(tex, vec2(tc.x, tc.y - 2.0 * inv_image_size.y)).x;
17         float y_m1 = texture(tex, vec2(tc.x, tc.y -       inv_image_size.y)).x;
18         float y_p1 = texture(tex, vec2(tc.x, tc.y +       inv_image_size.y)).x;
19         float y_p2 = texture(tex, vec2(tc.x, tc.y + 2.0 * inv_image_size.y)).x;
20
21         derivatives.x = (x_p1 - x_m1) * (2.0/3.0) + (x_m2 - x_p2) * (1.0/12.0);
22         derivatives.y = (y_p1 - y_m1) * (2.0/3.0) + (y_m2 - y_p2) * (1.0/12.0);
23 }