Simple Projected Shadows

Projected shadows render the actors with a special shadow matrix to produce a shadow on the ground. This would not give you self-shadowing and would only cast the shadow onto the ground, but I think for a sports game such as footbal or soccer this would be fully valid. I think David A. Winter has done it this way in his Maximum Football games, maybe you can find some infos about how he has done it by searching the forums.

The following code will do the trick:

Dim tmpShadowMat, tmpPlayerMat As TV_3DMATRIX
Dim tmpPlane As TV_PLANE 'define a new plane
tmpPlane.Normal = TV_Globals.Vector(0, 1, 0) 'this plane will be your field so the normal goes up
tmpPlane.Dist = 0 'the dist is the height where your field is (in this case 0)
tmpPlayerMat = Player.Actor.GetMatrix() 'Get the players matrix
'create a shadow matrix (only one per light),
'vector4 is the light direction (don't know what the 4th entry is for)
'and the plane is your field where the shadow gets cast onto
TV_Math.TVMatrixShadow(tmpShadowMat, TV_Globals.Vector4(-1, -1, -1, 0), tmpPlane) 
TV_Math.TVMatrixMultiply(tmpShadowMat, tmpPlayerMat, tmpShadowMat) 'multiply the players matrix with the shadow matrix
Player.Actor.SetMatrix(tmpShadowMat) 'set the new matrix
Player.Actor.SetTexture(TV_Globals.GetTex("Black")) 'set a black texture
Player.Actor.Render() 'this renders the "shadow"
Player.Actor.SetMatrix(tmpPlayerMat) 'set the normal matrix
Player.Actor.SetTexture(TV_Globals.GetTex("PlayerTexture")) 'set the normal texture

Of course you can also use a dedicated actor for the shadow rendering, so SetTexture would not be needed.

-By WEst November.10.2007

tutorialsarticlesandexamples/create_simple_projected_actor_shadows.txt · Last modified: 2013/11/22 13:32