/cournia.com/dev/null - convolution home
convolution with vertex/fragment programs November 10, 2003

I decided to give running convolution filters in vertex/fragment programs a try. I've heard that people were doing this but I couldn't find any demos or documentation about the subject. The approach I took was to use a vertex program to generate texture coordinates for samples around a fragment. I then use a fragment program to apply a given kernel (which is passed in via local parameters) to the fragment and its neighbors.

I was surprised on how easy it was to implement. The speed was even good on my GeForceFX 5200!

The demo only supports a 9x9 1 pass filter, but I'll probably add support for larger/separable filters in the future.

Here's AVP's coffee cup with the following Laplacian kernel applied:

-1-1-1
-18-1
-1-1-1

 

Here's an image with the following smoothing kernel applied:

121
242
121

 

I should probably add a scaling/biasing term that would be applied at the end of the convolution.

  index