Tutorial 8 - Simple Shadows
By Pieter Germishuys, January 4 2006
For ultimate realism what
better way to produce this then actually implementing shadows. This is definitely
not the best method but it's a good hack.
What is a Shadow?
A shadow is a dark shape, e.g. on the ground or a wall, caused by an object (or person, etc.) blocking light.
What do we need to know?
Now that we know what a shadow is, how do we produce one?
Since this is a beginner tutorial I am not going to be using shaders nor am I going to use any difficult tricks.
The theory is simple for this exercise.
1) Create a plane that will define the normal of the object
2) Use the Matrix.Shadow method to create a transformation that will flatten the geometry to a plane.
3) Render your Solid object with a the world matrix
4) Render your Solid object again, this time with the shadow Matrix.
Declaring your objects.
|private Box box;
private Floor floor;
private Plane shadowPlane;
private Matrix matShadow;
private Matrix matFloor;
private Matrix matBox;
private Material mtrlBox;
private Material mtrlFloor;
private Material mtrlShadow;
The constructor that will initialize our objects and load our mesh.
window = new Window();
//setup our point light
//enable lighting in our
//I created a simple floor
and box class that will just instantiate our box and floor
//The floor material
//The plane of the shadow
| private void
//set the box at 10 units above the floor
matBox = Matrix.Translation(0.0f, 10.0f, 0.0f);
//set the floor 1.0 units lower so that we can see the shadow
matFloor = Matrix.Translation(0.0f, -1.0f, 0.0f);
//Render the floor with the position and material
window.D3DDevice.Material = mtrlFloor;
window.D3DDevice.Transform.World = matFloor;
//Render the box with the position and material
window.D3DDevice.Material = mtrlBox;
window.D3DDevice.Transform.World = matBox;
//Render the shadow box with the position and material
window.D3DDevice.Material = mtrlShadow;
window.D3DDevice.Transform.World = matShadow;
Files for this tutorial