GameDev Diary – SpaceLife #7

It was all going so well.

I placed some pre-canned planets procedurally, as well as making planets farthest from the sun be gaseous. Then I decided to be a fool and turn on lighting. Producing some lovely results as you can see below:


Yay! That looks cool.

But then I discovered something quite awkward.

The sun is in a mini, scaled down solar system 30,000 units away. So that’s where the directional lighting is.

The ship and asteroids are NOT in the same place. So we’re actually getting the right shadows by luck rather than by judgement. If I warped behind the sun, we’d get the shadows on the wrong side because it’s all been faked. We will also find that shadows of planets will only fall on other planets and not on the ship or asteroids, because the light is coming from a different direction and length (we won’t get the correct cone of shadow).

I’m not 100% sure what to do about this. I need to prevent light bleed from both locations, yet represent the light in both locations.

If I create a fake light in my ‘local space’ and curtail the light effects of the mini solar system so they do not bleed into us, then we still won’t get shadows falling from planets.  That will manifest itself when we start to add space-stations. If a space-station is near a planet, and the sun is behind the planet, then the space station’s rear should be dark too. But because I’ll be faking a local light that’s not got a planet in the way – that won’t be the case.

So I either work out something clever, or I keep this simple-stupid.

Time to read up on lighting I think!


Using a point light in the scaled-down universe allows me to get an area-of-effect light but curtail it’s distance. That’s the solar system lit up nicely! You can see here that a planet further away is bright as day but the back side of the planet near us is dark.

2016-06-04 13_53_03-Start.png

However, if I were to add some asteroids or change the camera to see the cockpit, it won’t be lit up yet. Time to add another spotlight that lives in our near universe – mimicking the position of the sun.

This is achieved by a spotlight 5000m away in the +ve Z axis, pointing at us. Here’s a picture of how it all pans out.


Now the trick will be to keep the sun in the correct place; remember – the floating origin trick? Well, if we do nothing, and keep our local sun as a root game object, it will work. But you’ll see the intensity of the light get higher and higher until our player reaches the threshold for the floating origin ‘push back’. Suddenly the lighting conditions will appear to flip to a darker scene. So we have to keep the local sun at the same distance away from us, and if it’s starting position is different (maybe in future, we’ll warp to a planet the other side of the sun) it will keep in the same elevation/position relative to the mini universe specifications.

What have we lost? Shadows from planets. But in reality, they player probably won’t even notice.

After adding some ambient light, our scene looks nice, like the first images of ‘fake success’.

2016-06-04 14_34_30-Unity Personal (64bit) - SkyboxTestScene.unity - SpaceLife - WebGL_ _DX11_.png

2016-06-04 14_38_50-Start.png

Next I think I need to tidy up the current code, start thinking about how to warp near planets to get to their space stations – if they have them. One day I’ll get rid of the lame warp-up/down etc. That’s just to play around with.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s