Flight Gear Sky Representation and Rendering.

Curtis L. Olson
(curt@me.umn.edu)

1 Introduction

No flight simulator should be without a nice sky that smoothly transitions into haze at the horizon. Such a sky should also be able to render sunrise and sunset effects. This document describes how we have implemented such a sky.

2 Overview

The sky is represent as a 12 sided dome (or upside down bowl if you prefer.) Figure 1 shows how a 6 sided dome might be constructed.

   figure19
Figure 1: Simplified (6 Sided) Sky Dome

The center section can be constructed with a triangle fan. The inner and outer ``skirts'' can be constructed with triangle strips.

The colors of each vertex can be independently controlled to achieve sky to haze transitions, sunrise/sunset effects with a pinkish/oranges glow, and one side of the sky can easily be made brighter than the other. By enabling smooth shading in OpenGL, the colors will be blended together for a very nice effect.

3 Implementation

This sections describes how the sky has been implemented in OpenGL.

3.1 Vertex Generation

The sky dome structure is intended to be centered over the current view point at sea level. This way we could paste cloud textures on the dome if we liked. So, we simply have to generate vertices for a fixed dome, and then use OpenGL calls to transform and rotate it to the desired place. Please refer to the actual code (.../../../Src/Scenery/sky.c) for specifics, but to generate the vertices we simply create a 12 element array for the inner set of vertices, another 12 element array for the middle set of vertices and a last 12 element array for the outer set of vertices.

3.2 Vertex Coloring

For each vertex position array, there is a corresponding vertex color array. This way we don't have to compute each vertex color every iteration. Also, by being able to individually control the color at each vertex, we can do all sorts of nice sky to haze blending with dusk and dawn effects. Again, please refer to the source (.../../../Src/Scenery/sky.c) for specific details on how the coloring is implemented. However, here's the quick overview.

3.2.1 Day and Night Coloring

For the general middle of the day, or middle of the night sky, we already know the desired sky color, and the haze color. This is computed elsewhere based on the current sun position. During the night these colors are both nearly black. During the dawn they are smoothly transitioned to day time colors. And, during the dusk they are smoothly transitioned back to night time colors.

The center of the dome is assigned the current sky color. The color of the first inner ring of vertices is weighted 70% towards the sky color and 30% towards the fog color.

Then color of the middle ring of vertices is weighted 10% towards the sky color and 90% towards the fog color.

The the outer ring of vertices are assigned the current fog color.

3.2.2 Dusk and Dawn Effects

Dusk and dawn effects can be accomplished by controlling the color of the vertices. Rather than trying to figure out which vertices are near the current sun position, I just rotate the dome so the 0'th vertex of each ring (and the center fan) align with the sun. This makes it easier to calculate vertex colors. But, there is a fair amount of work involved in calculating the proper dome rotation.

   figure29
Figure 2: Overview of Earth

Figure 2 shows an overview of the setup. P, the current view position, and tex2html_wrap_inline186 , the local ``up'' vector, define the plane which is tangent to the Earth's surface at point P. Just for a quick review of your linear algebra, given tex2html_wrap_inline190 , the position vector of P and tex2html_wrap_inline194 , the position vector of some other arbitrary point on the plane, and tex2html_wrap_inline186 , the normal to the plane, then the vector tex2html_wrap_inline186 and the vector tex2html_wrap_inline200 are orthogonal (perpendicular.) If the two vectors are orthogonal then their dot product will be zero, so the following must be true:

equation42

This is the vector equation of the plane and can be rewritten as:

align47

We want to find a vector tex2html_wrap_inline194 representing the direction along the current tangent plane towards the position on the Earth where the Sun is directly overhead. The vector tex2html_wrap_inline204 is defined as tex2html_wrap_inline206 .

   figure54
Figure 3: Vectors and Points in Local Coordinate System

Figure 3 shows a more detailed ``local'' view of the points and vectors involved. The point, P, is the current view point. The vector, tex2html_wrap_inline186 , is the local up vector. S represents the current position on the Earth's surface where the Sun is directly overhead. We want to find the vector, tex2html_wrap_inline194 which is a projection of tex2html_wrap_inline204 onto the plane defined by P and tex2html_wrap_inline186 .

To do this we first calculate tex2html_wrap_inline222 which is the shortest distance from point S to the tangent plane.

equation65

Armed with tex2html_wrap_inline222 we can now calculate tex2html_wrap_inline194 which is the local surface direction on the tangent plane towards the sun, S.

equation74

Ok, so now we have tex2html_wrap_inline194 , but the fun doesn't stop here. Now we need to calculate a rotation angle tex2html_wrap_inline234 about tex2html_wrap_inline186 to align our dome with tex2html_wrap_inline194 . The origin of the dome always aligns with a vector pointing directly South. So, we need to repeat the above procedure to map a vector pointing straight down tex2html_wrap_inline240 onto our tangent plane to produce the local, surface, south vector tex2html_wrap_inline242 . We then take the tex2html_wrap_inline244 of the dot product of tex2html_wrap_inline194 with tex2html_wrap_inline242 .

equation87

Whew, that gives us the angle we want. Well almost, not quite. The problem is that the dot product returns a number in the range of tex2html_wrap_inline250 . Thus, the tex2html_wrap_inline244 function returns a tex2html_wrap_inline234 in the range of tex2html_wrap_inline256 . But this is not enough information to determine if tex2html_wrap_inline194 is in the east hemisphere or west hemisphere and if this angle should be positive or negative.

So, to get that last piece of information we need, we can rotate the vector tex2html_wrap_inline242 by 90 degrees about tex2html_wrap_inline186 . This gives us the local surface east vector on the tangent plane. Taking the dot product of tex2html_wrap_inline194 and the local east vector tells us which hemisphere tex2html_wrap_inline194 is in. And, from this, we can uniquely determine the proper angle for the sky dome rotation.

About this document ...

Flight Gear Sky Representation and Rendering.

This document was generated using the LaTeX2HTML translator Version 96.1 (Feb 5, 1996) Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.

The command line arguments were:
latex2html -split 0 -show_section_numbers Sky.tex.

The translation was initiated by Curtis L. Olson on Wed Feb 18 18:10:55 CST 1998


Curtis L. Olson
Wed Feb 18 18:10:55 CST 1998

Google Advertisements - Click to support FlightGear

Latest Version

v2.0.0 - 18 Feb 2010

A new major update of the FligtGear simulator. Please check the readme

Notam

Notam image file

Would all pilots try and avoid mpserver02 as its often overloaded.