Game Development Reference
In-Depth Information
void main()
{
float t = (vertexPosition.w < 0.5) ? 1.0 : 0.0;
vec4 extrudedPosition =
vec4 (vertexPosition.xyz + lightDirection, vertexPosition.w);
extrudedPosition = vertexPosition - extrudedPosition * t;
gl_Position = vec4 (dot(mvpMatrix[0], extrudedPosition),
dot(mvpMatrix[1], extrudedPosition),
dot(mvpMatrix[2], extrudedPosition),
dot(mvpMatrix[3], extrudedPosition));
}
In the case that shadow volume caps must be rendered for a point light
source (see the next section), a vertex shader similar to the one in Listing 10.2
should be used to transform vertices belonging to triangles that face away from
the light. As demonstrated in Listing 10.4, extruded cap vertices can be obtained
by simply subtracting the x , y , and z coordinates of the light's position from the
vertex's position and assuming that the result has a w coordinate of 0. As shown
in Figure 10.11, the silhouette extrusion for an infinite light source always comes
to a point, so caps are never necessary.
Listing 10.4. This vertex shader extrudes vertices belonging to a shadow volume cap away from a
point light source. (Note that the extruded position is only a three-dimensional vector here.) Vertex
p ositions are then transformed into homogeneous clip space.
in vec4 vertexPosition; // The object-space vertex position.
uniform vec4 mvpMatrix[4]; // The model-view-projection matrix.
uniform vec3 lightPosition; // The object-space light position.
void main()
{
vec3 extrudedPosition = vertexPosition.xyz - lightPosition;
gl_Position = vec4 (dot(mvpMatrix[0].xyz, extrudedPosition),
dot(mvpMatrix[1].xyz, extrudedPosition),
dot(mvpMatrix[2].xyz, extrudedPosition),
dot(mvpMatrix[3].xyz, extrudedPosition));
}
Search Nedrilad ::




Custom Search