Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 4 (100 posts) 1 2 3 4 Next >

Tutorial: XNA Shader Programming

Last post 5/7/2012 3:10 PM by Vidar_0. 99 replies.
  • 3/25/2009 10:32 AM

    Tutorial: XNA Shader Programming

    Hi,

    I have just posted my XNA Shader Programming tutorial on my blog. I have had many presentations and workshops regarding XNA here in norway, and this is my collection related to shader programming.
    The tutorials have been written as simple as possible in order to make them easy to follow. This means that there is no custom classes handling shaders, advanced scenes and so on.

    I'm currently in the process of porting my tutorials to from XNA 3.1 to 4.0.

    XNA 4.0 Shader Programming
  • 3/25/2009 10:50 AM In reply to

    Re: XNA Shader Programming Tutorial

    Nice series. Congratulations!
  • 3/25/2009 11:19 PM In reply to

    Re: XNA Shader Programming Tutorial

    Thank you! :)

    I have added an other tutorial about gloss maps.
  • 3/30/2009 1:08 PM In reply to

    Re: XNA Shader Programming Tutorial

    Very nice tutorial, thank you very much!

    The only complain right now is that you could have a little more comments in the shader.fx, and some of your comments are in the Norwegian Language..
  • 3/30/2009 1:12 PM In reply to

    Re: XNA Shader Programming Tutorial

    Yeah, the examples was in norwegian at first. I will go trough the tutorials later and fix it all and add some commets. Thank you for the feedback!
  • 3/31/2009 1:36 PM In reply to

    Re: XNA Shader Programming Tutorial

    After three days of trial and error with shader-programming, I now finally understand how it all works! I modified your normal map example to work with multiple lights.

    Now to the problem, after each render loop I want to use a spritebatch to draw some text to the scene. But if I use the spritebatch, all the 3d-surfaces get totally blank.

    My code looks like this
               graphics.GraphicsDevice.Clear(Color.Black); 
              
                effect.CurrentTechnique = effect.Techniques["NormalMapping"]; 
     
                // Begin our effect 
                effect.Begin(); 
     
                foreach (EffectPass pass in effect.CurrentTechnique.Passes) 
                { 
                     //-----    ------// 
                } 
                // Stop using this effect 
                effect.End(); 
     
                //Here comes the problem 
                spriteBatch.Begin(); 
                spriteBatch.End(); 
                //Every thing works fine until I use the spriteBatch 
     

  • 3/31/2009 2:49 PM In reply to

    Re: XNA Shader Programming Tutorial

    TG Viking:
    Now to the problem, after each render loop I want to use a spritebatch to draw some text to the scene. But if I use the spritebatch, all the 3d-surfaces get totally blank.
    Let Teh Shawn show you the light. :)
  • 3/31/2009 3:24 PM In reply to

    Re: XNA Shader Programming Tutorial

    Thanks for the tutorials. They made me understand better how the whole thing works ! Now, I can get fun with the shaders !
  • 3/31/2009 7:03 PM In reply to

    Re: XNA Shader Programming Tutorial

    TG Viking: You need to call SaveState when using the spriteBatch. spriteBatch.

    Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);


    I'm happy these tutorials help you guys. This gives me a lot of motivation, and I'm currently writing a few more examples and tutorials :) Also, if anyone lives in Oslo, I will now start holding monthly XNA presentations at NITH ( A university college ),Oslo.

    I will also update the old tutorials with comments once my work gives me some spare time..
  • 4/1/2009 1:36 AM In reply to

    Re: XNA Shader Programming Tutorial

    Thanks for the help, it works now..

    Im stuck on another thing, I want to know how I can send arrays to my shader.
    //If my shader have this variable:
    float range;
    //I send my value like this:
    effect.Parameters["range"].SetValue(8);

    //But if my shader have this array??
    float ranges[12];
  • 4/1/2009 11:10 AM In reply to

    Re: XNA Shader Programming Tutorial

    Did you try this?

    float[] myArray = new float[12];
    effect.SetValue("ranges", myArray);

    in the shader:
    float ranges[12];


    Or else, you can devide the array into a few float4s, but that might not be good enough.

  • 4/1/2009 12:09 PM In reply to

    Re: XNA Shader Programming Tutorial

    Thanks!  Why didn't I think of that! This is the one that works:

    effect.Parameters["ranges"].SetValue(new float[4] {1,1,1,1});
  • 4/3/2009 12:57 PM In reply to

    Re: XNA Shader Programming Tutorial

    Sounds good :) I usually send paramteres to shaders like this, reducing the amount of declarations in the shader and less variables passed to the shader.
  • 4/3/2009 12:57 PM In reply to

    Re: XNA Shader Programming Tutorial

    I still havent been able to update my tutorials this week due to a lot of work.. Work, eat, sleep every day.

    I will fix this during the weekend :)
  • 4/5/2009 11:18 AM In reply to

    Re: XNA Shader Programming Tutorial

    All tutorials updated!

    I have commented all of the shaders in my tutorials and they are now uploading. If the download does not work, please try again soon!
  • 4/5/2009 1:34 PM In reply to

    Re: XNA Shader Programming Tutorial

    Nice to hear! I run across another problem with your tutorial. The mesh (sphere.x) must have it properties changed to work on xbox, set "Generate Tangent Frames" to be True.
  • 4/5/2009 6:03 PM In reply to

    Re: XNA Shader Programming Tutorial

    Yes, that is for normal map right?
  • 4/5/2009 7:08 PM In reply to

    Re: XNA Shader Programming Tutorial

    yess, or else they they will only be gray spots on the model then it is played on xbox
  • 4/6/2009 12:02 AM In reply to

    Re: XNA Shader Programming Tutorial

    Thanks, this is now fixed as well :)
  • 4/15/2009 12:47 PM In reply to

    Re: XNA Shader Programming Tutorial

    My time is slowly starting to get balanced again after a hectic easter. This means I can start writing more shader tutorials. I got some tutorials in my mind but I want to know what you guys need to learn? Anything you want me to write about?
  • 4/15/2009 10:50 PM In reply to

    Re: XNA Shader Programming Tutorial

    How about a shield effect tutorial? As in a transparent sphere around a spaceship or ground object that changes color/shape when hit.

  • 4/16/2009 4:44 PM In reply to

    Re: XNA Shader Programming Tutorial

    I modyfied your bump-map code with multiple lights (3), that could be a good toturial. Im also interested in a multiple-lights+bump+specular+shadows, mostly how you would pick out witch object is affected by witch light. 

    Im also curius about how spotlights works, all your examples are with point lights.

    I've never seen any solutions where you look straight into a lamp and get a nice light effect.

    Also more about how I can optimize the useage of the shader, when do I know when something is outside the screen? How you normally handle frame rate dropping.

    And one last thing, textures in the far background can be very noisy (looks like an old movie), how do you normally handle that problem?
  • 4/22/2009 9:24 AM In reply to

    Re: XNA Shader Programming Tutorial

    Sure, I'll add some multiple lights tutorials :)

    I have added two post process tutorials, and will be creating a few more of them as this is the main area I get questions about.

    My two new tutorials can be found here:
    9 - Wiggle post process
    10 - Invert post process

    (and on the main post)
  • 4/22/2009 9:29 AM In reply to

    Re: XNA Shader Programming Tutorial

    TG Viking:


    I've never seen any solutions where you look straight into a lamp and get a nice light effect.


    There are many ways of doing this, and HDR laighting can be a good approach. If you mean that "a nice effect" is only the viewer that gets blended, you can take the angle between the view vector and the light direction, and have a white quad on the screen that gets blended based on the Dotproduct between those two vectors.

    TG Viking:

    And one last thing, textures in the far background can be very noisy (looks like an old movie), how do you normally handle that problem?


    Do you mean z-buffer fighting/flickering? If so, you can try and modify the near/far clipping plane dynamically, making it as correct as possible.
  • 4/24/2009 6:10 AM In reply to

    Re: XNA Shader Programming Tutorial

    Good tutorial!
    Can you write a tutorial about transparency and alpha maps?
Page 1 of 4 (100 posts) 1 2 3 4 Next > Previous Discussion Next Discussion