1
/* Sobel filter, basically a way of finding the edges in an image.
3
* coord = current fragment coordinate
4
* size = vec2(1.0 / width, 1.0 / height)
7
float sobel(sampler2D tex, vec2 coord, vec2 size) {
8
/* computes a sobel value from the surrounding pixels */
10
vec2 basecoord = coord;
15
vert = texture2D(tex, basecoord + vec2(-step.x, -step.y)) * -1.0;
16
vert += texture2D(tex, basecoord + vec2(-step.x, 0.0 )) * -2.0;
17
vert += texture2D(tex, basecoord + vec2(-step.x, +step.y)) * -1.0;
19
vert += texture2D(tex, basecoord + vec2(+step.x, -step.y)) * 1.0;
20
vert += texture2D(tex, basecoord + vec2(+step.x, 0.0 )) * 2.0;
21
vert += texture2D(tex, basecoord + vec2(+step.x, +step.y)) * 1.0;
23
hori = texture2D(tex, basecoord + vec2(-step.x, -step.y)) * -1.0;
24
hori += texture2D(tex, basecoord + vec2( 0.0 , -step.y)) * -2.0;
25
hori += texture2D(tex, basecoord + vec2(+step.x, -step.y)) * -1.0;
27
hori += texture2D(tex, basecoord + vec2(-step.x, +step.y)) * 1.0;
28
hori += texture2D(tex, basecoord + vec2( 0.0 , +step.y)) * 2.0;
29
hori += texture2D(tex, basecoord + vec2(+step.x, +step.y)) * 1.0;
31
/* returns the dot product */
32
return float(sqrt((vert * vert) + (hori * hori)));