Challenge


As a little challenge to get more familiar with shaders you should now write a simple DiffusePerPixel shader, which works the same way as the SpecularPerPixel shader except for the specular color component, which is cut out. DiffusePerPixel will be more useful for non-shiny materials, and to switch between SpecularPerPixel and DiffusePerPixel you should have two techniques in the SimpleShader.fx file.

With the following code you can then dynamically choose between the two techniques based on whether or not the user currently pressed space:

  if (Input.Keyboard.IsKeyDown(Keys.Space))   effect.CurrentTechnique = effect.Techniques["DiffusePerPixel"]; else   effect.CurrentTechnique = effect.Techniques["SpecularPerPixel"]; 

If you are still very excited about the whole shader idea you also might want to check out the shaders included with FX Composer in the HLSL directory of the program. Maybe you can play around with them a little or even try to implement them into SimpleShader.fx.

Have fun!




Professional XNA Game Programming
Professional XNA Programming: Building Games for Xbox 360 and Windows with XNA Game Studio 2.0
ISBN: 0470261285
EAN: 2147483647
Year: 2007
Pages: 138

Similar book on Amazon
XNA Game Studio 4.0 Programming: Developing for Windows Phone 7 and Xbox 360 (Developer's Library)
XNA Game Studio 4.0 Programming: Developing for Windows Phone 7 and Xbox 360 (Developer's Library)
Learning XNA 3.0: XNA 3.0 Game Development for the PC, Xbox 360, and Zune
Learning XNA 3.0: XNA 3.0 Game Development for the PC, Xbox 360, and Zune
Beginning XNA 2.0 Game Programming: From Novice to Professional (Expert's Voice in Game Programming)
Beginning XNA 2.0 Game Programming: From Novice to Professional (Expert's Voice in Game Programming)
Microsoftu00ae XNAu00ae Game Studio 3.0: Learn Programming Now! (Pro - Developer)
Microsoftu00ae XNAu00ae Game Studio 3.0: Learn Programming Now! (Pro - Developer)

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net