X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=derivatives.frag;h=e5e355700f56e1197d1ca3cd2326ae346d98a651;hb=24c21cf229d7e273ecc0e7ad0dc93bcb9fe466e3;hp=f5394c37a3f26031ca54d4244824568ae6477af6;hpb=e08fc3634afa41320df5dea0ec44feb3d4e4e679;p=nageru diff --git a/derivatives.frag b/derivatives.frag index f5394c3..e5e3557 100644 --- a/derivatives.frag +++ b/derivatives.frag @@ -4,19 +4,18 @@ in vec2 tc; out vec2 derivatives; uniform sampler2D tex; -uniform vec2 inv_image_size; void main() { - float x_m2 = texture(tex, vec2(tc.x - 2.0 * inv_image_size.x), tc.y).x; - float x_m1 = texture(tex, vec2(tc.x - inv_image_size.x), tc.y).x; - float x_p1 = texture(tex, vec2(tc.x + inv_image_size.x), tc.y).x; - float x_p2 = texture(tex, vec2(tc.x + 2.0 * inv_image_size.x), tc.y).x; + float x_m2 = textureOffset(tex, tc, ivec2(-2, 0)).x; + float x_m1 = textureOffset(tex, tc, ivec2(-1, 0)).x; + float x_p1 = textureOffset(tex, tc, ivec2( 1, 0)).x; + float x_p2 = textureOffset(tex, tc, ivec2( 2, 0)).x; - float y_m2 = texture(tex, vec2(tc.x, tc.y - 2.0 * inv_image_size.y)).x; - float y_m1 = texture(tex, vec2(tc.x, tc.y - inv_image_size.y)).x; - float y_p1 = texture(tex, vec2(tc.x, tc.y + inv_image_size.y)).x; - float y_p2 = texture(tex, vec2(tc.x, tc.y + 2.0 * inv_image_size.y)).x; + float y_m2 = textureOffset(tex, tc, ivec2( 0, -2)).x; + float y_m1 = textureOffset(tex, tc, ivec2( 0, -1)).x; + float y_p1 = textureOffset(tex, tc, ivec2( 0, 1)).x; + float y_p2 = textureOffset(tex, tc, ivec2( 0, 2)).x; derivatives.x = (x_p1 - x_m1) * (2.0/3.0) + (x_m2 - x_p2) * (1.0/12.0); derivatives.y = (y_p1 - y_m1) * (2.0/3.0) + (y_m2 - y_p2) * (1.0/12.0);