关于Depth Bounds Test (DBT)和在CE3的运用
- DBT的逻辑是在 scissor test 后面, alpha testing前面
- min/max值被clamp在[0, 1]之间,非法值会被转为0
- DBT会被打开,当下面条件都为真时
- min < max
- min > 1 并且 max<1
- depth值在Shader里被使用
void CD3D9Renderer::SetDepthBoundTest(float fMin,float fMax,bool bEnable) { if(bEnable) { m_pd3dDevice->SetRenderState(D3DRS_ADAPTIVETESS_X,MAKEFOURCC(‘N‘,‘V‘,‘D‘,‘B‘)); m_pd3dDevice->SetRenderState(D3DRS_ADAPTIVETESS_Z,*(DWORD*)&fMin); m_pd3dDevice->SetRenderState(D3DRS_ADAPTIVETESS_W,*(DWORD*)&fMax); } else// disable depth bound test { m_pd3dDevice->SetRenderState(D3DRS_ADAPTIVETESS_X,0); } }
DBT的主要用处有两个,一个例子是在OpenGL extension文档里的例子 可以用来优化stenciled shadow volume 的渲染
-
SetDepthBoundTest(0.f,0.9999f,true);
下雨效果
CD3D9Renderer::FX_DeferredRainLayer()
constVec4 vDepthBounds =CDeferredShading::Instance().GetLightDepthBounds(rainVolParams.m_vWorldPos, rainVolParams.m_fRadius); SetDepthBoundTest(max(vDepthBounds.x, fMinZ), min(vDepthBounds.z, fMaxZ),true);
下雪效果
CD3D9Renderer::FX_DeferredSnowLayer()
constVec4 vDepthBounds =CDeferredShading::Instance().GetLightDepthBounds(snowVolParams.m_vWorldPos, snowVolParams.m_fRadius); SetDepthBoundTest(max(vDepthBounds.x, fMinZ), min(vDepthBounds.z, fMaxZ),true);
延迟光照着色
CDeferredShading::LightPass
-
Vec4 pDepthBounds =GetLightDepthBounds( pDL ); rd->SetDepthBoundTest( pDepthBounds.x, pDepthBounds.z,true);
IBL的延迟着色
CDeferredShading::DeferredCubemapPass
-
Vec4 pDepthBounds =GetLightDepthBounds( pDL ); rd->SetDepthBoundTest( pDepthBounds.x, pDepthBounds.z,true);
屏幕空间反射
CDeferredShading::ScreenSpaceReflectionPass
-
rd->SetDepthBoundTest(0.0f,0.9999f,true);
CDeferredShading::DirectionalOcclusionPass()
-
CDeferredShading::DirectionalOcclusionPass()
阴影处理
CDeferredShading::ShadowLightPasses()
-
Vec4 pDepthBounds =GetLightDepthBounds(&light ); rd->SetDepthBoundTest( pDepthBounds.x, pDepthBounds.z,true);
为了在绘制里可以忽略天空部分
void CDeferredShading::Render()
if(CRenderer::CV_r_DeferredShadingDepthBoundsTest ) { constVec4 pDepthBounds =CDeferredShading::Instance().GetLightDepthBounds( rRendSettings.m_pos, m_fDistance ); rd->SetDepthBoundTest(pDepthBounds.x, pDepthBounds.z,true);// skip sky only for GI }
修改方法也比较简单,关闭CV_r_DeferredShadingDepthBoundsTest,或在shader里添加clip来discard掉像素,或用alpha test替代,但这两种方法在移动平台上忌讳的,所以需要进一步测试才有结果了
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。