bw logo

Chapter 5. Cloud shadows

All objects in the BigWorld client engine that are drawn outside are affected by cloud shadows. This effect is applied per-pixel, and is performed using a light map-stored as a texture feed in the engine that is projected onto the world.

This light map is exposed to the effects system via macros defined in the file bigworld/res/shaders/std_effects/stdinclude.fxh.

By default, the texture feed is named skyLightMap, and therefore is accessible to Python via the command:

BigWorld.getTextureFeed( "skyLightMap" )

Information for the sky light map is found in the sky XML file, which is defined in the file <res>/spaces/<space>/space.settings (for details on this file's grammar, see the document File Grammar Guide's section space.settings) for the given space. The parameters are the same as in any BigWorld light map.

5.1. Requirements

Cloud shadowing requires one extra texture layer per material. While the fixed-function pipeline supports this for most materials, cloud shadowing on bump-mapped and specular objects requires more than four sets of texture coordinates, meaning that for bump-mapped objects it will only work on Pixel Shader 2 and above.

5.2. Implementation

The sky light map is calculated by the code in C++ file src/lib/romp/sky_light_map.cpp, and is updated by the sky module during draw.

It is exposed to the effect engine via automatic effect constants. The light map is updated only when a new cloud is created, or the current set of clouds has moved more than 25% downwind.

Between updates, the projection texture coordinates are slid by the wind speed so that the cloud shadows appear to move with the clouds. All effect files incorporate the cloud shadowing effect, including the terrain and flora.

5.3. Effect File Implementation

There are two effect constants exposed to effect files to aid with sky light mapping:

  • SkyLightMapTransform

    Sets the "World to SkyLightMap" texture projection.Use this constant to convert x,z world vertex positions to u,v texture coordinates.

  • SkyLightMap

    Exposes the sky light map texture to effect files.

There are several macros in file bigworld/res/shaders/std_effects/stdinclude.fxh that assist with integrating cloud shadowing into your effect files.

These macros are described in the list below:

  • BW_SKY_LIGHT_MAP_OBJECT_SPACE, BW_SKY_LIGHT_MAP_WORLD_SPACE

    These macros declare the variables and constants required for the texture projection, including:

    • World space camera position.

    • Sky light map transform.

    • The sky light map itself.

    When using an effect file that performs lighting in object space (for example, if you are also using the macro DIFFUSE_LIGHTING_OBJECT_SPACE), use the variation BW_SKY_LIGHT_MAP_OBJECT_SPACE, and that will have the world matrix declared.

  • BW_SKY_LIGHT_MAP_SAMPLER

    This macro declares a sampler object that is used when implementing cloud shadows in a pixel shader.

  • BW_SKY_MAP_COORDS_OBJECT_SPACE, BW_SKY_MAP_COORDS_WORLD_SPACE

    These macros perform the texture projection on the given vertex position, and set the texture coordinates into the given register.

    Be sure to pass the positions in the appropriate reference frame, depending on which set of macros you are using.

  • BW_TEXTURESTAGE_CLOUDMAP

    This macro defines a texture stage that multiplies the previous stage's result by the appropriate cloud shadowing value.

    It should be used after any diffuse lighting calculation, and before any reflection or specular lighting.

  • SAMPLE_SKY_MAP

    This macro samples the sky light map in a pixel shader, and returns a 1D-float value representing the amount by which you should multiply your diffuse lighting value.

5.4. Tweaking

After the light map is calculated based on the current clouds, it is clamped to a maximum value. This means that the cloud map can never get too dark, or have too great an effect on the world.

For example, even if the sun is completely obscured by clouds during the day, there will still be enough ambient lighting and illumination from the cloud layer itself such that sunlight still takes effect.

The BigWorld watcher Client Settings/Clouds/max sky light map darkness sets the maximum value that the sky light map can have. A value of 1 means that the sky light map is able to completely obscure the sun (full shadowing). The default value of 0.65 represents the BigWorld artists' best guess at the optimal value for cloud shadowing. A value of 0 would mean there is never any effect of cloud shadows on the world.

This value is also read from the file sky.xml in the light map settings. It is represented by the maxDarkness tag. For details on the sky light map settings file, see Sky light map.