Game Development Reference
In-Depth Information
input.normal.w
= 0.0f;
LightDirection
= mul(LightDirection, WorldViewMatrix);
input.normal
= mul(input.normal, WorldViewMatrix);
//
// Compute the 1D texture coordinate for toon rendering.
//
float u = dot(LightDirection, input.normal);
//
// Clamp to zero if u is negative because u
// negative implies the angle between the light
// and normal is greater than 90 degrees. And
// if that is true then the surface receives
// no light.
//
if(u < 0.0f)
u = 0.0f;
//
// Set other tex coord to middle.
//
float v = 0.5f;
output.uvCoords.x = u;
output.uvCoords.y = v;
// save color
output.diffuse = Color;
return output;
}
A couple of remarks:
We assume the world matrix doesn't do any scaling because if it
does, it can mess up the length and direction of a vector that multi-
plies it.
We always set the v texture coordinate to the middle of the texture.
This implies that we are using only a single horizontal line in the
texture, which implies we could use a 1D luminance texture
instead of a 2D one. However, both 1D and 2D textures work. For
the sample we have used a 2D texture over a 1D texture for no
particular reason.
17.5.3 Silhouette Outlining
To complete the cartoon effect, we need to outline the silhouette edges.
This is a bit more involved than cartoon shading.
Search WWH ::




Custom Search