Lighting for aircraft

Hi guys,

I am trying to figure out how to handling directional lighting for aircraft at altitude.

I have two directional lights, the sun and the moon.

The position of each is calculated from time, date, latitude, and longitude.

These get converted to directions and added into the lighting system.

My problem is that when they go below the horizon, they are still illuminating the objects.

So I need to handle the fact that the earth is blocking the light from these objects, but I need to account for the altitude of the aircraft as an aircraft at 30,000 feet will be illuminated for longer than one at 3,000 feet.

Anyone come across a solution for this?

I have absolutely no idea, so I’m just going to speculate a little and see if that helps :smiley:

I’m wondering if you could just calculate whether or not the light from your light sources would hit your object at the altitude they’re at (ie, with a ray cast) and use that to enable/disable the light sources for those objects? You wouldn’t really get a terminator line on your object, but the period of time at which that would happen is so small that you could probably get away with it.

This might be harder if you have multiple objects that need to be lit at altitude… but if you’re doing something like KSP where you only have your one aircraft, then you could probably get away with some trickery :smiley:

Anyway, that’s just an idea. Good luck!

No I have hundreds of aircraft in the air at any time

And it’s important as you can plan raids yourself, so accidentally getting your raid over an AAA battery when they are lit up like a christmas tree is probably a bad thing. :grin:

I initially planned to do it with a ray cast, but when the earth, sun, and moon are in galactic coordinates and your aircraft are rendered in world coordinates it becomes a mess.

Currently I am thinking of doing something with the 2D screen space position of the sun and moon, doing some kind of inverse transform to get them into worlds space, but I am not keen on that.

Maybe I can work out the tangent of the line between the sun and the earth at the horizon and use trig to work it out

Well I did something different, but it works

I calculate the distance to the horizon based on altitude.

Using this I calculate one of the intersection points between a circle at the aircraft location with a radius of the above distance and a circle at 0,0,0 with the same radius as the Earth.

I convert this into a direction and compare it with the sun light direction.

Complicated, but it woks

1 Like