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.
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