Skip to main content
gamedev.net
🔒 Locked

Basic Shadow Mapping problem

Started by Dunge Oct 3, 2008 at 1:16 AM 3 replies 1.2k views
Original Post
Dunge
Dunge
Hello everyone! Ok, basically I want to implement nice shadow mapping in my DX10 engine. I read a lot and checked multiple samples before starting to implement it myself. I started out with basic PCF filtering, and will later add support multiple lights, omnidirectional (cubemap) shadow for the point light. Then I planned to use Summed-Area Variance Shadow Maps but I don't have access to GPU Gems 3 DVD so I'll probably use normal VSM or ESM instead and forget about penumbra. My principal problem is that most examples I find on internet are for SM2.0 and DX9 and don't take advantage of DX10. I finally decided to base myself mostly on NVIDIA SDK VSM sample, which use DX10 and look nice. Anyway, my problem is not DX10 related at all and might be pretty stupid. I've been searching for many hours now and can't put my finger on the problem. I have a simple scene with one floor and two balls, with the light attached to the right of the controllable one and facing to the right. With only Phong shading it look like this: Free Image Hosting at www.ImageShack.us If I render my depth map texture instead of the diffuse one I can clearly see the camera view on the floor, and it is correct IMO : Free Image Hosting at www.ImageShack.us But unfortunately, if I project it into my camera view and use a PCF filter, it get an offset and don't render the shadow at the good place: Free Image Hosting at www.ImageShack.us I use similar PCF and projection code as the nvidia sample, but it is the same idea as everywhere else. I might get mixed up in the format, I don't have any rendertarget for the light pass (pass NULL to OMSetRenderTarget) and only use a depthstencil texture with no multisample for now. Here are the formats used, are theses ok?: D3D10_TEXTURE2D_DESC = DXGI_FORMAT_R32_TYPELESS D3D10_DEPTH_STENCIL_VIEW_DESC = DXGI_FORMAT_D32_FLOAT D3D10_SHADER_RESOURCE_VIEW_DESC = DXGI_FORMAT_R32_FLOAT I clear it to 1.0f. I also change the viewport size before render the shadow map to match the texture size (512*512 for now). The light viewProj matrix use a D3DX_PI * 0.5f fov and a 1.0f aspect ratio. My HLSL shader code can be viewed there: http://gamedev.pastebin.com/me9d0c17
Dunge
Dunge
Nevermind, I was updating my lights ViewProj matrices only when rendering the shadow map, and the last set matrix stayed active for the scene render. I'm still having problems for other things though so this thread may be useful is I have another question :).

Free Image Hosting at www.ImageShack.us
The floor is shaded in a very layered way, I hope this will go away when I change the filtering method.

[Edited by - Dunge on October 3, 2008 7:02:43 AM]
MJP
MJP
That "layered" look is due to biasing artifacts. Try adding a small amount (~0.0001) to the depth from the light's perspective either when you're writing the depth, or when you're doing the depth comparison. You may need to make the bias bigger depending on how many PCF samples you take. To be more accurate you can also make your bias dependent on the slope of the receiver.

As for VSM's...the Summed Area stuff is cool but still pretty expensive to generate the data. I'd definitely look into EVSM's though, they do a fantastic job of eliminating light bleeding. They look best when you store both positive and negative moments which means using a R32G32B32A32F texture, but you can get away with only storing the positive moments.
Dunge
Dunge
I now have a working VSM with 5x5 blur filter
Free Image Hosting at www.ImageShack.us

[Edited by - Dunge on October 3, 2008 12:19:03 PM]
Dunge
Dunge
Ok, a DX10 question now,

Basically I was trying to add support for multiple lights with shadow mapping. As I understand, I can make one pass per light or try to wrap this up in a single pass. I decided to try the single pass approach, and for this I need a Texture2DArray of all my shadow maps. I would like to use only one render target an depthstencil texture for all my lights (since each shadow map get rendered individually), but use an DIMENSION_TEXTURE2DARRAY flag for the render target texture and the resource view so I can use Texture2DArray inside HLSL to obtain a shadow map array that I coud use inside my normal scene render.

So what I want would be a way to change the index of the 2darray rendertarget texture used as the output for the rendertarget view. But not at all use MRT and render to multiple target at the same time. Hope this make sense. Or if someone have a much better idea, say it :).

[Edited by - Dunge on October 4, 2008 2:09:11 AM]

Topic Locked

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

Sign in to reply to this topic.