2

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

CuriousGeorge
  • 7,120
  • 6
  • 42
  • 74

1 Answers1

4

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

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982