# Shadowmapping ( Omni Directional Lights ) & Depth buffer

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey I'm currently implementing a shadow mapping technique in my engine to create dynamic shadows. But I'm having abit of a problem with setting the render targets. When I set my new depth stencil and try to draw to the shadow map D3D tells me : "Direct3D9: (ERROR) :DepthStencil Buffer must be at least as big as the RenderTarget." And I totally agree with that, only, it should be as big since I use the same constant value when creating them. I'm including the code below, any ideas on what I'm doing wrong would be greatly appreciated. Creation of Shadowmap and its depth buffer
if ( FAILED ( D3DXCreateCubeTexture(m_pDev,SHADOWRESOLUTION,D3DX_DEFAULT,D3DUSAGE_RENDERTARGET,

Loggline("Failed to create the back buffer for the shadow map");

Render code...
  // loops thru all sides and renders to the shadow map
{
LPDIRECT3DSURFACE9 pFace=NULL;

m_pDev->SetRenderTarget( 0 , pFace );

// Draw object

SAFE_RELEASE(pFace);

}

m_pDev->SetDepthStencilSurface( pZBuffer );
m_pDev->SetRenderTarget( 0 , pBackBuffer );

SetupPerspective();
m_pDev->SetTransform(D3DTS_VIEW, &m_pCurrentScene->GetCamera()->GetViewMatrix());

// Render again this time with a shadow map



##### Share on other sites
Oh, that was a simple fix :-) Had forgot to change it back to my power of two setting ( tried to change it when I got some other errors )...

Thanks....

##### Share on other sites
Hmm...interesting that it would give that error when a non power of 2 size was used...Does the API automatically, hm, round down (or up) to powers of 2 for some things like that?

##### Share on other sites
Ya, thats defintily possible, 'cause if I multiplied the resolution by two it worked... First I was thinking that perhaps it just printed the wrong error message ( i.e. my depth buffer was in an invalid format but it figured that the size was invalid , but when I tried making the depth buffer ridicisly large it worked, so it has to round it up or down to a power of two size...

##### Share on other sites
Quick question (off topic a bit): Is shadowmapping faster than volume shadows, or are they similar speeds? What is the difference in between the two?

Thanks!

##### Share on other sites
Quote:
 Original post by JoCCoYa, thats defintily possible, 'cause if I multiplied the resolution by two it worked... First I was thinking that perhaps it just printed the wrong error message ( i.e. my depth buffer was in an invalid format but it figured that the size was invalid , but when I tried making the depth buffer ridicisly large it worked, so it has to round it up or down to a power of two size...

Make your own function to create correct size automatically. I'm use this function for it :

inline int GetPowerOf2 (int n)
{
int low = 1;
for (; low < n; low <<= 1);
return low;
}

##### Share on other sites
Quote:
 Original post by GremlinXQuick question (off topic a bit): Is shadowmapping faster than volume shadows, or are they similar speeds? What is the difference in between the two?Thanks!

They have different performance aspects. Shadow maps have a big performance hit right off the bat due to the SM generation, but on higher end cards, as geometry increases the speed doesn't increase very much. The opposite is true for SVs, where performance is quite linear in comparison, and for lower poly models is quite a bit faster.

Right now though, my shadow map demo, which is currently unoptimized IRT performance, can run circles around an unoptimized SV demo (the DX9SDK one) on my X800Pro when using high poly objects like the skull. Plus, I think that there is greater opportunity for speed optimizations for SMs compared to SVs, so my SMs will have a greater benefit. I highly doubt though that, say, a 9600 would run my SM demo faster than the SV demo.

In terms of IQ pros/cons: SMs get to have soft shadows at a nice performance, but they suffer from the typical SM aliasing. The opposite is true for SVs.

##### Share on other sites
My thought on the pow2 thing was that you can create a shadow map of any size, but a cubemap must be a power of 2...

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 12
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633354
• Total Posts
3011493
• ### Who's Online (See full list)

There are no registered users currently online

×