I've noticed that when I raise the size of my shadow map above 512x512, the following artifact creeps in at the bottom:
I'm not sure why - it only appears when I raise the shadow map size! Is it a simple issue?
Jump to content
Posted 13 April 2013 - 09:53 AM
Can you show the same screen shot with a smaller resolution shadow map? Also, what is the artifact that you are describing - the shape of the shadow itself?
Jason Zink :: DirectX MVP
Direct3D 11 engine on CodePlex: Hieroglyph 3
Direct3D Books: Practical Rendering and Computation with Direct3D 11, Programming Vertex, Geometry, and Pixel Shaders
Articles: Dual-Paraboloid Mapping Article :: Parallax Occlusion Mapping Article (original):: Fast Silhouettes Article
Games: Lunar Rift
Posted 13 April 2013 - 10:03 AM
Hi, sorry if it wasn't visible.
The only thing casting a shadow should be the pyramid, but in the first pic there's a long rectangle added onto the shadow for some reason. Here's how it looks with a 512 shadow map:
There's no rectangle at the bottom. Also, in the first picture, the artefact is shadowing the object itself too, so for some reason it seems to think there's an object blocking the light there.
Posted 13 April 2013 - 12:02 PM
I thought it might have been, but this is what I get when I render the shadow map straight to the screen - they both look the same:
Is there a way to save the shadow texture itself to a file? I guess that would be a better diagnostic!
Posted 13 April 2013 - 12:42 PM
Ah, well I dumped my render surface to a png file and it came out with this at a size of 1024x1024. I guess that's the problem. I should also say that the cutoff starts at 768 pixels down - the size of my back buffer. So does that mean I can only use maps smaller than my back buffer?
Posted 13 April 2013 - 12:59 PM
Its been a while, but don't you need to set a z/depth-buffer thats at least the size of your current render target? Experienced some issues like this a while ago, I swear it was something with depth buffer, but I can't really tell anymore.
Posted 13 April 2013 - 01:07 PM
As said above, did you created separate depth/stencil buffer beside your RT on which you render shadow depth? And set it before render to shadow RT?
Did you set new viewport based on shadow map size/camera properties?
Edited by belfegor, 13 April 2013 - 01:08 PM.
Posted 14 April 2013 - 04:11 AM
Posted 14 April 2013 - 04:44 AM
When you create your device, and you specify this:
presentParams.EnableAutoDepthStencil = TRUE;
there is one depth/stencil (DS) buffer created for you behind the scene and its size is as backbuffer. Then when you set render target (RT) for shadow depth, DS size must be larger then your RT. If you had 1024x768 window with shadow 512x512 its ok, but with 1024x1024 you see its larger? Its best to create yet another DS buffer with size of your RT.
And then you render something like this:
// backup old buffers LPDIRECT3DSURFACE9 oldBackBuffer; LPDIRECT3DSURFACE9 oldDepthStencil; D3DVIEWPORT9 oldViewport; d3d9device->GetRenderTarget(0, &oldBackBuffer); d3d9device->GetDepthStencilSurface(&oldDepthStencil); d3d9device->GetViewport(&oldViewport); // set shadow buffers D3DVIEWPORT9 shadowViewport; shadowViewport.X = 0; shadowViewport.Y = 0; shadowViewport.Width = SHADOW_RT_WIDTH; shadowViewport.Height = SHADOW_RT_HEIGHT; shadowViewport.MinZ = 0; shadowViewport.MaxZ = 1; d3d9device->SetViewport(&shadowViewport); d3d9device->SetRenderTarget(0, shadowSurface); d3d9device->SetDepthStencilSurface(shadowDS); DrawFromShadowView(); // restore old buffers d3d9device->SetViewport(&oldViewport); d3d9device->SetRenderTarget(0, oldBackBuffer); d3d9device->SetDepthStencilSurface(oldDepthStencil); // you must call Release to avoid memry leaks as Get...Surface increment ref count oldBackBuffer->Release(); oldDepthStencil->Release(); DrawFromPlayerCamera();
Posted 14 April 2013 - 05:59 AM
OK, I tried that, and yes, setting the viewport and the new depth stencil surface did work! I can now do any-size shadow maps! Thanks a lot for your help.
I also decided to look at the sample shadow map program in the SDK and the same routines are done in there too, including backing up the old buffers on the fly.
I do have one small question though, regarding D3DXSaveSurfaceToFile. I tried using it to save my ShadowDepthStencilSurface to a screenshot, but it didn't save anyhting. It works fine for the shadow surface itself, but not for the depth surface. I guess there's a good reason! Also, when I render my shadow surface to the screen, I get the usual gradient of black to white denoting depth values. However, when I save the surface to a file, I get a strange looking blue outline without any depth gradient info - why is this? I ask more out of curiosity, because it seems to be the correct thing since the shadow map works!
Posted 14 April 2013 - 07:47 AM
The format of my SM texture is D3DFMT_R32F and then I use GetSurfaceLevel(0, &shadowMapSurface) to get the surface. I saved it as a PNG using D3DXSaveSurfaceToFile, and then just uploaded the PNG file as it was. I guess because it's not an RGB format that it only has a red channel.
Posted 14 April 2013 - 08:34 AM
Exactly. Also there is a 32 bits in RT red channel and on conversion to RGB png ( where is each channel 8 bits) some values are clamped (probably), and then you loose proper image representation so you can't rely on that output.
You could save as DDS witch supports that format, but then again it depends how would image editor/browser display 32 bits floating point image.
Edited by belfegor, 14 April 2013 - 08:44 AM.