Skip to main content
GameDev.net gamedev.net
🔒 Locked

Hardware Shadow Mapping Question

Started by GMano Jul 23, 2008 at 7:10 PM 2 replies 3.3k views
Original Post
GMano
GMano
I am using the Hardware Shadow Mapping using NVidia graphics card on my project, and it works fine. However, I am using quite a large shadow map, and I am forced to create a render target texture in addition to the depth texture in order to render to the depth buffer. The memory for this texture is just wasted, as I am only rendering the depth (calling SetRenderState(D3DRS_COLORWRITEENABLE, 0)) before rendering to the shadow map). Is there any way around this, or do you have to create a render target texture that you do not use in order for the hardware shadow mapping to work?
LeGreg
LeGreg
Quote:
Original post by GMano
I am using the Hardware Shadow Mapping using NVidia graphics card on my project, and it works fine. However, I am using quite a large shadow map, and I am forced to create a render target texture in addition to the depth texture in order to render to the depth buffer. The memory for this texture is just wasted, as I am only rendering the depth (calling SetRenderState(D3DRS_COLORWRITEENABLE, 0)) before rendering to the shadow map). Is there any way around this, or do you have to create a render target texture that you do not use in order for the hardware shadow mapping to work?


You can create a NULL rendertarget.

First you check that the device currently supports the NULL format for rendertargets (make sure to check return value and fall back to regular format if that's not supported !):

HRESULT hr = pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT,     D3DDEVTYPE_HAL,    AdapterFormat,    D3DUSAGE_RENDERTARGET,    D3DRTYPE_SURFACE,    (D3DFORMAT)MAKEFOURCC('N','U','L','L') );

Then if supported, you create the NULL RT :

HRESULT hr = pD3dDevice->CreateRenderTarget(sizex,    sizey,    (D3DFORMAT)MAKEFOURCC('N','U','L','L'),     D3DMULTISAMPLE_NONE /* use the DepthStencil buffer multisampling type here*/,     0 /* use the DepthStencil buffer multisample quality here */,     false /* certainly not lockable */,     &pNullSurface /* pointer to the surface you're creating */,     NULL /* HANDLE); 

You should use the depth buffer sizex and sizey, it doesn't matter to the driver but it may matter to the runtime (especially debug), so choose the right dimension to be on the safe size. In practice it will not take any significant video memory.

Then you set it as you would any rendertarget.

HRESULT hr = pD3dDevice->SetRenderTarget(0, pNullSurface);

Also if you use a NULL RT you don't need to set the color write enable mask to 0 because it is implied.

LeGreg

[Edited by - LeGreg on July 23, 2008 11:07:26 PM]
GMano
GMano
Quote:
Original post by LeGreg

You can create a NULL rendertarget.

First you check that the device currently supports the NULL format for rendertargets (make sure to check return value and fall back to regular format if that's not supported !):

*** Source Snippet Removed ***
Then if supported, you create the NULL RT :

*** Source Snippet Removed ***
You should use the depth buffer sizex and sizey, it doesn't matter to the driver but it may matter to the runtime (especially debug), so choose the right dimension to be on the safe size. In practice it will not take any significant video memory.

Then you set it as you would any rendertarget.

*** Source Snippet Removed ***
Also if you use a NULL RT you don't need to set the color write enable mask to 0 because it is implied.

LeGreg


Thank you! This worked like a charm.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.