• Advertisement
Sign in to follow this  

how to access stencil buffer from shaders

This topic is 4760 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how do i access (or use somehow) the stencil buffer from a pixel-shader ? a Cg or GLSL example would be helpful

Share this post


Link to post
Share on other sites
Advertisement
I'm pretty confident that you can't access it directly. You could, however, do some sort of multipass thing where you do the following:

1. Write to stencil buffer

2. Switch to a render texture (with same dimensions and stencil buffer as the main render target)
3. Render all stencilled pixels in white (no depth writes or compares)
4. Render non-stencilled pixels in black (again, no depth writes or compares)

5. Switch back to main render target.
6. Use that texture from the shader. Then, white is "stenciled" and black is "not".

It's not as fast as direct access, but it's about the only thing I can think of to do if you actually NEED that data for something.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement