2D Refraction in Xna 2.0

Last post 04-11-2008, 11:02 AM by Nick Gravelyn. 3 replies.
Sort Posts: Previous Next
  •  04-10-2008, 8:29 PM

    2D Refraction in Xna 2.0

    Hi, what I'm trying to do is to follow the sample on ziggyware.com by Nick Gravelyn posted here.

    It's in Xna 1.0 and I want to use refraction for a water technique in 2.0, except I'm kinda a newbie with effects so I can't convert or use the code.  I was wondering how I might do that or possibly just get a better way to do refraction.  The code is all on the link.

    Thanks in advance.
  •  04-10-2008, 8:41 PM

    Re: 2D Refraction in Xna 2.0

    It's actually a pretty easy upgrade. Here are the changes that need to be made:

    1) Remove the ContentManager content; instance in the Game1 class.
    2) Add this line to the Game1 constructor:

    Content.RootDirectory = "Content";

    3) Remove "Content/" from all of the load calls.
    4) Make sure all the load calls use the Content (upper case C) property.
    5) Move all of the stuff in the LoadGraphicsContent method (all of the stuff inside the if statement) into the LoadContent method.
    6) Remove all the calls to GraphicsDevice.ResolveRenderTarget.
    7) Remove the UnloadGraphicsContent method entirely.

    All the theory (the important part) still applies. I've also uploaded a new version with all these changes if you want. There are comments in the source: Refraction2D.zip.


    Nick Gravelyn -- Microsoft XNA MVP
    XNA Wiki | Zune Games
  •  04-11-2008, 5:28 AM

    Re: 2D Refraction in Xna 2.0

    I've never seen this tutorial ! really nice done ! Is it especially for 2d model or can we extend it like the xna sample ?

    cheers
  •  04-11-2008, 11:02 AM

    Re: 2D Refraction in Xna 2.0

    Sueds:
    I've never seen this tutorial ! really nice done ! Is it especially for 2d model or can we extend it like the xna sample ?

    cheers


    Not entirely sure what you're asking. If you mean is this effect only for 2D stuff then the answer is "kind of". My particular implementation only works in 2D, however it's a similar concept in 3D. So with a little work it shouldn't be too hard to get working in 3D.


    Nick Gravelyn -- Microsoft XNA MVP
    XNA Wiki | Zune Games
View as RSS news feed in XML
©2007 Microsoft Corporation. All rights reserved. Privacy Statement Terms of Use Code of Conduct Feedback