summaryrefslogtreecommitdiff
path: root/wimmel.frag
blob: b9271d7458c314fd027d7b650aa35d79d174e42f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
varying vec2 v_texcoord;
uniform sampler2D tex;
uniform vec2 pixelsize;
uniform vec4 search_rect;
uniform int barrier;

void
main()
{
	float i, j;
	float width = search_rect[2];
	float height = search_rect[3];
	int diff = 0;

	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;
		}
	}

	/* Only written if fragment is NOT discarded in loop */
	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

// vim:ft=c: