Scene lighting not applied on build

Hi! I am currently have an issue about the scene lighting. The problem is scene lighting seems to be not applied on build.
In my scene there is only one directional light and it is already set to Realtime. The lighting (including shadows) works great in editor, but not on build.
I have attached some screenshots in both editor and browser.

The first screenshot is from editor with scene lighting toggled on. This is what I expected what it should be on build.

The second screenshot is from editor with scene lighting toggled off, which looks the same as in browser (third screenshot) right now.

Any help would be appreciated!




Original Post on Discord

by user 66936191118737408

In Build means in the browser when you click play and open the exported website in e.g. chrome, right?

Can you try adding the AdditionalLightData component (the button in the footer of the Light component in Unity)? You should see a gizmo for your light then showing you the bounding box for the light. In three.js the light position for directional lights matters so my guess would be that perhaps the light is not positioned to cover your scene.

In Build means in the browser when you click play and open the exported website in e.g. chrome, right?
=> Yes, you are right

Oh sorry I forgot to mention that I’m using URP. Is the “Universal Additional Light Data” component same as the " Additional Light Data" you mean? The former one is already added when I encounter this problem. I can only find this component in my project.

Also I have attached a screenshot of the directional light in the scene. I am not sure if this is the bounding box you mean.


image.png
image.png

by user 66936191118737408

Ah sorry I meant this one:
image.png

It’s not the same :slightly_smiling_face: the LightShadowData just exposes more options specially for three/needle-engine and also draws the light bounding gizmos

Oh thx! The lighting applied after I added the LightShadowData. But the shadows in build seems not to be exactly the same as in the editor. The shadows in build seems to be much softer. Is it possible to make it looks harder? I have tried changing to hard shadows but did not work.



LightShadowData.png

by user 66936191118737408

The shadows appear softer because the area that the light covers is very large (width=500 and height=500) in comparison to the shadowmap resolution (2048) in your scene. To make it look harder you can either:

  1. Increase the shadow map resolution (bad for performance)
  2. Reduce the width and height of the light and instead move the light with the camera to always cover roughly the view that is visible on screen

You can also try using one of the libraries that exist for threejs to add better shadows or shadow cascades. Something like this for example: GitHub - StrandedKitty/three-csm: ☀️ Cascaded shadow maps (CSMs) implementation for Three.js

I see. I will try both solutions. Thx for the help! :grinning:

by user 66936191118737408