summaryrefslogtreecommitdiff
path: root/src/sobel.frag
blob: dd07bf5ac6cee561b50c56b6a827d29c4f6a851b (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
#version 130

in vec2 texcoord;
uniform sampler2D sampler;

void main(void)
{
	// http://www.roborealm.com/help/Sobel.php
	vec4 p1 = textureOffset(sampler, texcoord, ivec2(-1, -1));
	vec4 p2 = textureOffset(sampler, texcoord, ivec2( 0, -1));
	vec4 p3 = textureOffset(sampler, texcoord, ivec2( 1, -1));
	vec4 p4 = textureOffset(sampler, texcoord, ivec2(-1,  0));
	vec4 p5 = textureOffset(sampler, texcoord, ivec2( 0,  0));
	vec4 p6 = textureOffset(sampler, texcoord, ivec2( 1,  0));
	vec4 p7 = textureOffset(sampler, texcoord, ivec2(-1,  1));
	vec4 p8 = textureOffset(sampler, texcoord, ivec2( 0,  1));
	vec4 p9 = textureOffset(sampler, texcoord, ivec2( 1,  1));

	vec4 Gx = p1+2*p2+p3-p7-2*p8-p9;
	vec4 Gy = p3+2*p6+p9-p1-2*p4-p7;

	vec4 G = sqrt(Gx * Gx + Gy * Gy);
	gl_FragColor = G;
}