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, ...

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.