Accessing Stencil buffer from fragment program

Started by
2 comments, last by imaginary 19 years, 4 months ago
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
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!
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...
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.

This topic is closed to new replies.

Advertisement