Adding Realism Using Shading

You don't need to be a graphics designer to realize that doesn't look all that great. It's just a big white blob that vaguely resembles a go-kart. The problem here is that your shader returned 1.0f (pure white) for every vertex, so naturally the entire model is colored pure white. You need to fix this problem, which you do by emulating a directional light from the fixed-function pipeline.

You've been using directional lights throughout this book as a way of making things appear more realistic, and now you implement the same directional light using a shader and the programmable pipeline. Back in the KartRacers.fx file, replace the Transform function with the one in Listing 20.4.

Listing 20.4. Directional Lighting Shader ...

Get Beginning 3D Game Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.