Skip to Main Content
XNA 3.0 Game Programming Recipes: A Problem-Solution Approach
book

XNA 3.0 Game Programming Recipes: A Problem-Solution Approach

by Riemer Grootjans
May 2009
Intermediate to advanced content levelIntermediate to advanced
671 pages
18h 34m
English
Apress
Content preview from XNA 3.0 Game Programming Recipes: A Problem-Solution Approach
CHAPTER 6 ■ ADDING LIGHT TO YOUR SCENE IN XNA 3.0
568
As the result of a vector multiplication with a 44 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; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

XNA 4.0 Game Development by Example: Beginner's Guide

XNA 4.0 Game Development by Example: Beginner's Guide

Kurt Jaegers
Learning LibGDX Game Development - Second Edition

Learning LibGDX Game Development - Second Edition

Suryakumar Balakrishnan Nair, Andreas Oehlke

Publisher Resources

ISBN: 9781430218555Purchase Link