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;
2 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.

1 Like

I had the idea of a shadow light which would be the inverse of a volumetric light source, rather than a light effect it would shoot a beam of darkness onto objects but instead of stopping at the first face it would penetrate and darken each object face, then the main light would override the first face with light, thus making per light based shadows a thing, not sure if anyone could make that happen or not, in theory it could work and would solve things like maxZ of camera being restricted to 50k before shadows distort. Nothing should be dependant on Camera MaxZ in my opinion and so far that has been the only thing I have discovered that has been effected by maxZ being over 50k from my tests, I have found no other ill effects from having maxZ set to above 1 million, just shadow generator seems to be the only thing currently limited.