Queries about my edge detection shader and RTT

I’ve written an edge detect shader and after bashing my head against a wall I got it working, but I’m not sure why.

First off, this reference Orange Book, section 19.7.2 (and I’m sure there were others, or similar), shows a convolution matrix of

   0, 1, 0
   1,-4, 1
   0, 1, 0

but that will produce a -ve final vector and if I set gl_FragColor it then I get black. So I had to negate the above matrix. I’m I missing something?

The second thing is I am rendering a 2048x2048 texture to a 128x128 texture. I thought the offsets to move the sample coord would be 1/2048 (e.g. add 1/2048,1/2048 to S,T to sample the pixel 1 to the right and 1 up from the current pixel), but I had to use 1/128. Don’t undertand why.



D’oh! Shouldn’t have been doing that at 1 in the morning. Realised why it’s 1/128 (since the 2040 texture is mapped to a 128 quad).

However, still interested if I am missing something about the matrix values.

The matrix above will produce 0 for flat color areas, 1 for pure black to pure white transition as well as from white to black, etc. You want to multiply the result if it is too dark.

If the original image is too blurry, you may have to widen the kernel.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.