GAME PROGRAMMING RESOURCES

VOLUMETRIC SHADOWS

Any 3d model made of just closed hulls can be used as a shadow caster by 3Impact engine. Shadow casters aren't directly rendered. Instead, the engine will render the shadow they cast onto visible meshes.

In a previous tutorial you have learned how to replace the ball in the interactive-ball game with a custom object. Let's change the ball shadow to your custom object's shadow now.

1. From the original texture-mapped model, make an additional model. It will be used by the engine as a shadow caster.


Make sure that the model:
  • is made of triangles only (triangulate).
  • has no texture.
  • is made of perfectly closed hulls.
  • does not include very big triangles. Triangle side length should never be greater than 10-20 meters, in order to ensure proper computation.


  • 2. Save the shadow model to 'mygame_res' folder as an .x file, named, for example, 'mymodel_shadow.x'.

    NOTE: make sure that DirectX® templates and material data are actually exported to the destination .x file.

    3. Open your compiler and, in the source code for the interactive-ball game, replace the

    "default_res\\ball_shadow.x"
    string in the iMeshBodyShadowCasterCreate() function call with

    "mygame_res\\mymodel_shadow.x"
    and then re-compile and run.

    REMARKS

  • Respect to normal meshes, shadow casters are slower to render.


  • There is no need for the shadow caster model to match all details of the visible mesh model.

    For example, you may want to model it as a subset of the visible mesh, in order to reduce the number of shadow-polygons to render.

    However, because the shadow is cast onto the corresponding visible mesh too (self-shadow-casting), exactly matching the geometries will ensure a consistent effect.


  • By default all meshes in the scene are affected by cast shadows. Still, if necessary, you can prevent a mesh surface to be darkened by shadows with the iMeshRenderModeSet() function.


  • A caster should be provided for all objects in the scene. Consider the following case:



    When a caster mesh is provided for both the ball and the wall (left), the visual effect is always proper. But when a caster isn't provided for the wall (right), chances are that the ball shadow is also cast on the dark side of a the wall. It also isn't properly cast onto the ground either.

    Still, in order to ensure smooth frame rates on slower machines, not to provide, whenever possible, a shadow caster for scenery features that are static is recommended.

    You should design your scenery models so that the number of static features casting shadows is minimal.

    You should provide a different shadow caster for each scenery feature so that you can disable them when far from the camera.

    You should even consider faking some static shadows by painting shadows in your scenery textures.


  • Surfaces, for shadow caster models, should never precisely match (overlap). Matching surfaces, like for example the sides of two cubes precisely put one upon the other, will cause rendering artifacts. You can usually work this problem around by separating or intersecting a little bit the two geometries.


  • Don't forget to seek for 'shadow' in the Reference document for more on volumetric shadows!