exc_html5 Posted July 16, 2016 Share Posted July 16, 2016 Hi Everyone! Can someone explain how BabylonJS calculates the resolution of the shadow map? I think I understand it but just want to be sure because I'm having difficulties getting sharp shadows in one of our projects. First off see the overall 3D area of the game/project, I pointed out the dark spots are baked shadows, so ignore those. Also, the area you see in the camera (where most of the objects are located) is circled. Also, the items marked #1 and #2 are two spheres i made that were moved out to the far edges of the area. - Next, you see what it looks like in the BJS camera if the spheres at the edges (1 and 2) are NOT casting shadows. The shadow generator (set to 4k shadow map size) looks nice and crisp. (These are realtime shadows, not baked) - However, the minute I turn enable casting shadows for those two sphere's at the edge of the map, the same exact shadow generator now produces this: - Obviously this looks less than desirable. So initial assumption is that the "resolution" of objects on the shadow map (which I'm assuming is one single dyanmic texture) is calculated by the bounding boxes of the objects casting shadows? Where the edge of the texture goes to the edge of bounding box on the furthest object from the directional lights field of view? Quote Link to comment Share on other sites More sharing options...
Dal Posted July 17, 2016 Share Posted July 17, 2016 Yep, this is a limitation in the shadows system at the moment... As I understand its just represented with one image. To fit in the new stuff you add, it has to sort of "zoom out" everything else to make space, and if those things are far away, it has to zoom out even further, resulting in everything getting more pixelated. @Deltakosh has a solution planned for this which is to implement CSM shadows (which hopefully is coming for the 2.5 release) which will allow Babylon to give more detail to the nearby shadows and less detail to the ones far away. You can work around this limit a bit for now though by: a) Increase the shadowmap size to the absolute maximum you can get away with b) Write a little script which simply adds things to the shadow map when the player gets within 50m or so, and removes them again when they're outside that radius (far away things won't be shadowed, but I think it's a better solution than having ugly shadows). Combine that with baked shadows and distance fog and you can get away with it. Boz 1 Quote Link to comment Share on other sites More sharing options...
exc_html5 Posted July 17, 2016 Author Share Posted July 17, 2016 Regarding item B, thanks for the tip! Never occurred to me that you could remove add stuff on the fly to the list of things being shadowed. But makes total sense. I'll give that a whirl. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 18, 2016 Share Posted July 18, 2016 Hey! @Dal is correct. If you are using a directional light, babylon.js try to compute the perfect point of view to embrace all objects in your shadow map (https://github.com/BabylonJS/Babylon.js/blob/master/src/Lights/babylon.directionalLight.ts#L45) You can turn this behavior off by using light.autoUpdateExtends = false But you can also consider having various directional lights: one for the closed range objects and one for the far objects. Quote Link to comment Share on other sites More sharing options...
exc_html5 Posted July 18, 2016 Author Share Posted July 18, 2016 @@deltakosh if I turn the behavior off using that switch, how to I tell it how big to make shadow map scale? (or how do I manually make the shadow map?) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 18, 2016 Share Posted July 18, 2016 You can scale it with light.shadowOrthoScale Quote Link to comment Share on other sites More sharing options...
exc_html5 Posted July 18, 2016 Author Share Posted July 18, 2016 Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.