关于Z(Depth 深度)和Stencil(模板)两种测试对后台缓存的影响次序

本文介绍了在图形渲染中,深度测试与模板测试的执行流程。首先进行模板测试,根据当前模板缓存值、参考值和掩码执行相应操作。若模板测试通过,则进行深度测试,若深度测试通过,则将像素写入后台缓存。深度测试只在模板测试通过或关闭时执行。这对于理解3D图形渲染中的缓存管理至关重要。

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   指定是否开启模板测试

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值