shadow_stencil
Determines the type of dynamic shadows cast by models.
Range:
0 - Z-buffer shadows (default).
1 - Z-pass stencil shadows.
2 - Z-fail stencil shadows A7 .
Type:
var
Remarks:
Stencil buffer shadows look better than z-buffer shadows: they 'bend'
around corners, and objects can cast shadows on themselves. Due to the hard
shadow edges, especially with self shadows, they work best with high
polygon models and rather dark levels with hard light contrasts. Stencil buffer
shadows have the following restrictions:
- Stencil shadows are slower than z buffer shadows, and only run
on 3D hardware with 8 bit stencil buffer support. All 3D cards manufactured
after 2000 fulfil this requirement.
- Stencil shadows can only be cast by nontransparent, non-invisible models
consisting of closed meshes with no holes. No polygons must
intersect each other or touch each other with their flat side. Otherwise
rendering errors (dark lines projecting from the model to the shadow) can
be visible. In a closed mesh, every edge is shared by exactly two triangles.
If the model's mesh is not closed, create a closed mesh LOD model for shadow
casting. The MED mesh
tester can
be used for determining whether a mesh is closed or not.
- Stencil shadows can be cast from the sun or from dynamic lights. For this
the light emitting entity must have the CAST flag set. A stencil shadow
is cast by the strongest dynamic light that reaches the origin of the entity.
If the entity origin is not within the range of any light, the shadow is
cast by the sun.
Shadow casting lights must not be inside a shadow throwing object.
- Dynamic shadows are not clipped by walls. A shadow can be cast on a wall,
at the back side of the wall, and on the floor behind the wall at the same
time. Take care that level and models are dark in unlit parts, or
use the CAST flag to prevent self shadows.
- Stencil shadows are also visible on model polygons that point away from
the light source, which can lead to undesired shadow polygons. To avoid this,
use a material with low ambient and a high diffuse part.
- On surfaces precisely perpendicular to the light source,
z-beating effects can occur between the shadow and the surface. The
engine uses a depth bias value to prevent z-beating, however some
old 3D cards don't support depth bias.
- Shadow rendering can be greatly sped up by using LOD models. By
default, shadows are cast from the first LOD step. This can
be modified through the shadow_lod variable.
Z-pass stencil shadows are faster than z-fail shadows,
but don't allow to move the camera into a shadow volume.
They are the best method for elevated 3rd person
cameras, like in an isometric game. In first person
mode the player's shadow is automatically switched off when z-pass
stencil shadows are activated.
Z-fail stencil shadows are slower than z-pass shadows, but more
robust. They are independent of the camera position and allow LOD
models to differ greatly from the original model, which would otherwise
cause shadow faults with the z-pass algorithm.
Z-fail shadow volumes are columns rather than cones, although the
difference is only visible with close lights. A script can
be used for tracing a ray from a light source to the camera, and
automatically switching to z-fail shadows when the ray hits an obstacle.
Z-buffer shadows are projected onto the floor below the model by the sun
only. The projection direction is given by the sun azimuth and elevation
(sun_angle).
Example:
shadow_stencil = 2; // activate z-fail stencil shadows
See also:
CAST, SHADOW, shadow_threshold
► latest
version online