Shadow mapping: D3DUSAGE_DEPTHSTENCIL or D3DUSAGE_RENDERTARGET?

Started by
13 comments, last by Tispe 10 years, 5 months ago

Hi

Reading the nvidia shadow mapping guide it uses a depthstencil surface to render the shadow map:


pD3DDev->CreateTexture(texWidth, texHeight, 1,
D3DUSAGE_DEPTHSTENCIL, D3DFMT_D24S8, D3DPOOL_DEFAULT,
&pTex);

You don't need stencil for shadow/depth texture, use D24X8.

Advertisement

Thanks guys. I think I will go for the D3DUSAGE_RENDERTARGET, D3DFMT_R32F, surface since I am targeting DX9 hardware and I need to most compatibility, and I don't want to complicate things by writing hardware specific code at this stage.

For ultra compatibility, you can use a regular 8888 target, and use the shader to split the 32bit depth value into 4 8bit values (and in the shader that applies shadow, you can put those 4 values back together into the original value using a dot product). However, you have to wonder if GPUs that are this old even have enough horsepower to deliver decent FPS with shadow mapping, etc wink.png

You can see here which GPUs will support 32F or 16F render targets:

http://zp.amsnet.pl/cdragan/query.php?dxversion=9&feature=formats&featuregroup=selected&adaptergroup=groups&adapterselected%5B%5D=NVidia&adapterselected%5B%5D=Intel&adapterselected%5B%5D=ATi&featureselected%5B%5D=53&featureselected%5B%5D=50&featureselected%5B%5D=1&resource=TEXTURE&usage=RENDERTARGET&orientation=horizontal

e.g. 32F render targets are ~GeForce 5 upwards and Radeon 9500 upwards, but will not work on Intel's DX9 cards.

You can read a lot of the fancy "vendor specific" D3D9 stuff here:

http://developer.amd.com/wordpress/media/2012/10/Advanced-DX9-Capabilities-for-ATI-Radeon-Cards_v2.pdf

Most of the stuff in that document isn't actually ATI-specific, as the link that Mona2000 posted above shows.

AFAIK, The D24 shadow-map stuff, with built-in automatic hardware PCF via the sampler, is actually supported on more cards than 32F render-targets unsure.png

Any DX10+ GPU will also work with the INTZ format in the above PDF, which is basically a normal D24S8 depth buffer, but is able to be used as a texture like in D3D10/11. This is my preferred format for depth buffers on D3D9 (when you don't want the automatic in-build PCF stuff) -- I even use it for the main depth buffer so that I can do DOF post-processing, etc... (assuming it's supported -- otherwise I disable the DOF/etc code).

Thanks for the pdf, Hodgman. I may actually try to implement shadow maping using a depthstencil again with this new knowledge smile.png

Trying to implement this. I've been fiddling with Z buffer issue for hours now. Shadow Map is 512x512, I render to it fine but it seems like Z buffer is disabled, even though I enabled it and clear it properly. After I render to Shadow Map, I set the Back Buffer back, clear it and everything renders as normal. I draw the shadow map texture as a sprite ontop just to verify.

What could be the issue? Do I have to make a special zbuffer aswell? -.-


d3ddev->CreateTexture(512, 512,
		1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8,	//D3DFMT_R32F
		D3DPOOL_DEFAULT, &pShadowMapTexture, NULL);

This topic is closed to new replies.

Advertisement