Stencil access from fragment shaders

Can I get access to the value in the stencil buffer at the fragment I am evaluating?

That is, can I do something like:

int st = gl_StencilValue;
int c1 = st%2;
int c2 = (st%4)/2;
vec4 color = color1c1 + color2c2;

The above, of course, isn’t exactly what I would be doing, but it’s enough to give you an idea.
Anyway, is this possible?

AFAIK, it is not posible on current hardware. Please read Issue 7 - Is alpha blending programmable? in GLSLangSpec.Full.1.10.59.pdf GLSLangSpec.Full.1.10.59.pdf on page 75.

yooyo

It’s clearly stated in chapter 2.2 Fragment Processor that this is not possible today.

The fragment processor does not replace the fixed functionality graphics operations that occur at the back end of the OpenGL pixel processing pipeline such as:
• Shading model
• Coverage
• Pixel ownership test
• Scissor
• Stipple
• Alpha test
• Depth test
• Stencil test
• Alpha blending
• Logical ops
• Dithering
• Planemasking

Right, thanks for pointing out the relative sections of the docs. I think I’ll have to render into a texture buffer, and use that instead of the stencil buffer. Then, I can just bind it to one of the texture units, and my shaders can be reasonably happy :slight_smile:

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