Advertisement

Shadow map problem?

Started by May 05, 2018 08:07 AM
5 comments, last by deathwingA 6 years, 6 months ago

I was just implementing a simple shadow map for the first time and I make the shadow map follow wherever my camera position is so I can have better resolution shadow but then this happens...

In the pic,the shadow of the house only shown half(because the other half not inside the shadow map), when  I move forward,the shadow is also revealed......I don't know what phenomenon this is called so I have got no result in googling it. Anyone has a fix for this? 

Edit;Forgot to say this is made with DirectX9

test.JPG

Help i'm to depended on school library

take a look on cascaded shadow maps.

There is demo in dxdsk june 2016

https://msdn.microsoft.com/en-us/library/windows/desktop/ee416307(v=vs.85).aspx

Advertisement
31 minutes ago, deathwingA said:

Anyone has a fix for this? 

Baked shadows. Learn how to bake shadows in Unity.

This way the same thing still happens but when you are near it shows your shadow and when far it shows the baked shadow.: https://docs.unity3d.com/Manual/LightMode-Mixed.html and https://docs.unity3d.com/Manual/LightMode-Baked.html

Funny, the new explanation is worse than the Unity 4 explanation but I can't find a old manual.

 

4 hours ago, joeblack said:

take a look on cascaded shadow maps.

There is demo in dxdsk june 2016

https://msdn.microsoft.com/en-us/library/windows/desktop/ee416307(v=vs.85).aspx

thanks,this looks like the thing I need from what I've read,is it viable in DirectX9?

 

4 hours ago, Scouting Ninja said:

Baked shadows. Learn how to bake shadows in Unity.

This way the same thing still happens but when you are near it shows your shadow and when far it shows the baked shadow.: https://docs.unity3d.com/Manual/LightMode-Mixed.html and https://docs.unity3d.com/Manual/LightMode-Baked.html

Funny, the new explanation is worse than the Unity 4 explanation but I can't find a old manual.

 

Sorry I forgot to mention I'm not doing it in Unity,but with my own engine(not a very good one btw)

Help i'm to depended on school library

Nice this brings back some memories when I was trying the same thing some years ago. As joeblack already mentioned, the most common way is to solve it with cascaded shadow maps. This is perfectly doable in DirectX 9 or any graphics API that can do shadow maps. The only thing you must do here, is instead of rendering one shadow map, you will render multiple ones (for example 3). All 3 shadow maps can have the same resolution, but each shadow projection matrix will be placed farther away from the camera and set up to cover a bigger range. When implementing this, as with any technique it can be overwhelming at the first time. So I suggest break down the implementation in steps:

  1. Just create two shadow maps and test that both are rendered to
  2. You must sample from both in the shaders, but you can visualize which shadow map you will be sampling from by outputting red/green/etc.. colors from shaders instead of sampling shadow maps. This is useful to find bugs early on.
  3. Create the second shadow matrix with just bigger size, but place it to just follow the camera
  4. If it's working, you can already use it to have a great range covered by shadows, but the next step of improvement is placing the bigger shadow matrix not to the camera center, but somewhere farther away on the camera look direction vector. Also, you can calculate the size of the shadow matrix to cover the camera frustum, but not more, which will increase the effective resolution/world space unit.
  5. Make the whole thing so that you can adjust the number of shadow map cascades, adjust split distance...

Good luck with your engine, is it open source by the way? :)

3 hours ago, turanszkij said:

Nice this brings back some memories when I was trying the same thing some years ago. As joeblack already mentioned, the most common way is to solve it with cascaded shadow maps. This is perfectly doable in DirectX 9 or any graphics API that can do shadow maps. The only thing you must do here, is instead of rendering one shadow map, you will render multiple ones (for example 3). All 3 shadow maps can have the same resolution, but each shadow projection matrix will be placed farther away from the camera and set up to cover a bigger range. When implementing this, as with any technique it can be overwhelming at the first time. So I suggest break down the implementation in steps:

  1. Just create two shadow maps and test that both are rendered to
  2. You must sample from both in the shaders, but you can visualize which shadow map you will be sampling from by outputting red/green/etc.. colors from shaders instead of sampling shadow maps. This is useful to find bugs early on.
  3. Create the second shadow matrix with just bigger size, but place it to just follow the camera
  4. If it's working, you can already use it to have a great range covered by shadows, but the next step of improvement is placing the bigger shadow matrix not to the camera center, but somewhere farther away on the camera look direction vector. Also, you can calculate the size of the shadow matrix to cover the camera frustum, but not more, which will increase the effective resolution/world space unit.
  5. Make the whole thing so that you can adjust the number of shadow map cascades, adjust split distance...

Good luck with your engine, is it open source by the way? :)

Thanks for the great explanation ! I'm still beginner in shader(started these few weeks) but I'll give it a shot anyway. And the engine isn't open source,at least not yet .

Help i'm to depended on school library

This topic is closed to new replies.

Advertisement