Question

I'm learning from a sample in DirectX SDK on shadow map. This sample created a stencil surface during initialization, and says:

 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.

What does this mean? I tried to comment the statements which creates and operates on the stencil buffer, then I got quite instable results: if I make the window greater, the shadow works well, while the shadow stops to move when I make the window much smaller. Does anyone can explain this to me? Thank you very much!!!

Was it helpful?

Solution

The Main DepthStencil buffer is the one used when rendering to the Main window and thus will have the same resolution as the Window. The shadowing process however doesn't have to use the same resolution, viewport and so on. That is why they create a second DepthStencil buffer that has the same resolution as the viewport that is used for rendering the Shadowmap.

Also, as the quote states, it might not be desirable to use the same Format, Multisampling settings and so on that you use to render your scene, to create the shadowmap.

Edit:

You use the stencil buffer because you want to store the depth of the nearest occluding triangle.

A DepthStencil buffer doesnt "support shadowmapping" its just a technique that happens to need a depthbuffer, preferably with certain attributes (like right size, no MSAA and so on)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top