XNA Creators Club Online
Page 1 of 1 (10 items)
Sort Posts: Previous Next

Shadow mapping question

Last post 8/28/2009 12:50 PM by brainziziz. 9 replies.
  • 8/27/2009 8:19 AM

    Shadow mapping question

    I'm trying to implement shadow mapping on top of the well known Catalin Zima deffered rendering article. When you get to the point where you rendered the shadow map, and are now trying to check whether the distance from the pixel you're looking at is lower than the distance written in the shadow map, what is the formula for getting the correct texture coordinates in the shadow map.

    In one sample this is used:

    output.Shadowcoord.x = lightPosition.x / lightPosition.z / 2 + 0.5f; 
    output.Shadowcoord.y = -lightPosition.y / lightPosition.z / 2 + 0.5f; 


    The shadow mapping sample uses this:

    float2 ShadowTexCoord = 0.5 * lightingPosition.xy / lightingPosition.w + float2( 0.5, 0.5 ); 
    ShadowTexCoord.y = 1.0f - ShadowTexCoord.y; 

    And a render monkey sample uses this:

       float4 sPos = mul(proj_matrix, pos); 
       sPos.z += 10; 
       Out.shadowCrd.x = 0.5 * (sPos.z + sPos.x); 
       Out.shadowCrd.y = 0.5 * (sPos.z - sPos.y); 
       Out.shadowCrd.z = 0; 
       Out.shadowCrd.w = sPos.z; 

    The shadow mapping sample and the first sample use an orthographic camera as the light camera, while the render monkey uses a normal fov camera (i think).
    How does the type of camera projection affect these shadow coordinates, and what's the math behind this?
    Visit my dev blog - dev in the making
  • 8/27/2009 9:06 AM In reply to

    Re: Shadow mapping question

    Answer
    Reply Quote
    So, it really comes down to projective texture mapping. You can read a pretty good article on it here.
  • 8/27/2009 10:02 AM In reply to

    Re: Shadow mapping question

    In my implementaion I've based on implementation of deferred shadows, that use an ortho camera. I don't know the really math behind this, but for reference you can take a look at a sample i've made, check it on my signature link. The sample technique, is the most simplest way I've found, I've made some improvements to final version that i've used in my game. But both have some problems, but for now I won't take it again. Sorry about english
    Like games? Like Programming? 3D Gaming and Programming
    Twitter: vando_pereira
  • 8/27/2009 12:16 PM In reply to

    Re: Shadow mapping question

    Yeah, thanks I already looked at your sample. I found it a bit confusing, especially the shader code and the calculate frustum code, but I experimented a bit with it. I think I'll switch my code to use an ortho camera also, I think I'm getting bad results due to shadow map inaccuracies. By my calculations the shadow map I got from the light fov camera is using about 1 / 5 of the whole range.
    Visit my dev blog - dev in the making
  • 8/27/2009 1:10 PM In reply to

    Re: Shadow mapping question

    I'm currently doing this:

    RenderShadowMap();
    DrawSceneUsingDefferedRendering()
    DrawLights();
    CombineMaps();

    The draw scene renders color, normals, and the occlusion into g-buffers, and the the CombineMaps() combines them all.
    Is that ok?
    Visit my dev blog - dev in the making
  • 8/27/2009 4:11 PM In reply to

    Re: Shadow mapping question

    Does anyone have a clue what could be causing this:

    http://a.imagehost.org/0364/Abandoned_2009-08-27_17-58-56-62.jpg
    http://a.imagehost.org/0573/Abandoned_2009-08-27_17-59-00-78.jpg

    When I move a little closer or farther it's normal:

    http://a.imagehost.org/0179/Abandoned_2009-08-27_17-59-06-89.jpg

    Also this:

    http://a.imagehost.org/0373/Abandoned_2009-08-27_17-59-52-17.jpg

    The spikes are not in the terrain!
    I can post my code if it would help.

    Visit my dev blog - dev in the making
  • 8/27/2009 11:23 PM In reply to

    Re: Shadow mapping question

    Answer
    Reply Quote
    That banding *might* be caused by 2 things:

    1. the shadow depth map doesn't have enough accuracy (try using SurfaceFormat.Single, or look into splitting a float value into a 4 value color buffer)

    2. the area that is being rendered by the shadow map is not being covered by the shadow map, which can lead to weird lines, spikes and other strange graphical glitches.

    Those are my guesses from lots of messing around with shadows. Hope this helps somehow.

    zander.
    Graphics Programmer,Sandswept Studios.http://www.sandswept.net
  • 8/28/2009 6:32 AM In reply to

    Re: Shadow mapping question

    I'll try splitting my floats, thanks for the idea!
    Visit my dev blog - dev in the making
  • 8/28/2009 12:44 PM In reply to

    Re: Shadow mapping question

    Answer
    Reply Quote
    Sometimes i experienced the same problem that you in first two photos. Try to render a view from shadow caster view, probably it will help you to see if it is some problem with projection. A fast look to Render Targets in PIX may can help you too.
    Like games? Like Programming? 3D Gaming and Programming
    Twitter: vando_pereira
  • 8/28/2009 12:50 PM In reply to

    Re: Shadow mapping question

    I solved my problem with a couple of things:
    - Maximizing depth precision by placing the view camera as close as possible to the terrain and adjusting its far clip (I couldn't make it work with on ortho camera. The minimal frustum algorithm I found didn't suit my kind of terrain.)
    - Making the terrain "full", the first terrain was made from a plane and that caused inaccuracies when the sun lit the terrain from below.

    What I'm planing to do now is try to implement variance shadow map following this article: http://www.ziggyware.com/readarticle.php?article_id=161


    Visit my dev blog - dev in the making
Page 1 of 1 (10 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG