CuriousGeorge
CuriousGeorge

Reputation: 7400

Affect depth, or stencil buffer from inside fragment shader?

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

Upvotes: 3

Views: 1342

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474116

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

Upvotes: 4

Related Questions