Self shadow - mesh is too dark (with PG example)

Hello there I am experiencing weird problem with mesh that casts and also recieves shadows.
It is “humanoid orc” mesh without any special shapes.

When it casts shadows, it somehow casts it onto itself even on the side that points to the source of light and it seems somehow buggy :-/ Some ideas how to solve it ?

Note: Source of light is above head of “my character”, I have tried lot of diferent shadow caster settings but none seems to be working.

I can achieve best results when I turn “recieve shadows” to false - then orcs are lit nicely and they still cast shadow onto the ground. They are just not shadowed by corners of walls but it is still relatively ok. I can live with that but it still seems to be weird.

  1. When shadow casting is on - shadow is nicely casted to the ground but mesh itself is almost not enlighted.

shadowOn

  1. When shadow casting is off, mesh is lit by “my character” as it is meant to be

Playground example https://playground.babylonjs.com/#MCNF1Y#1

What happens when you use full floats on the shadow generator?

This is done by setting the third constructor parameter to true on the generator.

Not sure if this would fix it, Id dig more but I broke my left hand today in a fall and have limited typing capabilities. :frowning:

hi. can you make playground with your environment and light setup and some ground and mesh?

It’s probably a problem with the bias (“shadow acne”): try to increase it, until wrong shadows disappear.

Hello, I believe that you mean “decrease bias” right ? Because the lower the number is, the lower bias is. I have tried to set the value to “0” and it remains the same :frowning: My shadow generator is set like this

this.shadow = new BABYLON.ShadowGenerator(1024, this.light);
this.shadow.bias = 0;
this.shadow.setDarkness(0.25);

Hello, here is that playground - if you comment mesh.receiveShadows = true; then it is looking ok.

https://playground.babylonjs.com/#MCNF1Y#1

Ohh my gosh, I need talk to text. There is too much to explain with one hand to explain what’s going on and some fixes. If nobody helps by tomorrow, ill see if I can.

I did meant to increase the bias value:

https://playground.babylonjs.com/#MCNF1Y#2

The acne is removed with the proper bias value.

You can also play with the normalBias property.

Have a look to the Troubleshooting section in this link for additional information about shadow generation.

Thanx for some insight ! Sadly it only helps in this simple playground scene. In real application when I set bias high enough to prevent self-shadowing, then it corrupts shadows from another objects and vice-versa. There seems to be no exact bias value that would work for all objects at all distances. I have tried another options from shadow troubleshooting section but none seems to help.

I would love to have possibility to just somehow prevent mesh from self-shadowing at all (but still being shadowed by another meshes). Curently the best option for me is not to recieve shadows at smaller objects.

I could theoretically create several shadowGeneratos with different biases and somehow move objects between them but I am afraid that it would have tremendous impact on performance and probably I would not be able to guess correct bias value at all.

You can try with a directional light and set autoCalcShadowZBounds = true to tighten the near/far planes and see if it helps.

https://playground.babylonjs.com/#MCNF1Y#3

But your plane is quite big compared to the mesh (decreasing its size will improve the shadows), so it’s hard to get a detailed shadow map in these conditions (you can also raise the shadow generator size).

New shadow technics are planned for 4.2, I think, which will help in this case.

Hey guys try my environment solution https://playground.babylonjs.com/#MCNF1Y#4
https://playground.babylonjs.com/#MCNF1Y#5

i think you need use ambient light + directiona llight + IBL with PBR material but i dont know about performance of this combination

In any case, stage lighting is never limited to a single light source, since in reality there is always reflected light called global lighting, and if we cannot calculate it directly, we need to simulate it using ambient lighting and environmental maps, for example. In reality, objects almost never happen without reflections, so something needs to be reflected from the material, and this is an environment map. otherwise you will get a picture with dark shadows and cognitive dissonance if you are trying to achieve some kind of photorealism.

and final solution https://playground.babylonjs.com/#MCNF1Y#7
self shadows, cast and recive shadows work fine with scene IBL and direct light.
if you try off scene IBL you get dark self shadows so use scene IBL and be happy)


on big scenes you can get acne.

just increase the bias e/g from 0.0001 to 0.001

and use inspector for play with shadows settings without reload scene

@Evgeni_Popov PR for CSM will soon address some of the large scenes issues.

I ll review it as soon as I am done with the forum :slight_smile:

1 Like

Hello I have tried really hard to find correct shadow settings but always something was wrong.

I need actually 3 things to be shadowCasters:

  1. My own character
  2. Monsters
  3. Cave walls

I couldnot find setting that works for all 3 so I tried to think a little bit outside of the box and I came up with possible solution, but I am afraid of performance issues.

What about split that 1 light into 3 lights ?

  1. Light will only enlight monsters and create their shadows
  2. Light will only enlight my own character and create my shadow
  3. Light will enlight everything (except monsters and my own character) and create shadow for cave walls.

What do you think about it ? I am afraid that 2 more lights will have tremendous performance impact, on the other hand they will all enlight different objects (not 2 lights will lit the same object) and also each light will cause shadows for one object - theoretically it will create the same set of enlighted and shadowed objects as one light - but still it will be 3.

What would you think about it ? As a side effect it will allow me to controll each light separately (different position and ranges) whis is also benefical. And I believe that this way I will be able to find correct shadow setting for each light.

try cascade shadow map Cascaded Shadow Maps (CSM) are now in! or documentation says for large scenes use closeBlurExponental type of shadows and in any way you need directional light