Hi all,
I’m running into some strange issues with a CascadedShadowGenerator.
They look great most of the time:
but from certain camera angles, they appear to get spotty:
Unfortunately I can’t share a playground as this is a very large project I’m making that currently relies on a connection to a server to load in.
Here’s my code for setting up the shadow generator:
shadowLight = new BABYLON.DirectionalLight('light', new BABYLON.Vector3(-1, -2, -1), scene);
shadowLight.intensity = 0.5;
shadowLight.diffuse = BABYLON.Color3.FromHexString("#f7edc6");
shadowLight.specular = BABYLON.Color3.Black();
shadowLight.position = new BABYLON.Vector3(512, 32, 512);
shadowGenerator = new BABYLON.CascadedShadowGenerator(2048, shadowLight);
shadowGenerator.lambda = 0.8;
shadowGenerator.autoCalcDepthBounds = true;
shadowGenerator.stabilizeCascades = false;
shadowGenerator.depthClamp = true;
shadowGenerator.usePercentageCloserFiltering = true;
shadowGenerator.filteringQuality = BABYLON.ShadowGenerator.QUALITY_HIGH;
Wondering if anyone has any tips to help. Thank you!
It’s hard to tell without a repro somewhere… Try to tighten camera.minZ
/ camera.maxZ
as much as possible, meaning set camera.minZ
as high as possible and camera.maxZ
as low as possible.
You may also try to set lamdba
to 1 as you are using autoCalcDephBounds = true
.
1 Like
Thanks for the pointers @Evgeni_Popov!
With lambda
set to 1, the issue seems to remain and there is a very small range of angles that produce this effect:
And reducing camera.maxZ
to 32 doesn’t seem to mitigate the issue:
If it would help, I can provide a link to log in to the game (maybe to run a debugger? I’m more of a backend guy so I’m not totally sure if that’d help).
Yes, a live link would help I think.
I really appreciate it! Here’s a link:
http://game.blake.sh:8080/game/play.html
No username or password is required, you can just click Sign in. The camera can be moved with arrow keys or middle mouse click. I’ll leave this online, please let me know if you need any other information.
You should disable depth clamping as it seems it interacts negatively with the way you use CSM.
Indeed, you are only adding the character in the shadow caster list: if you plan to only have shadows for the character, you would better use a standard shadow generator and have the light follow the character. It will be a lot less taxing on performances.
See for eg Best shadow parameters for specific scene - #2 by Evgeni_Popov and Best shadow parameters for specific scene - #12 by Evgeni_Popov for a method to tighten the light frustum as much as possible for a given mesh.
1 Like
I would like to get to the point of having shadows for all objects and players (with the ability to scale to hundreds of players in one area), but read that there are only so many lights Babylon can support. Would it be best to stick with Cascaded shadows for this scenario? I may need to turn down some of the higher quality configurations for this.
Yes, in that case you should stick with the CSM generator. However, you may need to reduce the list of objects rendered in the shadow maps (cascades) and implement your own custom culling for that. See Cascaded Shadow Maps | Babylon.js Documentation