开发者

Quick question about glColorMask and its work

开发者 https://www.devze.com 2023-02-09 07:23 出处:网络
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

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?


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.


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


No, the shader programs execute independent of the fixed function pipeline. Setting the glColorMask will have no effect on the shader programs.

0

精彩评论

暂无评论...
验证码 换一张
取 消