7 uniform float inv_width, inv_height;
11 // There are two common Sobel filters, horizontal and vertical
12 // (see e.g. Wikipedia, or the OpenCV documentation):
16 // [-1 0 1] [-1 -2 -1]
17 // Horizontal Vertical
19 // Computing both at once allows us to get away with eight
20 // texture samples instead of twelve.
22 float x_left = tc.x - inv_width;
24 float x_right = tc.x + inv_width;
26 float y_top = tc.y + inv_height; // Note the bottom-left coordinate system.
28 float y_bottom = tc.y - inv_height;
30 float top_left = texture(tex, vec2(x_left, y_top)).x;
31 float left = texture(tex, vec2(x_left, y_mid)).x;
32 float bottom_left = texture(tex, vec2(x_left, y_bottom)).x;
34 float top = texture(tex, vec2(x_mid, y_top)).x;
35 float bottom = texture(tex, vec2(x_mid, y_bottom)).x;
37 float top_right = texture(tex, vec2(x_right, y_top)).x;
38 float right = texture(tex, vec2(x_right, y_mid)).x;
39 float bottom_right = texture(tex, vec2(x_right, y_bottom)).x;
41 gradients.x = (top_right + 2.0f * right + bottom_right) - (top_left + 2.0f * left + bottom_left);
42 gradients.y = (top_left + 2.0 * top + top_right) - (bottom_left + 2.0f * bottom + bottom_right);