The edge detect filter is another convolution. The eight neighboring input pixels all contribute to the output.
1.0 / 512.0texture2D(colorTexture, fragmentTexCoord + vec2(−d, −d)).rgbtexture2D(colorTexture, fragmentTexCoord + vec2(0, −d)).rgbtexture2D(colorTexture, fragmentTexCoord + vec2(+d, −d)).rgbtexture2D(colorTexture, fragmentTexCoord + vec2(−d, 0)).rgbtexture2D(colorTexture, fragmentTexCoord + vec2(0, 0)).rgbtexture2D(colorTexture, fragmentTexCoord + vec2(+d, 0)).rgbtexture2D(colorTexture, fragmentTexCoord + vec2(−d, +d)).rgbtexture2D(colorTexture, fragmentTexCoord + vec2(0, +d)).rgbtexture2D(colorTexture, fragmentTexCoord + vec2(+d, +d)).rgbgl_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.