D3DBook:D3D10 1 Considerations for Shadows

From GDWiki
Jump to: navigation, search

Direct3D 10.1 considerations for shadow rendering

Direct3D 10.1, a new version of the Microsoft’s graphic API announced in late 2007 and launched at March 2008, provides two new capabilities that are very suitable for rendering shadows more efficiently than with the 10.0 baseline:

Gather instruction

This new texture-related instruction can be used to load the red components of 4 nearest texels of a texture to a float4 register, given a sample position. While the classic-style texture sampler is sufficient for most texturing purposes with point, bilinear and trilinear filtering capabilities, using the Gather instruction enables the developer to access the raw data of the sample and implement a custom filtering algorithm for quality enhancement or special effects.

As Gather only loads the red components of the source texels, it is not directly usable to replace the default samplers when dealing with ordinary color data – instead, the method is most useful in implementing a custom filter for shadow map edges. If the developer has an error heuristic available at the time of drawing a shadow map, that heuristic can be used in weighting the 4 samples together for far higher quality than the default 4-tap filter is capable of. The error heuristic could be as simple as a texture of 2D vectors telling how far the actual edge of the shadow caster is at any given shadow texel. Also, sophisticated image-space shadow edge blurs become more feasible.

Gather is represented by a method in the texture object, when the HLSL code is compiled with the 4.1 profile. The source texture must contain a red channel; for typeless depth textures, this typically matches the first and only channel that, unsurprisingly, represents depth values.

Cube map arrays

Direct3D 10.1 introduces the ability to address multiple cube maps as shader-indexable arrays. For shadows, this means that it is possible to simultaneously create cubic shadow maps for arbitrary number of point lights by using single draw call; this contrasts the way that baseline 10.0 needs all the cubes to be rendered with their own draw calls. When using the generated shadow cubes to render the shadowed scene, the pixel shader can again access them as source array of cubes for further efficiency gains.

To create cube map arrays, create a resource of type Texture2DArray containing enough data to fill your cube array. Then, create a shader resource view for this resource by using the new method ID3D10Device1::CreateShaderResourceView1() that is a new version of this method for the Direct3D 10.1 functionality level devices. The D3D10_SHADER_RESOURCE_VIEW_DESC1 structure used in that method has been augmented from the 10.0 baseline version in that it can contain a new resource view parameter structure, D3D10_TEXCUBE_ARRAY_SRV1. In addition to the ordinary cube map parameters, this structure has an integer member “NumCubes” that you can use to specify the number of distinct cubes for your resource view. Bound as a render target, a cube map array is indexed in the same fashion as an array of 2D textures; there is no separate render target view exclusively for cubes.

When using texture cube arrays as input to the pixel shader, use the new type TextureCubeArray to declare the reference to your cube array resource view; as you then sample the data from the array, use the first three texture coordinate components as the normal that you would use with sampling a single cube, and set the w component to the index of the cube that you want to use.

Personal tools