Fast Shadows Documentation

FAST SHADOWS DOCUMENTATION

HOW IT WORKS

A FS_SimpleShadow component is added to objects that will have shadows. During Update each of these objects does a raycast to determine if a shadow should appear on any surfaces (based on the layer mask). If a shadow is needed then the object registers itself with the FS_ShadowManager. During LateUpdate the shadow manager generates a shadow mesh for each group of shadows that share the same material. If all shadows share the same texture then a single mesh is generated (one draw call). Otherwise it will generate several meshes (several draw calls). Each shadow is a quad that hovers above a surface.

==============
QUICKSTART

Drag the FS_SimpleShadow script to an object in your scene or add if from the Component menu. Press play and it will have a shadow.

==============
DESCRIPTION OF OPTIONS

LAYER MASK

Shadows will only appear on layers selected here.

MAX PROJECTION DISTANCE

This is the maximum distance that a shadow will be cast from an object. Shadows will
fade as they approach this distance and then disappear.

SHADOW SIZE

The size of the shadow.

SHADOW HOVER HEIGHT

The shadow will hover at this height above a surface.

STATIC

If shadows will not move then setting a shadow to static can improve performance. Static shadows are calculated once at “Start” and are not recalculated again. The only overhead for static shadows is the draw call. Hundreds of static shadows can be rendered at almost the same speed as one. Note that static shadows are rendered with a separate draw call from non-static shadows. If you only have a few static shadows you are probably better off not using the static option.

SHADOW MATERIAL

The material used by the shadow. It is recommended to duplicate the FS_ShadowMaterial found in the Resources folder and use this for your shadows. Replace the material texture if you want a custom shape. There will be a separate draw call for each shadow material used. Multiple shadow shapes can share the same material by using a texture atlas and setting the UV coordinates.

UV RECT

Multiple shadow shapes can share the same material by using a texture atlas and setting the UV coordinates. The rectangle specified here must be in a square of size 1 x 1.

USE LIGHT SOURCE GAME OBJECT

Incoming light direction can be described by:

  • A light direction vector (infinitely distant light source)
  • A game object (usually a light). Shadows will move and distort as an object moves relative to the light

USE PERSPECTIVE PROJECTION

This only works with a if “Use Light Source” has been selected. If checked then shadows will distort and grow as the shadow-casting object approaches the light source.

================
TROUBLESHOOTING

If shadows do not appear

– Shadows only appear in play mode. They don’t not appear in the editor.

– Check the layer mask. Shadows only appear on the selected layers. if the layer mask has been set to ‘Everything’ the shadow may be appearing on the shadow casting object itself.

– Check that the ShadowMaterial has been set up correctly.

– Check the “Max projection distance” value. Shadows will not appear beyond this distance.

Strange shadow rotation

Fast Shadows tries to rotate the shadow to match the orientation of and object. It assumes:

  • y – is up
  • z – is forward
  • x – is right

If your model is not set up this way then fast shadows can still be used by setting up your hierarchy this way:

GameObject
– Model (with necessary rotations)
– GameObject (FS_SimpleShadow is attached to this)

Debugging

Gizmos are drawn in the scene view when playing.
-Enable gizmos
– Click play
– Click pause and switch the the scene view. A frustum should be visible for the shadow.