PDA

View Full Version : Stencil Buffer on a per-pixel level.



Crane
12-28-2003, 03:57 PM
I have a black-and-white texture (made up of only {0.0, 0.0, 0.0, 0.0} and {1.0, 1.0, 1.0, 1.0} RGBA elements) and I need to draw it in a way so only the white pixels of where the texture is drawn have their stencil values changed. How do I do this accurately?

dorbie
12-28-2003, 04:25 PM
Load the image into an alpha texture and use glEnable(GL_ALPHA_TEST) glAlphaFunc to cull the fragments you don't want.

Depending on your objective you may have to do this in a separate pass after you draw the object to the visible buffers. You could use glColorMask to limit rendering to the stencil buffer.

Crane
12-28-2003, 04:41 PM
Thanks Dorbie, the alpha test works a treat. So many different tests... Alpha, Stencil, Depth... it gets confusing!

My objective was to draw a portion of the background onto an irregularly shaped region, hence why I needed the stencil buffer. The effect is the "cloak blur", which I mentioned in the "OpenGL coding: advanced" forum.

[This message has been edited by Praetor PredAtor (edited 12-28-2003).]

dorbie
12-28-2003, 05:00 PM
I see... you could adjust the alpharef dynamically and have a greyscale image instead of a black & white checker pattern and fade the shimmer in and out. :-)

The grey scale pattern would be some appropriate blended distribution of black & white blobs.

However all of these give you a bit of a discontinuous shimmer with sharp edges around the culled fragments.

Simply drawing the original object in place with a texgen in eye space of the original image with a bit of displacement or a vertex program to peturb the image with a bit of per vertex noise could also look cool and most likely a bit refractive.