Click or drag to resize
DigitalRuneSky

This topic gives an overview of types which can be used to render the background of a 3D scene.

Sky in games is usually rendered using a static cube map texture and skybox. Static skyboxes are supported in DigitalRune Graphics. Additionally, you can create dynamic skies for day-night cycles including: stars, sun, moons and planets (including phase), sky (based on user-defined colors for maximal artistic control or using physically-based simulation for maximum realism).

Additionally, DigitalRune Graphics reduces the work necessary to configure a dynamic sky by providing the following values automatically for any time and any place on Earth: positions of the sun, moon and stars, star brightness, moon phase, direct and ambient light (intensity + color) caused by the sun and the moon, and fog colors.

Games do not have to use these real-world values, but it helps to have them as a reference.

This topic contains the following sections:

Video

The following video demonstrates features of the sky rendering system:

The sky in this example consists of a Milky Way cube map, the 9110 brightest stars, the moon, the sun, and sky colors created using atmospheric scattering. Positions of sky objects, direct light, indirect light and fog colors are computed automatically. Post-processing is used to add noise and a physically-based blue-shift during night.

Following video demonstrates the cloud rendering (see also Clouds):

Defining sky

The class SkyNode is a scene node and the base class for all sky classes.

DigitalRune.Graphics.SceneGraph (Sky)
Class Diagram: Sky

Several sky nodes can be added to scene. The property DrawOrder can be used to define the order in which the sky nodes are rendered. A complex sky can for example consist of (from back to front):

Tip Tip

In most applications, the sky changes only very slowly. If rendering several sky nodes in each frame is too expensive, the sky nodes can be rendered into a single cube map, and in each frame, only this cube map is rendered as the skybox. Meanwhile, an updated sky can be rendered into a second cube map. This background update can be distributed over several frames, and then the cube maps are swapped.

SkyboxNode

A SkyboxNode can be used to render the background with a single cube map texture.

Important note Important

Due to limitations on certain mobile platforms it is recommended to disable mipmaps of skybox textures:

  • Select the skybox texture in the content project.

  • Right-click the texture and select Properties to open the Properties window.

  • In the Properties window search for the property Content Processor and set Generate Mipmaps to False.

SkyObjectNode

The SkyObjectNode can be used to render a quad that shows a planet/moon texture and up to two "glows". The glow is rendered in the shader, it is similar to the specular highlight of a Phong shaded material. The sky object node can be used to render the sun disk: no texture, 1 glow with a high "glow exponent" to create the sun disk, 1 glow with a low "glow exponent" for a smooth highlight around the sun.

Sky-Sun

The moon can rendered with a moon texture and optional glow. The moon phase does not need to be baked into the texture. When the sun direction is set the phase is computed automatically in the shader.

Sky-Moon

StarfieldNode

The StarfieldNode renders a list of stars as anti-aliased points. Stars could be created using a random generator, but arbitrary star positions and brightness values look unnatural. It is preferable to import the actual positions and brightness values from a star catalog [1]. The Samples shows how to load the values of the 9110 brightest stars from a file.

ScatteringSkyNode

The ScatteringSkyNode defines a sky which colors are computed using atmospheric scattering. This sky node has a few properties that define the appearance of the sky. These values can be tweaked to get a clear sky, a hazy sky, or even the atmosphere of an alien planet. The ScatteringSkyNode can also estimate direct sunlight, indirect light and fog colors that match the configured sky.

GradientSkyNode and GradientTextureSkyNode

The GradientSkyNode provides a simple method to define a sky. It takes several user-defined colors and interpolates these colors across the sky.

The GradientTextureSkyNode is more complex and allows artists to create completely user-defined day-night cycles. This method is similar to the approach described by Stephen McAuley [2]. You need to create two input textures, which define the colors in the direction of the sun and opposite to the sun. For example:

Sky-Gradient-Front
Sky-Gradient-Back

The x axis represents the time of day (from midnight to midnight). Each column in the textures is a vertical color gradient for a specific time of day. The renderer chooses a column in each texture and uses these gradients for the sky. The first image defines the colors from horizon to zenith in the direction of the sun. The second image defines the colors from horizon to zenith opposite the sun. All other sky colors are interpolated from these two gradients.

The GradientSkyNode and the GradientTextureSkyNode both support the CIE Sky Model. This CIE standard defines brightness distributions (only intensities, no color) that match real world sky conditions. Applying these models helps to give the sky a realistic luminance distribution.

CloudLayerNode

The class CloudLayerNode can be used render clouds. See Clouds.

Rendering sky

This section explains how to render SkyNodes (skyboxes, sky objects, atmospheric scattering, clouds, etc.).

The SkyRenderer is a SceneNodeRenderer which handles SkyNodes. Per default, it can handle all built-in sky nodes (see Sky).

The sky is usually rendered after all opaque objects:

C#
// Render opaque objects...

// Render a SkyNodes.
skyRenderer.Render(skyNodes, context);

// Render alpha-blended objects...

If fog is rendered using the FogRenderer, the sky can be rendered before the fog. In this case the sky is fogged as well. This is suitable for dense fog near the camera which hides the sky. The sky can also be rendered after the fog, in which case the sky is not obscured by the fog. This can be used to create "aerial perspective", where object in the distance shift towards the fog color but the sky is fully visible.

Since the class is derived from SceneRenderer new custom SceneNodeRenderer can be added to its Renderers collection to handle new custom SkyNodes.

Subtopics
References