root / trunk / tbeta / Linux / apps / addonsExamples / Codeblocks_8_linux / bin / data / shaders / blobDetector.fs @ 164

View | Annotate | Download (1.9 KB)

1
uniform sampler2D tex;
2
3
void main()
4
{
5
	vec2 offset = vec2(1.0/512.0, 1.0/512.0);
6
7
	float weight = 1.0;
8
	vec2 positionSum = gl_TexCoord[0].xy;
9
	float numPixelsL = 1.0;
10
	float numPixelsR = 1.0;
11
	float numPixelsU = 1.0;
12
	float numPixelsD = 1.0;
13
 
14
	int maxSize = 200;
15
	for (int i=1; i<maxSize && weight > 0.0; i++){
16
		vec2 currentOffset = float(i)*vec2(1.0, 0.0)* offset;
17
		weight = (texture2D(tex, gl_TexCoord[0].xy + currentOffset).r > 0.5 ? 1.0 : 0.0) * weight ; 
18
		numPixelsR = numPixelsR +  1.0* weight;
19
	}
20
	if(weight > 0.0){
21
		numPixelsR = 0.0;
22
		weight = 0.0;
23
	}else{
24
		weight = 1.0;
25
	}
26
27
	for (int i=1; i<maxSize && weight > 0.0; i++){
28
		vec2 currentOffset = float(i)*vec2(0.0, 1.0)* offset;
29
		weight = (texture2D(tex, gl_TexCoord[0].xy + currentOffset).r > 0.5 ? 1.0 : 0.0) * weight ; 
30
		numPixelsU = numPixelsU +  1.0* weight;
31
	}
32
	if(weight > 0.0){
33
		numPixelsU = 0.0;
34
		weight = 0.0;
35
	}else{
36
		weight = 1.0;
37
	}
38
39
	weight = 1.0;
40
	for (int i=1; i<maxSize && weight > 0.0; i++){
41
		vec2 currentOffset = float(i)*vec2(0.0, -1.0)* offset;
42
		weight = (texture2D(tex, gl_TexCoord[0].xy + currentOffset).r > 0.5 ? 1.0 : 0.0) * weight ; 
43
		numPixelsD = numPixelsD +  1.0* weight;
44
	}
45
	if(weight > 0.0){
46
		numPixelsD = 0.0;
47
		weight = 0.0;
48
	}else{
49
		weight = 1.0;
50
	}
51
	
52
	weight = 1.0;
53
	for (int i=1; i<maxSize && weight > 0.0; i++){
54
		vec2 currentOffset = float(i)*vec2(-1.0, 0.0)* offset;
55
		weight = (texture2D(tex, gl_TexCoord[0].xy + currentOffset).r > 0.5 ? 1.0 : 0.0) * weight ; 
56
		numPixelsL = numPixelsL +  1.0* weight;
57
	}
58
	if(weight > 0.0){
59
		numPixelsL = 0.0;
60
		weight = 0.0;
61
	}else{
62
		weight = 1.0;
63
	}
64
65
66
67
68
69
	if(numPixelsL > 5.0){
70
		float centerL = abs(numPixelsU - numPixelsD) < 2.0 ? 1.0 : 0.0;
71
		float centerR =  abs(numPixelsL - numPixelsR) < 2.0 ? 1.0 : 0.0;
72
		gl_FragColor = vec4(centerR, centerL , 0.0, 1.0);
73
	}
74
	else
75
		gl_FragColor = vec4(0.0,0.0,0.0,1.0);
76
}