Game Development Reference
In-Depth Information
vector eyeToVertex = input.position;
// transform normals to view space. Set w
// components to zero since we're transforming vectors.
// Assume there are no scalings in the world
// matrix as well.
input.normal.w = 0.0f;
input.faceNormal1.w = 0.0f;
input.faceNormal2.w = 0.0f;
input.normal = mul(input.normal, WorldViewMatrix);
input.faceNormal1 = mul(input.faceNormal1, WorldViewMatrix);
input.faceNormal2 = mul(input.faceNormal2, WorldViewMatrix);
// compute the cosine of the angles between
// the eyeToVertex vector and the face normals.
float dot0 = dot(eyeToVertex, input.faceNormal1);
float dot1 = dot(eyeToVertex, input.faceNormal2);
// if cosines are different signs (positive/negative)
// then we are on a silhouette edge. Do the signs
// differ?
if( (dot0 * dot1) < 0.0f )
{
// yes, then this vertex is on a silhouette edge,
// offset the vertex position by some scalar in the
// direction of the vertex normal.
input.position += 0.1f * input.normal;
}
// transform to homogeneous clip space
output.position = mul(input.position, ProjMatrix);
// set outline color
output.diffuse = Black;
return output;
}
17.6 Summary
Using vertex shaders, we can replace the transformation and light-
ing stages of the fixed function pipeline. By replacing this fixed pro-
cess with our own program (vertex shader), we can obtain a huge
amount of flexibility in the graphical effects that we can achieve.
Vertex declarations are used to describe the format of our vertices.
They are similar to flexible vertex formats (FVF) but are more
flexible and allow us to describe vertex formats that FVF cannot
describe. Note that if our vertex can be described by an FVF, we
can still use them; however, internally they are converted to vertex
declarations.
Search WWH ::




Custom Search