ShadowGenerator: SIZE, Position, AND multiple instances?

Hello,

The size of the BABYLON.ShadowGenerator shadowMapSIZE is 512.

Perfect shadows within that area.

PROBLEM:

There is a HALFPIPE that goes up into space…

… and the shadows become predictably blurry outside the 512 area (on the halfpipe):

I must’ve had some error in the FOLLOW LIGHT.

Thanks,
:eagle: : )

Update: needed to fix follow light some how. Result was great!

The shadow resolution will try to adapt to all objects it needs to capture by moving the light away so the light can see the entire scene.

If you have multiple objects that are going to be far from each other I would recommend to use two shadow maps

The other idea is to attach the light to the hero so it will only capture local shadows (Do not forget to update the shadowMap.renderList)

1 Like

Thank you for confirming DK!

A SMALL(24), SHADOW MAP / LIGHT that FOLLOWS HERO below.

Thanks,
:eagle:

UPDATE:

beautiful shadows on LAND and SPACE.

A SMALL (24) shadow map following HERO at 60FPS.

For anyone (like me) who reads everything… here was the solution:


/*********************************CREATE-SHADOW******************************/
nx.initFollowShadow = function(){
    if(!nx.lightShadow){ //one-time- LIGHT - FOR - SHADOWS-.
        nx.lightShadow = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(0, -1, -0.2), nx.scene);
        nx.lightShadow.position = new BABYLON.Vector3(0,0,0);
        nx.lightShadow.position.copyFrom( {x:0, y:24, z: 0})
        nx.lightShadow.diffuse = new BABYLON.Color3(0.2, 0.2, 1);
        nx.lightShadow.specular = new BABYLON.Color3(0, 0, 1);
        nx.lightShadow.intensity = 0.88;
    }
    var shadowMapSIZE = 24; //can be re-instanced by initShadows(); But not necessary.
    nx.shadowGenerator = new BABYLON.ShadowGenerator(shadowMapSIZE, nx.lightShadow);
    nx.shadowGenerator.useVarianceShadowMap = false; //default-.
    nx.shadowGenerator.usePoissonSampling = false; //better shadows but slower-.
    nx.shadowGenerator.useExponentialShadowMap = false; //true default, false is performance boost-.
    nx.shadowGenerator.useBlurExponentialShadowMap = true; //blur the shadow, better, slower-.
    nx.shadowGenerator.blurScale = 1;
    nx.shadowGenerator.blurBoxOffset = 4;
    nx.shadowGenerator.usePercentageCloserFiltering = false; //v3.2, webgl2 shadows-.
    nx.shadowGenerator.filteringQuality = BABYLON.ShadowGenerator.QUALITY_LOW;
    nx.shadowGenerator.useContactHardeningShadow = false;
    setTimeout(function(){ //delay shadows to TEST rendering optimization-.
      nx.shadowGenerator.getShadowMap().renderList.push(nx.HERO);
    },3000);
    nx.shadowDamper=0;
    if(nx.shadowDamper===0){ //one-time-.
        nx.scene.registerBeforeRender(function () {
            if(++nx.shadowDamper%10!=0){return} //DECIDAMPER-.
            if(nx && nx.HERO && nx.lightShadow){
                var lightPOS = new BABYLON.Vector3.Zero(); //follow light
                lightPOS.copyFrom(nx.HERO.position);
                lightPOS.y += 24;
                nx.lightShadow.position.copyFrom(lightPOS)
            }
        });
    }
}

1 Like

ERROR with SHADOWS, after adding 3 EXTRA LIGHTS.

Looking for answer.

FANTASTIC SHADOWS with 2 lights (point, directional):

then add 3 lights (point, point point): gets outline:
image

  • what happened?

  • and ways to make it go away? :grin:

  • can remove the 3 lights - but they are nice.

I’m in v3.2
Searching docs… Light - Babylon.js Documentation
(the shadow code is above) - new problem - in just this post - not the full thread.

What is causing that outline?

Thx!

Hi @Evgeni_Popov, thanks for your link in the other thread.

CSM is exciting. I bookmark to read all someday.

Do you happen to know why extra light would cause the result (directly) above?

Any work around or insights as to what that is?

I look through all docs and not find what that outline is. : )

Thanks much

Hard to say without a repro…

However, you may come to a resource limit somewhere: 3 light points is 6*3=18 RTT created and rendered.

Note also there was a bug in the point light shadow rendering before 4.1 which made the shadows look wrong.

1 Like

Yes, the outline does occur at 3 lights.

Goal is simple shadow, from one light. Other lights do not need to cast shadow.

Is there a way (in v3.2) to EXCLUDE the additional light from the shadow?

You can exclude some meshes from a light thanks to light.excludedMeshes, if that’s what you are asking?

1 Like

Thanks, slightly different… want to exclude light from shadow.

When 3 lights were added the shadow turns from really nice, to the fragment outline (above).

Any way to exclude the light from the shadow calculation, to stop that outline?

Not sure to understand…

For light / shadows, you basically have:

  • sg = new ShadowGenerator(light, ...) to make a light cast shadows
  • sg.renderList to add meshes as shadow casters for this shadow generator
  • mesh.receiveShadows = true to enable drawing a mesh with shadows (if the mesh is lit be a light that is attached to a shadow generator)
  • light.excludedMeshes array to prevent some meshes to be affected by a light
  • mesh.lightSources() to get all light sources affecting a mesh

Thanks. : )

When I add 1 Point Light it turns the nice shadow into that screenshot.

I understand all the aspects listed. And the ShadowGenerator code is included above.

But I do not see anything in docs on this.

What can I try to solve it?

INFO:

  • the extra light is NOT in the renderList, because it does not need to be a shadow caster.

  • the extra light is NOT in the excludedMeshes, because it needs to receive light just not cast a shadow. And NOT break the shadow.

So GOAL is 1 extra light that does not cast a shadow, or break the existing (simple) shadow.

Any thoughts on things I can try to solve this?

Should I make new Thread?

Thanks,

Shadows are cast on meshes. If you don’t want a light L1 to alter the shadows created on a mesh by light L2 (+L3+…) then you must exclude the mesh from being lit by L1, I can’t think of any other way to do it (except by writing custom shaders). There’s no (simple) way to have the shadowed parts of a mesh not being affected by a given light but still have the non shadowed parts being affected, if that’s what you are after.