1
\$\begingroup\$

I'm using the TerrainTools unity package to create a simple 500x500 terrain, and placing a simple character that moves around, however, by default, the lightning is at real time mode, and the shadows over the terrain flicker like this:

https://youtu.be/_eFFDCRjObY

I know I can set the terrain as static and bake the lighting, however, doing that I lose my character shadow.

So my questions are, why this happens over real time lighting?, and, why I cannot see my shadow on a dynamic mesh over baked lightning?

Here you can see my lighting and directional light configs:

Lighting config: Lighting config

Directional light config: Directional light config

\$\endgroup\$
3
\$\begingroup\$

Flicking shadows on terrain can often be fixed by adjusting the "Bias" and "Normal bias" of the light source. However, adjusting those settings does have side effects, so you should pay attention to how the settings affect your shadows in different areas (especially on high-detail objects close to the camera). In the worst-case scenario, you might have to use tricks, like rendering nearby objects with one camera/directional light, and distant objects with a different camera/directional light, to get close and distant objects to both look right.

Other possible causes of flickering shadows:

  • The camera's near clipping plane is set too low (it should usually be at least 0.3 and may need to be set higher if the far clipping plane is very large).
  • The camera is very far away from the world center (more than 100,000 units if I remember correctly).

Baked lighting doesn't cast real-time shadows (e.g. character shadows) because it's baked. Baking your lighting essentially renders the shadows into a texture that is applied on top of the meshes. For traditional baked lighting, there's very little performance cost but it's completely static. However, you can combine real-time and baked lighting using mixed lighting.

Baked and real-time lighting are important concepts, so if you weren't already familiar with the differences between them, you should take some time to thoroughly read the Unity documentation on the different lighting modes.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for answering those questions, I'm going to check those settings you mentioned, and will study a lot more about lighting, thanks again \$\endgroup\$ – Ronald Petit Jan 20 at 4:15
  • \$\begingroup\$ near clipping of the camera did the trick, I read about lighting and I set my directional light to be mixed, I baked the terrain and now shadows look great (near clipping plane was 0.01 and I set it to 0.3, it was over a cinemachine camera) \$\endgroup\$ – Ronald Petit Jan 20 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.