简体   繁体   English

影响深度,还是片段着色器内部的模板缓冲区?

[英]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? 我知道可以通过写入gl_FragDepth来控制写入GLSL中的深度缓冲区的内容,但是可以写入到模板缓冲区吗?

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

If you are using the right hardware, you can write to the stencil buffer. 如果使用正确的硬件,则可以写入模板缓冲区。 All Radeon HD hardware can use AMD_stencil_shader_export. 所有Radeon HD硬件都可以使用AMD_stencil_shader_export。 There is an ARB_stencil_shader_export, but I can't verify if it is particularly widespread. 有一个ARB_stencil_shader_export,但是我无法验证它是否特别广泛。

If you want to stop a fragment from writing anything, you can use discard . 如果要阻止某个片段写任何东西,可以使用discard It's sort of like throwing an exception conceptually (but not behaviorally). 这有点像在概念上(但在行为上)抛出异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM