4.5. Sky Bodies

The sky is rendered in a special way. The scene is rendered first, including lighting (but not post-processing effects like bloom), and then any areas that remain undrawn are filled with the sky. The sky has only emissive lighting, as it is too far away to be affected by lights in the scene. It also does not move, it is always centered at the camera.

The sky is composed of a number of layers, composed via alpha blending in HDR buffers. Conceptually, each layer is a Sky Body whose polygons either completely or partially surround the camera (which is at 0,0,0). Thus, the body does not have a position like the regular graphics body (§4.1), although it can be rotated.

Different layers allow the controlling of different effects, e.g. you can have a base stars layer, then a moon layer (which you rotate to control the position of the moon), followed by a sky layer (with some sort of atmospheric colour model), finally followed by clouds. Each of these layers can be enabled/disabled and oriented seprately.

Each sky body uses a mesh that is exported from a modeller in the usual way. It is typically a cube or sphere, or in the case of sun / moon etc, a small billboard. One can also imagine strips or other shapes being used in certain cases, like meteorite belts or jet trails. The polygons all point inwards, towards vec(0,0,0). The distance of the polygons from 0,0,0 can be arbitrary, since the depth buffer is not used to control the layering of sky bodies, rather they are layered explicitly. Typically we use about 1 metre because that is easy to manipulate in modelling software.

Sky body materials refer to sky materials instead of regular materials (§4.2). Sky materials are defined in a special way, and are not interchangeable with regular materials, although they can share textures. Here is an example:

sky_material `starfield` {
    emissiveMap = `starfield.dds`;

There is currently implemented a prototype for custom sky shaders, that interact with the sky materials. This is going to be changed in future to make it easier to use, so we shall not document it here. Take a look at /system/sky.lua if you are curious to see the current state. If you need advanced skies now, contact us via IRC or the forums for assistance.

The sky body itself is created as shown below:

sky_ent = gfx_sky_body_make(`MySkyMesh.mesh`, 255)
sky_ent.enabled = true/false -- disable drawing of this layer
sky_ent.zOrder = 100 -- change z order
sky_ent.orientation = quat(1,0,0,0)

The 255 is the z order, an integer between 0 and 255 inclusive. The value of 255 places it behind everything else. Use lower numbers to add more layers on top. If two sky bodies have the same z order, the ordering is undefined. So don't do that unless you know the polys will not overlap.