Game Development Reference
In-Depth Information
Let ( n x , n y , n z , d ) be a 4D vector representing the coefficients of the
general plane equation describing the plane that we wish to cast the
shadow onto. Let L =( L x , L y , L z , L w ) be a 4D vector describing either
the direction of a parallel light or the location of a point light. We use
the w coordinate to denote which:
1. If w = 0, then L describes the direction of the parallel light.
2. If w = 1, then L describes the location of the point light.
Assuming the normal of the plane is normalized, we let k =( n x , n y , n z ,
d ) ( L x , L y , L z , L w )= n x L x + n y L y + n z L z + dL w .
Then we represent the transformation from a vertex p to its projection
s with the following shadow matrix :
n
L
k
n
L
n
L
n
L
x
x
x
y
x
z
x
w
n
L
n
L
k
n
L
n
L
y
x
y
y
y
z
y
w
S
n
L
n
L
n
L
k
n
L
y
x
z
y
z
z
z
w
dL
dL
dL
dL
k
x
y
z
w
Because it's been done elsewhere and not of significant importance to
us, we do not show how to derive this matrix. However, for the inter-
ested reader, we refer you to Chapter 6, “Me and My (Fake) Shadow,”
of Jim Blinn's Corner: A Trip Down the Graphics Pipeline , which shows
how this matrix can be derived.
The D3DX library provides the following function to build the
shadow matrix given the plane that we wish to project the shadow to
and a vector describing a parallel light if w = 0 or a point light if w =1:
D3DXMATRIX *D3DXMatrixShadow(
D3DXMATRIX *pOut,
CONST D3DXVECTOR4 *pLight, // L
CONST D3DXPLANE *pPlane
// plane to cast shadow onto
);
8.3.4 Using the Stencil Buffer to Prevent Double
Blending
When we flatten out the geometry of an object onto the plane to
describe its shadow, it is possible that two or more of the flattened tri-
angles will overlap. When we render the shadow with transparency
(using blending), these areas that have overlapping triangles will get
blended multiple times and thus appear darker. Figure 8.8 shows this.
Search WWH ::




Custom Search