Jump to content
  • Advertisement
Sign in to follow this  
mompox

OpenGL Accessing Stencil buffer from fragment program

This topic is 4977 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

Hi, I need to know how can I do to access (to Read and Write) the stencil buffer from within a fragment program / pixel shader. I was working with CG and OpenGl, but I didn't manage to figure it out. Is this possible with CG? is it possible with HLSL? Is it possible at all? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You could retrieve the stencil buffer and pass it to the pixel/fragment shader as a texture, that way you can read from the stencil buffer, I'm not too sure whether you could write to the stencil buffer, my insticts say no, but i have no experience with cg or hlsl, so don't want to say definately not!

Share this post


Link to post
Share on other sites
Thank you for your answer. I need this because I'm trying to implement something form a paper. In the paper says that you could use the stencil buffer to carry the "state" of the fragments, and this state was changed from within the fragment programs...
Maybe I misundestood the paper, thats why I'm asking if this is possible at all...

Share this post


Link to post
Share on other sites
Currently, direct access to the stencil buffer is not possible from within a fragment shader. To quote the ARB_fragment_program specs (which CG compiles down to):

Quote:

(11) Should we standardize options for stencil or aux data buffer
outputs?

RESOLVED: Stencil and aux data buffers will be saved for a
possible future extension to fragment programs.


Until this is implemented, the alpha component of the framebuffer might be a viable alternative ? Fragment shaders can directly write to it, and can read it, if the render target is bound as a texture in a successive pass.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!