默认情况下创建的深度模板缓冲区导致的问题

时间:2013-04-24 11:17:43

标签: directx stencil-buffer shadow-mapping

我正在从阴影贴图上的DirectX SDK中的示例中学习。该示例在初始化期间创建了一个模板表面,并说:

 Create the depth-stencil buffer to be used with the shadow map

 We do this to ensure that the depth-stencil buffer is large
 enough and has correct multisample type/quality when rendering
 the shadow map.  The default depth-stencil buffer created during
 device creation will not be large enough if the user resizes the
 window to a very small size.  Furthermore, if the device is created
 with multisampling, the default depth-stencil buffer will not
 work with the shadow map texture because texture render targets
 do not support multisample.

这是什么意思?我试图评论在模板缓冲区上创建和操作的语句,然后我得到了相当不稳定的结果:如果我使窗口更大,阴影效果很好,而当我使窗口更小时阴影停止移动。 有人能解释一下吗?非常感谢!!!

1 个答案:

答案 0 :(得分:2)

主DepthStencil缓冲区是渲染到主窗口时使用的缓冲区,因此具有与Window相同的分辨率。 然而,阴影过程不必使用相同的分辨率,视口等。这就是为什么他们创建第二个DepthStencil缓冲区,其分辨率与用于渲染Shadowmap的视口相同。

此外,正如引用所述,可能不希望使用相同的格式,多重采样设置等来渲染场景,以创建阴影贴图。

编辑:

您使用模板缓冲区,因为您想要存储最近的遮挡三角形的深度。

DepthStencil缓冲区不支持“阴影贴图”,它只是一种恰好需要深度缓冲的技术,最好是具有某些属性(如正确的大小,没有MSAA等)

相关问题