X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=sobel.frag;h=518b6f8abcdadb4491b8e1187f6cea3e696fa477;hb=24c21cf229d7e273ecc0e7ad0dc93bcb9fe466e3;hp=c4dabd519712465a9d2a5495617ac9c1e2708c5b;hpb=e08fc3634afa41320df5dea0ec44feb3d4e4e679;p=nageru diff --git a/sobel.frag b/sobel.frag index c4dabd5..518b6f8 100644 --- a/sobel.frag +++ b/sobel.frag @@ -26,24 +26,16 @@ void main() // Computing both directions at once allows us to get away with eight // texture samples instead of twelve. - float x_left = tc.x - inv_image_size.x; - float x_mid = tc.x; - float x_right = tc.x + inv_image_size.x; - - float y_top = tc.y + inv_image_size.y; // Note the bottom-left coordinate system. - float y_mid = tc.y; - float y_bottom = tc.y - inv_image_size.y; - - float top_left = texture(tex, vec2(x_left, y_top)).x; - float left = texture(tex, vec2(x_left, y_mid)).x; - float bottom_left = texture(tex, vec2(x_left, y_bottom)).x; - - float top = texture(tex, vec2(x_mid, y_top)).x; - float bottom = texture(tex, vec2(x_mid, y_bottom)).x; - - float top_right = texture(tex, vec2(x_right, y_top)).x; - float right = texture(tex, vec2(x_right, y_mid)).x; - float bottom_right = texture(tex, vec2(x_right, y_bottom)).x; + float top_left = textureOffset(tex, tc, ivec2(-1, 1)).x; // Note the bottom-left coordinate system. + float left = textureOffset(tex, tc, ivec2(-1, 0)).x; + float bottom_left = textureOffset(tex, tc, ivec2(-1, -1)).x; + + float top = textureOffset(tex, tc, ivec2( 0, 1)).x; + float bottom = textureOffset(tex, tc, ivec2( 0, -1)).x; + + float top_right = textureOffset(tex, tc, ivec2( 1, 1)).x; + float right = textureOffset(tex, tc, ivec2( 1, 0)).x; + float bottom_right = textureOffset(tex, tc, ivec2( 1, -1)).x; gradients.x = (top_right + 2.0f * right + bottom_right) - (top_left + 2.0f * left + bottom_left); gradients.y = (top_left + 2.0 * top + top_right) - (bottom_left + 2.0f * bottom + bottom_right);