O'Reilly logo

Beginning 3D Game Programming by Tom Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding Specular Highlights to Kart

With the background out of the way, you should take a bit of time to add some basic specular highlights to your car. A specular highlight is an area of glossiness on an object. That's the effect you are going for. To calculate this reflectivity, you not only need to know which direction the light is coming from, but you also need to know the location of the camera (or your “eye”). Add this declaration to your shader code (KartRacers.fx):

float4 eyeVector; // Vector for the eye location

Naturally, you update your rendering code as well, so find the OnFrameRender method in your C# class, and before the call to RenderScene, add the following line:

 effect.SetValue("eyeVector",new Vector4(camera.EyeLocation.X, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required