I’ve been able to get most things working reasonably well in Unity3D, but this is one obstacle I’ve run up against that I haven’t been able to find an effective solution for yet. The issue? With a sun sitting right in the middle of my scene I need a point light in order to shine light evenly to all my planets. However, the point light’s shadows don’t work in the same way that a direction light’s shadows do – so I actually do need to use directional lights (as far as I’ve been able to tell so far.
Let’s look at some comparison screens – point light on the left, directional on the right:
The directional light looks way better right!? Even if I turn on shadows on the point light – the vast distance between the sun’s light and the planet means that the shadows won’t ever appear. At one point I had set things up so that each planet had it’s own point light at a very close proximity so that it could cast some shadows – but the way that point lights and directional lights cast shadows is very different and ultimately I needed the directional effect.
And then there’s the other issue with point lights – which is that the light won’t be occluded by an object, so you can see all my objects on the dark side of the planet are still receiving light right through the planet’s body – which is not at all what I want. So the directional light is working pretty well for me on planets except that…
If I now look at the other planets from this planet, you’ll notice the light source for those isn’t accurate at all for the directional light – my script always points the directional light at the player’s current planet.
My solution up until now has been to switch my light source between point and directional whenever I land or take off from a planet, and try to hide the switch behind some particle effects. One potential solution might be to have both lights on at all times and change the layers of the lights’ culling masks and the target objects – but that might complicate my existing layer system. I spent a long time cracking my head against the wall on this one but so far this is the best solution I’ve come up with so far. It’s super hacky but unfortunately it’s a problem unique to using this open solar system setup.
I’d love to hear alternative ideas from anyone who might have one.
**UPDATE – While playing with the lights some more I discovered that setting the Render Mode on the point light to ‘Important’ will make the shadows work properly on the dark side of the planet. If I set up a spot light for each planet (that I can turn on/off when appropriate) then I can get my directional shadows this way as well – as long as the spot light is also set to ‘Important’.