Jump to content

How does the "Shadow Matrix" work?


IIerpos
 Share

Recommended Posts

I am having trouble with my shadows.

Everything that receives shadows but is not occluded is covered with what I think is elsewhere referred to as "shadow acne".

1 blender exported ESM shadows do not work at all. Why? Are they for a later version of Babylon?

2 I am not clear on how the shadows are being mapped. My first approach was to try to minimize field of illumination to increase the apparent resolution by pointing spot lights at my model and setting the camera clipping plane (which apparently is mapped in the blender exporter to the shadowMinZ/MaxZ) to conservative levels. I have had inconsistent results with this, so I really would like to understand clearly what it does. Is there in fact a Z axis resolution of the shadow map?

3 Of course I toyed with the shadow bias settings as well. However, when I set the map resolution to 512, by the time I get rid of the problems, the shadows begin well, well below the overhangs that create them. Much further than the apparent resolution of the shadow map would suggest is necessary. Then I decided to turn up the shadow map resolution to 4096, but then, even adding .00001 to the default bias setting offsets the shadow map by a huge amount, rendering the setting essentially useless. This makes no sense to me.

Also, what does the shadow map "resolution" mean for the directional lights, which have an infinite projection field? Is it somehow using the camera's FOV?

In my use case, I don't actually need the shadows to be dynamic, so I can set their resolution high and their refresh rate to 0.

Clearly I do not understand the shadows system, and am sorry to load so many questions at once. Any help is welcome! I can't give you the actual file I am working on due to non-disclosure issues, but I tried to recreate it with a simple model that has similar scale, thickness, light position, etc.

Thanks!

experiments.babylon

Link to comment
Share on other sites

Hello I improved the doc with the new options we added for Shadows on v3: http://doc.babylonjs.com/tutorials/shadows

1. They are in bjs 3.0

2. Shadow maps uses camera min and max Z if light.shadowMinZ and light.shadowMaxZ are not setup

3. You have several examples in the doc regarding bias and self shadowing

4. Directional uses orthographic projection:  https://github.com/BabylonJS/Babylon.js/blob/master/src/Lights/babylon.directionalLight.ts#L141. Spot lights and points lights use perspective projection: https://github.com/BabylonJS/Babylon.js/blob/master/src/Lights/babylon.spotLight.ts#L75

If you still have issues, the best option would be to try to reproduce it in the PG. I could help more then ;)

 

Note: If you really want to understand how shadows work, I recommend installing Spector.js (which is our webgl debugger). I can debug a frame for you and display the content of the shadow maps which helps A LOT to understand how shadows work: http://spector.babylonjs.com/

Link to comment
Share on other sites

Thanks!  I will look at Spector.js.

What I was wondering about the orthographically projected shadows was what defines their X and Y limits, where there is obviously a limited X and Y resolution. In the case of a spot light it is obviously the projection angle, but looking at the source filled me in on where the  "_orthoLeft", "orthoTop" etc. values come from.

For anyone reading this, it looks to me like the directional light adds finds the min and max boundaries of the meshes in the shadow render list, and then sets the width, height and offset for the shadow map according to that.

Also, The the Close Exponential Shadow map feature solved all my problems, just so you know!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...