关于 glColorMask 及其工作的快速问题
我想渲染深度缓冲区来进行一些漂亮的阴影贴图。不过,我的绘图代码由许多着色器开关组成。如果我设置 glColorMask(0,0,0,0)
并保留所有着色器程序、纹理和其他内容不变,只渲染深度缓冲区,会“OK”吗?我的意思是,如果 glColorMask 禁用“写入颜色分量”,是否意味着每个片段着色不会执行?
I want to render depth buffer to do some nice shadow mapping. My drawing code though, consists of many shader switches. If I set glColorMask(0,0,0,0)
and leave all shader programs, textures and others as they are, and just render the depth buffer, will it be 'OK' ? I mean, if glColorMask disables the "write of color components", does it mean that per-fragment shading IS NOT going to be performed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,着色器程序的执行独立于固定功能管道。设置
glColorMask
不会对着色器程序产生影响。No, the shader programs execute independent of the fixed function pipeline. Setting the
glColorMask
will have no effect on the shader programs.为了渲染阴影贴图,您通常需要将深度纹理(最好是平方和 2 的幂,因为立体驱动程序将此作为提示!)绑定到 FBO,并为所有内容仅使用一个着色器(尽可能简单)。您不想附加颜色缓冲区,因为您对颜色根本不感兴趣,并且它给 ROP 带来了更多不必要的压力(另外,某些硬件可以仅以深度渲染双倍速度或更高速度)。您不想在许多着色器之间切换。
根据您是否执行“经典”阴影贴图,或者更复杂的操作(例如指数阴影贴图),您将使用的着色器要么尽可能简单(恒定颜色,无深度写入),要么执行一些(适度)复杂)深度计算,但您通常不想执行任何颜色计算,因为这意味着不必要的计算,这些计算以任何方式都不可见。
For rendering a shadow map, you will normally want to bind a depth texture (preferrably square and power of two, because stereo drivers take this as hint!) to a FBO and use exactly one shader (as simple as possible) for everything. You do not want to attach a color buffer, because you are not interested in color at all, and it puts more unnecessary pressure on ROP (plus, some hardware can render double speed or more with depth-only). You do not want to switch between many shaders.
Depending on whether you do "classic" shadow mapping, or something more sophisticated such as exponential shadow maps, the shader that you will use is either as simple as it can be (constant color, and no depth write), or performs some (moderately complex) calculations on depth, but you normally do not want to perform any colour calculations, since that will mean needless calculations which will not be visible in any way.
不,片段操作无论如何都会执行,但它们的结果将被您的零颜色蒙版压扁。
如果您不想执行某些片段操作 - 请使用附加了空片段着色器的正确着色器程序,并将绘制缓冲区设置为 GL_NONE。
还有另一种禁用片段处理的方法 - 启用 GL_RASTERIZER_DISCARD,但在这种情况下您甚至无法获得深度值:)
No, the fragment operations will be performed anyway, but their result will be squashed by your zero color mask.
If you don't want some fragment operations to be performed - use the proper shader program which has an empty fragment shader attached and set the draw buffer to GL_NONE.
There is another way to disable fragment processing - to enable GL_RASTERIZER_DISCARD, but you won't get even the depth values in this case :)