pioneerspacesim/pioneer — pull request #1390 by Ae-2222 (2012-07-23 12:49:18+00:00)
Title: Fade building illumination depending on time of day and atmosphere

This controls building illumination, splitting available light into directly and ambiently lit portions. Ambient lights are added which become active under dark conditions so buildings are visible at close ranges

**It should be noted that my models-in-atmosphere branch expands on this (tweaking fade conditions for non-shader path) and contains comments/cleanup etc. It's preferable to review that one (with EnableModelsInAtmosphereShader set to 0 in config.ini).**

This basically casts a shadow over cities by the bulk of the planet as the sun sets, and depending on the thickness of the atmosphere, introduces a ambient component.

From the code comments:

Calculates the ambiently and directly lit portions of the lighting model taking into account the atmosphere and sun positions at a given location
1. Calculates the amount of direct illumination available taking into account
* multiple suns
* sun positions relative to up direction i.e. light is dimmed as suns set
* Thickness of the atmosphere overhead i.e. as atmospheres get thicker light starts dimming earlier as sun sets, without atmosphere the light switches off at point of sunset

2 . Calculates the split between ambient and directly lit portions taking into account
* Atmosphere density (optical thickness) of the sky dome overhead
* as optical thickness increases the fraction of ambient light increases
* this takes altitude into account automatically
* As suns set the split is biased towards ambient

3 . If twilight or night fade in model at close ranges by increasing scene ambient lighting to a specified minIllumination value. Starports are visible from further afar than city buildings to aid landing.

4 . This branch exposes Graphics/Renderer interfaces concerning lights and should fix issue #1358 (planet rings shader uses only 1 light).

5 . How much effect the atmosphere has is determined by the atmospheric density at a point and the strength of the light from the stars in a similar manner to my adjust star fading branch.

***

Notes:
**(Relevant for modellers:)**
* Pioneer had a non-zero scene ambient value of rgba = (0.2, 0.2, 0.2, 1.0). This caused unilluminated areas to not be dark.
* Modellers Note: It would have caused some saturation when bright areas were fully lit and affected art.
* This ambient value is now explicitly specified.

* Buildings generally do not have real model lights, they use non-lit coloured billboards instead. This causes models to be dark apart from the billboards at night.
* Some solution needs to be found. e.g.:
* Models need lighting or,
* a baked light map could be used which does subtle radiosity illumination (I'm not sure if this would look bad with the simple game lighting), much like the current emission map.

Further discussion would probably be done in its own issue.

Not as relevant for modellers:
* Emission maps fade out of existence at long ranges. As discussed on IRC.
* This is due to lower lods being obtained by averaging used in creating GPU mipmaps.
* Custom filtering in c++ that preserves bright emmision values can be used.

* In reality bright light sources which are small are visible (lower than the screen resolution or indeed the eye resolution - like stars).
* Lit building/ships, once they are a few pixels big, could be replaced by a glow billboard at night.
* This billboard would lose brightness in an strength/r^2 fashion. The strength (and colour) would be a mixture of lua controlled lights active+general strength of emission map.
* This would allow city lights from large cities and satellites/starports/distant ships to be visible. Fighting/navigating would be easier and destruction of stations/ships would be visible from a distance.