Jump to content
  • Advertisement
Sign in to follow this  
JoCCo

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.

If you intended to correct an error in the post then please contact us.

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,    
		D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pShadowMap) ) )
		Loggline("Failed to create shadow map"); 

if( FAILED ( m_pDev->CreateDepthStencilSurface(SHADOWRESOLUTION,SHADOWRESOLUTION,D3DFMT_D24X8,D3DMULTISAMPLE_NONE ,
					0, true, &m_pShadowDepthBuffer,NULL) ) )
					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_pShadowMap->GetCubeMapSurface((D3DCUBEMAP_FACES)iSide, 0, &pFace);

    m_pDev->SetRenderTarget( 0 , pFace );
    m_pDev->SetDepthStencilSurface( m_pShadowDepthBuffer );

     // Draw object
					
    SAFE_RELEASE(pFace);		

  }
				
m_pDev->SetDepthStencilSurface( pZBuffer );
m_pDev->SetRenderTarget( 0 , pBackBuffer );
					
SetupPerspective();
m_pDev->SetTransform(D3DTS_VIEW, &m_pCurrentScene->GetCamera()->GetViewMatrix());

CSTexture* shadowTexture=NULL;
CSTexture::Create("ShadowMap",m_pShadowMap,&shadowTexture);

 // Render again this time with a shadow map

SAFE_RELEASE( shadowTexture );

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by JoCCo
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...


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 this post


Link to post
Share on other sites
Quote:
Original post by GremlinX
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!


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 this post


Link to post
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!