Dest Shadow Material


shadow cast on leaves, but no fill interstice

Dest Material control how to blend shadow map with scene.
e.g. Use alpha test technic to splash shadow map to simulate shader on grass, leaves.

The flow to project shadow map:

1. Set TexCoordIndex[0] to CameraSpacePosition; set TextureTransformFlags[0] to Count4|Projected; set a texture transform matrix for stage0, so let generated texture coordinates bounds to 0 to 1

2. Set texture address mode of stage0 to Clamp (or Border mode if device is supported).

3. Set shadow map texture to texture0

4. Turn on alpha blend; SrcBlend=Zero, DestBlend=InvSrcColor; if reverse shadow, ScrBlend and DestBlend are all =One;

5.
For surfaces:
    1). If no use ready shadow map, set ColorOp[0] to SelectArg1;
   
2). If use ready shadow map, set TextureFactor to Light's color, set ColorArg1[0] to Texture, set ColorArg2[0] to TFactor. Set ColorOp[0] to SelectArg1 ( or Modulate  if reverse shadow ).

    For meshs:
    1). If no use ready shadow map, set ColorArg2[0] to Diffuse, set ColorOp[0] to Modulate;
   
2). If use ready shadow map, set TextureFactor to Light's color, set ColorArg1[0] to Texture, set ColorArg2[0] to TFactor. Set ColorOp[0] to SelectArg1 ( or Modulate  if reverse shadow ). Set ColorArg1[1] to Diffuse, set ColorOp[1] to Modulate.
   
3). Turn off all lights, only turn on the current light that produce shadow.

6. Activate dest shadow material and draw the objects in shadow.

 

Remark:

There is preset matrix matShadowViewProj for vertex/pixel shader.