Lighting Textures

In the previous chapter, simple directional lighting was discussed for a cylinder. The cylinder that was used for that example wasn't textured, and so far the lighting calculations have only been performed in the vertex programs. You can just as easily perform these lighting operations in your pixel shader code as well.

Like the previous example, we will use the simple mesh rendering example from the previous chapter as our starting point. In this section you will take that existing sample and add a colored light to the scene in our pixel shader.

The first step to making this update will be to add the following declarations to your shader code:

 float4x4 WorldMatrix : WORLD; float4 DiffuseDirection; Texture meshTexture; sampler ...

Get Managed DirectX® 9 Kick Start: Graphics and 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.