Shadows being cut with point light

hey guts, got another shadow problem
when using point light with a shadowGenerator, the bottom part of the shadow is not being cast. it looks like the bottom part of the cube map is not being set, or something like that
it looks like there is a invisible plane on the bottom like the image:

heres a demo with the code i have in my project:

it works perfectly in the demo, but in my project i have this issue
anyone got any idea of what may cause this? and how to solve this issue?

Usually this is caused by the shadow camera’s clipping plane, try to play with the min and maxZ properties: ShadowLight | Babylon.js Documentation

i set its shadowMin to 0, so it would not clip, its on the demo and its working with the same settings, but its not working on my project. i tried to increase/decrease both of them with no luck :confused:

Hmmm, weird. Can you share your project with us? Or maybe just a tiny sample of it, enough to reproduce the issue?

Did you check on the values you have in your demo compared to the PG?
Is your ground at zero? Your light further or closer to the mesh (torus in PG)?
Here is a rough repro of your ‘bug’. This is what I can get when I set a ‘wrong’ maxZ and minZ not accounting correctly the height of the mesh, position of the ground and/or light.

1 Like

incorrect. You would need to decrease one and increase the other depending on your light position. Also I would advise to use directional light to cast shadows since point light casts lights in all directions.

i can’t :confused:
i’m trying to reproduce in a demo, but with no luck so far

the values are exactly the same as the PG i sent
its the same code, just the scene creation that is being created somewhere else
trying to figure out whats happening
but its not the minZ and maxZ
tried a lot of different combinations, with no success

Try to move the light up/down with the Inspector and see what will happen.

Do you also have this torus with the same size? Isn’t it another mesh and size?
Did you try change it to a directional light and set a direction? Are you sure you don’t have any other code that could explain this? or another light source? another ground? Did you try with my version to see if you get the same result?

in my project i have enabled gizmos to move it aorund, it looks like there’s a ‘‘box’’ on the bottom of the light, that prevent the shadows being cast, but there is no other mesh in the scene, and no other object being sent to the shadow generator
if i put the light closer to the torus, so it would completely cover the ground with shadows, you can see that there is a empty square:

its exactly the code in the demo. no change in the meshes, positions or sizes
this only happens with spot light. i’m trying to find the code that is causing this, but its a complex project, and I have no idea of may cause this. i’m trying to remove everything from the project to see if i can find the answer, but so far no luck.
it doesn’t have any other light source. i tried with other lights in the scene too, but got the same results
with your version i got no shadow at all. thats because that ‘‘invisible block’’ ins completly on the way of the shadow:

i read in the docs that pont lights use a cube map to generate the shadows. it looks like the bottom image of the cube map is not being draw. i may be wrong about that, but i got no other explanation

Well, as I told you, a point light is not really the best to cast and master shadows. Using a directional light, you can cast shadows even from below the ground (so you would have no light from this light, just the shadow) and it should make it through your box you mentioned or whatever it is. With a directional light, it really is a matter of correctly setting the limits calculated from the light position and all through the size of the mesh you want to use as a shadow caster. To be honest, it’s hard for me to tell you more without a repro. But using a point light placed at origin zero, while the ground is at zero doesn’t sound like a good idea to me. In fact, I don’t even know why it seems to work in the PG!!!

Edit: Just opened your PG again and checked the nodes. Can you tell me what’s this name you have given to the light for (“”)? Depending on how you would use that in your script, this can certainly create issues.

Hey everybody,

Together with the topic-starter we figured out what is the matter.

With the help of Spector.js comparing what we have in our app and in the PG we found out that the shadow cubemap view matrix for -Y and +Y was wrong. That was because we overrode the Vector3.normalizeFromLength method to prevent some floating point errors. That caused the wrong values in these 2 view matrices.

Further investigation has show that in BJS there is a hack in the shadowGenerator.ts module to avoid lights perfectly perpendicual to the UP vector. I think that is not exactly correct and different UP vectors should be used for -Y, +Y cube shadow sides.

Thanks for sharing. No way we could have detected that from the above reading, I’m afraid.

Will transmit to the people taking care of this part with their hard and dedicated work :wink: @Evgeni_Popov but I feel that calling this a ‘hack’ straight out like that feels a bit ‘rough’ (personal opinion, if I can allow myself). I’m pretty sure there’s a reason for it. In any case, we sure do appreciate to receive such detailed and expert feedback so thanks for that already.

Else, I’m glad yours found the solution to your problem and I shall wish you Both a great day :smiley:

1 Like

Yeah. Sure. That was not possible.

Sorry if that sounds rude. No offense meant of course :slightly_smiling_face:. I consider realtime 3D graphics to be one big hack in general. We can call it a trick or whatever but it can be made safer I believe.
I’m speaking about this part specifically:

 if (Math.abs(Vector3.Dot(this._lightDirection, Vector3.Up())) === 1.0) {
    this._lightDirection.z = 0.0000000000001; // Required to avoid perfectly perpendicular light
Matrix.LookAtLHToRef(lightPosition, lightPosition.add(this._lightDirection), Vector3.Up(), this._viewMatrix);

I’d replace the UP vector here with (1,0,0) or whatever for the -Y / +Y directions

You can open a PR with the change! We always love contributions :smiley:

Yes, please do that and forgive me for saying your intervention was a bit ‘rude’. Point is with this messaging thing, you cannot see about how people ‘feel’. Also, I agree that 3D is ‘a hack’. Actually I often use this term even for when I see something in code that is simply not consistent with the structure.
If your solution is the one or even part of it or any good to consider, trust me when I say that it will be considered here and next implemented. And we shall thank you for your time and contribution :smiley: Meanwhile, have a great day :sun_with_face:


Ok. I’ll try to prepare a PR some time soon. This should be a small update if there are no hidden pitfals.