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

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