From 5bcbaab8ea90655c2496c8df029a9cb991dba0ce Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 14 Mar 2012 23:20:47 +0100 Subject: wimmel.frag: Discard fragment early if difference is to significant --- wimmel.frag | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wimmel.frag b/wimmel.frag index d3cf745..b9271d7 100644 --- a/wimmel.frag +++ b/wimmel.frag @@ -12,16 +12,19 @@ main() float height = search_rect[3]; int diff = 0; - for (i = 0.0; i < width && diff < barrier; i += pixelsize.x) { - for (j = 0.0; j < height && diff < barrier; j += pixelsize.y) { + for (i = 0.0; i < width; i += pixelsize.x) { + for (j = 0.0; j < height; j += pixelsize.y) { vec4 match = texture2D(tex, search_rect.xy + vec2(i,j)); vec4 orig = texture2D(tex, v_texcoord + vec2(i,j)); diff += int(any(greaterThan(abs(orig - match), vec4(0.2)))); + if (diff >= barrier) + discard; } } - gl_FragColor = vec4(float(diff < barrier), 0.0, 0.0, 1.0); + /* Only written if fragment is NOT discarded in loop */ + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); } // vim:ft=c: -- cgit