# Atmospheric Brightness

Atmospheric Brightness

Several principles combine to make this calculation one of the most complicated thus far.  As seen in the diagram below, three distances are available with the vertices provided at any given position, X, Y, and Z. It is known from vector math that if you take the two normalized directional vectors and cross-multiply them by each other, you get the cosine of the angle between them and can therefore determine the angle itself…

temp1 = 1 / sqrt(Zx² + Zy² + Zz²)

Zx = Zx · temp1                     Zy = Zy · temp1                     Zz = Zz · temp1

temp2 = 1 / sqrt(Yx² + Yy² + Yz²)

Yx = Yx · temp2                    Yy = Yy · temp2                    Yz = Yz · temp2

temp3 = sqrt(Zx · Yx + Zy · Yy + Zz · Yz)                          angle = cos-1 (temp3)

To determine the value for H, you multiply the sin of the angle by the length of the hypotenuse of the triangle we are determining the angle within (Z).

H = Z · sin (angle)

All that is left in determining a brightness factor is comparing this H value with the radius of the object in question.  We perform this by dividing H by the radius (2573km for PIII M2).  This will give us a value of 1 when the light source is exactly perpendicular to our perspective with respect to the object, and an increasing amount into infinity as the vessel travels away from the planet.  Since a factor from 0 to 1 for brightness would be more helpful, we simply subtract 1.  This value must be magnified so that the full effect of sunlight is available when H is 1km above the surface.  The value must then be clipped so that the upper and lower bounds are 0 and 1 respectively.

factor = H/2573/1000000L                factor = factor-1                    factor = factor * 2573

if (factor > 1) factor = 1 else if (factor < 0) factor = 0

Finally, this value is multiplied by the reference vessel’s altitude (distance to CG minus radius) over the altitude where visual effect of the atmosphere is negligible (48 kilometers for PIII M2) to simulate density decrease exponentially with higher altitudes.

factor = factor · sqrt(altitude) / sqrt(48)

A remarkable transformation of a single RGB combination of the VGA palette is performed as the vessel climbs from the surface of a planetoid on into space.  The stars must seamlessly blend into the brightness of the blue sky of day on the surface, and yet maintain their full luster at night from the ground or on into the vacuum of space.  The upper and lower ranges for each of the RGB colors from ground to sky are as follows…

On ground:    RU = 0            GU = 0            BU = atmopallettefactor / 64

RL = 0                        GL = 0            BL = atmopallettefactor / 64

In space:         RU = 1            GU = 1            BU = 1

RL = 0                        GL = 0            BL = 0

Since each of the window simulator screens has different properties due to variations in construction, brand, and settings of both the monitor and video card, up to 5 different atmopallettefactor’s exist.  We will choose one for the purpose of these computational examples…

atmopallettefactor example would be (45 – factor · 45)

We can see that neither RL or GL change during the transformation, so they are left at the constant of 0.  However, RU and GU linearly increase from 0 to 1 during the transformation, just the same as the factor previously discussed.  Therefore…

RU = factor    GU = factor

Since the difference between the two BU’s is ((64 / 64) – (atmopallettefactor / 64)), we simply multiply this difference by the factor as well.  An example of this value is shown below based on our (45 – factor · 45) atmopallettefactor example…

BU = (64 – 45) / 64 · factor + (45 / 64)

Likewise, the difference between the two BL’s is ((0 / 64) – (atmopallettefactor / 64)), and using the same example…

BL = (45 / 64) – ((45 / 64) · factor)

Another idea pending is to only update the factor from station_R if (factor · 63)’s integer result is different than before since there are only 64 shades available for each color.

To add the final touch, a starlight twinkle effect is added to the statstar routine which will only be evident when in the atmosphere and when the stars can be discerned from the blue sky.  This takes very little extra CPU time since A) the twinkle variable is global and doesn’t have to be passed to the statstar routine each time, B) the twinkle variable is of type int, and C) the color change is only applied to the few stars that pass all other display tests (only the ones that are possibly visible).  The twinkle variable is set to 32766 to indicate no twinkle effect when factor equals 1.2, a signal to the view program that the viewpoint is in clear space (not in atmosphere).  Any other time, the twinkle effect level is randomly set to a value between 1 and 99 since there is no altitude information available to the view system.

It should be noted that one of two previous attempts to create the atmospheric factor value resulted in a revelation about the inverse tangent function in trigonometry.  Take the number of radiuses you are away from a perfect sphere’s surface, subtract one, and then taking 90 minus the inverse tangent of that value gives you the angle that you can see around the planet.  For example, on the surface (1 radius) the result is 0°, at 2 radiuses, the result is 45°, and at 3 radiuses that value is ~26°.  This may be useful for something in the future, such as keeping from having to rotate the entire universe around the viewer rather than specifying a viewcone.