CHAPTER 6 ■ ADDING LIGHT TO YOUR SCENE IN XNA 3.0
568
As the result of a vector multiplication with a 4✕4 matrix that returns a homogenous vec-
tor, you need to divide the first three components by the fourth before you can use them.
Finally! At this point, you know the 3D position of the pixel. You also know the 3D normal
in this pixel. Together, they allow you to perform any kind of lighting calculation. The remain-
der of the pixel shader calculates the lighting influence of a spotlight and is taken straight from
recipe 6-8. This is your complete pixel shader:
PixelToFrame MyPixelShader(VertexToPixel PSIn) : COLOR0
{
PixelToFrame Output = (PixelToFrame)0;
float3 normal = tex2D(NormalMapSampler, PSIn.TexCoord).rgb;
normal = normal*2.0f-1.0f; ...