Shadow darkness below zero

Hello Forum,

In my current project, I am using a hemispheric Light to light the whole scene from “all” directions and also a directional Light to generate shadows. The two light sources both have an intensity of 1, so the scene does not get too bright. If I now generate shadows, they are not visible on the surfaces that are hit by both the hemispheric and the directional Light. I only managed to make the shadows visible by setting the shadow darkness to a negative value (example in my playground). In another forum post, I saw that it is not recommended to set the darkness in such a way. Is it possible to achieve the same results in another way?

Also: I tried using an exponential shadow map, but it always results in no shadows being visible at all.

No, if there is too much light, it’s expected the shadows are less/not visible. Setting the intensity to a negative is a trick, but if it does the job then I think it’s fine!

You have to tweak the shadowMaxZ / depthScale properties:

But that won’t change anything, you still won’t see the shadows.

2 Likes

OK, I think most is said. Light only adds to light and light (or env in case of PBR) takes from the shadows.
With that said, I eventually work some parts of my scene using 2 lights (one casting the shadows and one setting the overall light in the scene). Using this approach, excluding or including lights can help. Of course, this also means you will need to ‘balance’ your different lights (and eventually work the materials towards direct light intensity).

Beyond, that (as said above) playing with the depth/maxZ can also help (up to a certain point). casting a light much further then where it hits the mesh, will make for a darker (and ‘sharper’ shadow).

Finally, as per

there’s this really awesome thing about the ‘versatility’ of the BJS engine.
OK, you gave it a first try here by trying to set the value of -0.5 darkness (sadly not successful on this one :wink: because of the overall logic). BUT keep this openess in mind… You can often set values way beyond 1) what you can set in the Inspector 2) …and even beyond what you would consider as ‘normal’. And truly, in some cases, it might just give you the edge you needed :grin:

Edit: here’s an example for the above minus value set on the hemi to ‘compensate’ with the directional light. The minus value on the hemi removes from the overall (total) light on meshes lit, while the shadows remain dark.

2 Likes

Thank you @Evgeni_Popov and @mawa for your input! I managed to end up with somewhat acceptable shadows. Sadly, I am still suffering from a bug/feature that I can’t get rid of. In this PG I am trying out different methods for generating shadows, and I always end up with the same Problem:

image
The shadows don’t start at the actual edges of the casting objects, but have a slight offset instead.
image
(result of the default shadow settings)

I played around with the ShadowMaxZ value in Line 66 and the different methods of shadow generation in Lines 86-94 but could not fix the problem.

I get the best results when using the BlurExponentialShadowMap and a ShadowMaxZ value of 7, but this causes strange shadow behavior in other places of the scene:

image
This looks about right, but…


it creates unwanted shadows in the top right section of the screenshot. There should not be shadows above the ventilation system like that… In addition actually wanted shadows on the left side of the screenshot are still missing. I feel like increasing the MaxShadowZ Value even more would fix the problem on the left but also increase the unwanted shadows on the top right.

Can you follow the explanation of my problem and thought process? :worried:

Honestly, I didn’t read it all. Setting shadows the exact way you want can indeed be tricky and time-consuming. But I think you’re on the right track. :+1: May be you want some of your objects to actually not cast shadows.
Apart from this, when I want to cast shadows from objects to objects (some being rather small or close to each other), I suppose I favor the contact hardening shadow (but that might be just personal).

I’m afraid I don’t really have the time to dig into each and every detail of your scene shadowing (sorry :zipper_mouth_face: :pray:)…but may be someone else will have? (unless you figure it yourself eventually… as I said, it can take some time and a number of attempts).

I perfectly understand that. I just asked in case this was an obvious problem for somebody. :slight_smile:

1 Like

For

I can at least reply to this one. that’s because your light source is too close to the wall. You should push your dirlight higher up (from the scene and walls).

But then, this also means that you have to rework the direction and min and maxZ (from the new position - not done in this PG, sorry). GL and it looks to me like you have the skills to make it :man_superhero: Just a little bit more patience and a stubborn mind like mine should do the trick :grin: :hugs:

1 Like

The “Display frustum” debug button is your best friend when you try to setup shadows for a directional light (click on the light in the inspector, you will find the button at the very end of the property list):

We can see that shadowMaxZ=7 is not enough. 12 is ok:

Using PCF (with bias=0.01):

Also, this doc page can help you debug your shadow problems:

2 Likes