Question

I know it is possible to control what is written to the depth buffer in GLSL by writing to gl_FragDepth, but is it possible to write to the stencil buffer?

Also, can I cancel a pixel write completely from within the fragment-shader, as if the pixel had failed a stencil or depth test?

Thanks

Was it helpful?

Solution

If you are using the right hardware, you can write to the stencil buffer. All Radeon HD hardware can use AMD_stencil_shader_export. There is an ARB_stencil_shader_export, but I can't verify if it is particularly widespread.

If you want to stop a fragment from writing anything, you can use discard. It's sort of like throwing an exception conceptually (but not behaviorally).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top