Shadow howto: Multiple objects all over the scene

Hi all!

I’d like to cast shadows on ground (heightmap) of multiple (>10) meshes located all over the scene.

How to?

Hope for help,

. J

I think this should help:

After reading and playing a bit my concern is as follows:

  1. in order to get a detailed shadow for a mesh only one must be added to the ShadowGenerator
  2. for mesh-objects have big distances from each other, the size of the shadowmap would have to be gigantic trying to use a single ShadowGenerator
  3. the DirectionalLight.position has to be moved with the mesh-object to make sure the lights shadow frustrum remains as small as possible
  4. each DirectionalLight can only be used with a single ShadowGenerator

This means I have to have one ShadowGenerator per mesh-object -> one DirectionalLight per mesh-object.
AFAIK the number of lights is strictly limited and way less than the number of objects.

Is there a way out?
Can’t there be kind of a DummyDirectionalLight just used for the shadow casting and not being counted as a light in the scene, not lighting anything?

Still hoping for help,

. J

have a plot of 3000 * 3000 and cascading shadows. My light is quite high and all the objects, characters have shadows all over the ground and a quality shadow.
The cascading shadows are a marvel.

https://doc.babylonjs.com/babylon101/shadows_csm

Here are my current settings :

var light = new BABYLON.DirectionalLight("DirectionalLight", new BABYLON.Vector3(-5, -5, 5), scene);
light.position = new BABYLON.Vector3(1000, 1500, 0);
light.diffuse = BABYLON.Color3.White();
light.specular = new BABYLON.Color3(0.3, 0.3, 0.3);
light.intensity = 1.0;

var csmShadowGenerator = new BABYLON.CascadedShadowGenerator(2048, light);
csmShadowGenerator.stabilizeCascades = true;
csmShadowGenerator.forceBackFacesOnly = true;
csmShadowGenerator.shadowMaxZ = 100;
csmShadowGenerator.autoCalcDepthBounds = true;
csmShadowGenerator.lambda = 0.5;
csmShadowGenerator.depthClamp = true;
csmShadowGenerator.penumbraDarkness = 0.8;
csmShadowGenerator.usePercentageCloserFiltering = true;
csmShadowGenerator.filteringQuality = BABYLON.ShadowGenerator.QUALITY_HIGH;
3 Likes

Thank you @Dad72. I have no idea how it works … but it does. Pretty impressive!

And it does’nt even harm the performance budget too hard.

2 Likes