操作实例:使用 Direct3D 11 中的深度缓冲区实现阴影卷Walkthrough: Implement shadow volumes using depth buffers in Direct3D 11

本操作实例演示如何使用深度映射呈现阴影卷,并在所有 Direct3D 功能级别的设备上使用 Direct3D 11。This walkthrough demonstrates how to render shadow volumes using depth maps, using Direct3D 11 on devices of all Direct3D feature levels.

主题Topic 描述Description

创建深度缓冲区设备资源Create depth buffer device resources

了解如何创建支持阴影卷的深度测试所需的 Direct3D 设备资源。Learn how to create the Direct3D device resources necessary to support depth testing for shadow volumes.

将阴影映射呈现到深度缓冲区Render the shadow map to the depth buffer

从光线的角度呈现,以创建一个表示阴影卷的二维深度映射。Render from the point of view of the light to create a two-dimensional depth map representing the shadow volume.

通过深度测试呈现场景Render the scene with depth testing

通过向顶点(或几何图形)着色器和像素着色器中添加深度测试来创建阴影效果。Create a shadow effect by adding depth testing to your vertex (or geometry) shader and your pixel shader.

在许多硬件上支持阴影图Support shadow maps on a range of hardware

在速度更快的设备上更高保真度地呈现阴影,在功能不够强大的设备上更快地呈现阴影。Render higher-fidelity shadows on faster devices and faster shadows on less powerful devices.

 

阴影映射应用程序到 Direct3D 9 桌面的移植Shadow mapping application to Direct3D 9 desktop porting

Windows 8 adde d 深度比较功能,功能级别为 9 _ 1 和 9 _ 3。Windows 8 adde d depth comparison functionality to feature level 9_1 and 9_3. 现在,你可以将具有阴影卷的呈现代码迁移到 DirectX 11,并且 Direct3D 11 呈现器将是与功能级别 9 设备兼容的下一级设备。Now you can migrate rendering code with shadow volumes to DirectX 11, and the Direct3D 11 renderer will be downlevel compatible with feature level 9 devices. 本操作实例介绍任何 Direct3D 11 应用或游戏如何使用深度测试实现传统的阴影卷。This walkthrough shows how any Direct3D 11 app or game can implement traditional shadow volumes using depth testing. 代码包含以下过程:The code covers the following process:

  1. 为阴影映射创建 Direct3D 设备资源。Creating Direct3D device resources for shadow mapping.
  2. 添加呈现传递以创建深度映射。Adding a rendering pass to create the depth map.
  3. 将深度测试添加到主呈现传递。Adding depth testing to the main rendering pass.
  4. 实现必需的着色器代码。Implementing the necessary shader code.
  5. 用于在下一级硬件上快速呈现的选项。Options for fast rendering on downlevel hardware.

完成本演练后,应熟悉如何在 Direct3D 11 中实现与功能级别 9 _ 1 及更高版本兼容的基本兼容卷技术。Upon completing this walkthrough, you should be familiar with how to implement a basic compatible shadow volume technique in Direct3D 11 that's compatible with feature level 9_1 and above.

必备条件Prerequisites

应该准备通用 Windows 平台 (UWP) DirectX 游戏开发的开发人员环境You should Prepare your dev environment for Universal Windows Platform (UWP) DirectX game development. 目前,你还不需要模板,但需要使用 Microsoft Visual Studio 2015 为此操作实例生成代码示例。You don't need a template yet, but you'll need Microsoft Visual Studio 2015 to build the code sample for this walkthrough.

Direct3DDirect3D

阴影映射技术文章Shadow mapping technical articles