Search code examples
gpuvulkanamd-gpu

How can I make fragment_shader have a ouput to stencil_attachment?


I want to implement a pipeline, which can copy stencil image to stencil image. I want to use a texelfetch read the src image as the sampler2D in glsl, and output to the stencil image_attachment.

Are there any built-in variable like gl_fragdepth, which can help implement the copy image to image?

The wiki of glsl said:

After processing, the output fragment from a fragment shader consists of the following:

a depth value, either written by the fragment shader or passed through from the screen-space fragment's Z value. a stencil value. An array of zero or more color values, as written by the fragment shader. Any entries in the array which the fragment shader did not write have undefined values.

How to output a stencil value?


Solution

  • You cannot. Outside of certain extensions (not supported by NVIDIA), the fragment shader cannot modify the stencil value or the results of its test.