Directional light going through mesh when underneath?
I have a day-night cycle in my game where the Sun (directional light) rotates around a point. I'm running into an issue though where when the sun goes under the horizon, the light is coming through my terrain mesh and lighting up the bottom of my buildings and trees. I have tried putting other objects such as large cubes or reversed planes underneath my terrain to try to block the light but this did not work.
Here are some pictures. In this first image, you can see that the directional light is under the terrain pointed up at (0,0,0).
This is what it looks like from the game scene:
If I turn off the light you can see the bottom of the trees not lit up anymore.
I've tried turning off the light when it reaches an angle of 0 degrees to the horizon but this caused the lighting to look jumpy and I didn't like the results.
Does anyone have any suggestions on why this is happening?
it's funny how no one answers to this. same question here...
Answer by jrj2211 · Oct 18, 2017 at 07:34 AM
I fixed my problem by using an AnimationCurve to set the intensity of the light based on its rotation.
sun.GetComponent().intensity = sunIntensity.Evaluate(sun.transform.rotation.eulerAngles.x/180f);
I'd still like to know how to block directional lights with a mesh if anyone can provide the answer to that.
Your answer
![](https://koobas.hobune.stream/wayback/20220612141304im_/https://answers.unity.com/themes/thub/images/avi.jpg)