The edge detect filter is another convolution. The eight neighboring input pixels all contribute to the output.
1.0 / 512.0
texture2D
(colorTexture, fragmentTexCoord + vec2
(−d, −d)).rgb
texture2D
(colorTexture, fragmentTexCoord + vec2
(0
, −d)).rgb
texture2D
(colorTexture, fragmentTexCoord + vec2
(+d, −d)).rgb
texture2D
(colorTexture, fragmentTexCoord + vec2
(−d, 0
)).rgb
texture2D
(colorTexture, fragmentTexCoord + vec2
(0
, 0
)).rgb
texture2D
(colorTexture, fragmentTexCoord + vec2
(+d, 0
)).rgb
texture2D
(colorTexture, fragmentTexCoord + vec2
(−d, +d)).rgb
texture2D
(colorTexture, fragmentTexCoord + vec2
(0
, +d)).rgb
texture2D
(colorTexture, fragmentTexCoord + vec2
(+d, +d)).rgb
gl_FragColor
← vec4
(sqrt
(x * x + y * y), 1.0
)
In the case of edge detection, the pixel values are subtracted instead of added. Thus a simple derivative is calculated along the x and y axes. Thes differences are combined as a gradient, which highlights the changes in the image, and thus detects edges.