http://www.gamedev.net/topic/451617-how-the-stencil-buffer-works/
The order of operations goes like this (assuming the stencil test is enabled):
1) Perform stencil test. If failed, perform StencilFail operation and discard pixel. If passed, go to step 2.
2) Perform depth test. If failed, perform StencilZFail operation and discard pixel. If passed, perform StencilPass operation and write pixel color/depth.
So to answer your questions, the stencil test is based solely on the current value in the stencil buffer, the stencil reference value, and the stencil mask. It has to be, since it's done first. The depth test is performed only if the stencil test passes or is disabled.
The DX documentation can provide more details.
深度缓存和模板缓存操作顺序如下(假定模板缓存开启)
(1)执行模板测试,如果失败,执行模板测试失败的操作并且丢弃此像素(也就是禁止其写入后台缓存或颜色缓存),如果测试通过,执行下一步
(2)执行深度测试(或Z测试),如果失败,执行深度测试失败的操作,并且丢弃此像素。如果通过,那么执行模板通过操作并且写入像素到后台缓存中。
所以说深度测试执行仅在模板测试通过或则模板测试关闭的情况下。
D3DRS_STENCILENABLE 指定是否开启模板测试
本文介绍了在图形渲染中,深度测试与模板测试的执行流程。首先进行模板测试,根据当前模板缓存值、参考值和掩码执行相应操作。若模板测试通过,则进行深度测试,若深度测试通过,则将像素写入后台缓存。深度测试只在模板测试通过或关闭时执行。这对于理解3D图形渲染中的缓存管理至关重要。
2133

被折叠的 条评论
为什么被折叠?



