3D Dynamic Reflection in Windows Phone 7


Some classic ways of simulating Full Dynamic Reflection in Computer Graphics are Spherical Reflection (very low quality with lots of gaps but extremely fast), Dual Paraboloid Reflection Mapping (not so slow but not so beautiful) and Dynamic Cube Mapping (Slow but awesome quality).
In this post i will present a way to implement the Dynamic Cub Mapping Reflection in WP7 using only the built-in shaders provided by XNA.

The technic itself is very simple, we just need to set a cube map as a render target and render the scene in the point of the view of the camera. (this presented idea also works on PC and Xbox without change, but there are more clever ways to achieve the same results in these plataforms).
The only big problem is that XNA and Directx (xna runs in the top of it) uses different “hands” orientation.
DirectX uses a left-handed coordinate system and XNA uses a right-handed coordinate system with:

  • Forward is +Z, backward is -Z. Forward points towards the observer.
  • Right is +X, left is -X. Right points to the right-side of the screen.
  • Up is +Y, down is -Y. Up points to the top of the screen.

Microsoft hided all these differences behind the scenes (almost always we dont even know that it exists), but when rendering to cube map targets we need to be aware and more … we need to perform the conversion by hand …

To render the scene we also need to create a special camera as shown in the code below:

public void RenderSceneToTextureCube(RenderTargetCube renderTargetCube, Color backGroundColor, IWorld world, ref Vector3 objPos, GameTime gt,bool drawComponentsPreDraw = true,bool useCuller = false
            , List objListException = null, float nearPlane = 1, float farPlane = 1000
            )
        {
            Matrix proj = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, 1, nearPlane, farPlane);
            proj.M33 *= -1;
            proj.M34 *= -1;
            Matrix viewMatrix = new Matrix();
            // Render our cube map, once for each cube face( 6 times ).
            for (int i = 0; i < 6; i++)
            {
                // render the scene to all cubemap faces
                CubeMapFace cubeMapFace = (CubeMapFace)i;

                switch (cubeMapFace)
                {
                    case CubeMapFace.NegativeX:
                        {
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos -  Vector3.Left, Vector3.Up);
                            break;
                        }
                    case CubeMapFace.NegativeY:
                        {
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos - Vector3.Down,-Vector3.Forward);
                            break;
                        }
                    case CubeMapFace.NegativeZ:
                        {
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos + Vector3.Backward, Vector3.Up);
                            break;
                        }
                    case CubeMapFace.PositiveX:
                        {
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos - Vector3.Right, Vector3.Up);
                            break;
                        }
                    case CubeMapFace.PositiveY:
                        {
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos - Vector3.Up, -Vector3.Backward);
                            break;
                        }
                    case CubeMapFace.PositiveZ:
                        {
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos + Vector3.Forward, Vector3.Up);
                            break;
                        }
                }                
                
                // Set the cubemap render target, using the selected face
                SetCubeRenderTarget(renderTargetCube, cubeMapFace);
                Clear(backGroundColor);
                RenderSceneWithBasicMaterial(world, gt, objListException, ref viewMatrix, ref proj, drawComponentsPreDraw, useCuller);
                RestorePreviousRenderTarget();                
            }
                        
        }

The function RenderSceneWithBasicMaterial() just render all the scene objects with the most basic built-in shader. (other variables names are easily understandable, adjust it to your application) (there are some dumb Vector operations like -Vector3.Backward, fix it =P )

With the cube render target created and populated, we just need to pass it to the built in Environment Shader.
I wont put the code here cause it is straightforward.

Remember that you need to call this function (RenderSceneToTextureCube()) in all the frames and it is pretty slow, so be carefull !
Some things to speedup the process are:

  • Create a small Cube Render Target. (Cubemap render target creation code not shown)
  • Render objects in low resolution without effects
  • Do not render everything in all the frames (do magics like rendering only one face of the cubemap each frame ... )

The end result is very cool, but the price paid to render it is huge.
Obs: this obvious works on PC and Xbox also =P

  1. #2 by the little mermaid princess party on 30 de abril de 2017 - 9:20 am

    I just couldn’t go away your website before suggesting that I actually loved the usual information an individual supply to your guests? Is going to be again regularly in order to check out new posts.

  2. #3 by Review w88 on 30 de abril de 2017 - 9:21 am

    What is usually your opinion of personal blogs and on-line journaling?

  3. #4 by Home Improvement on 30 de abril de 2017 - 9:43 am

    I got what you intend, thanks for putting up.Woh I am lucky to find this website through google. “If one does not know to which port one is sailing, no wind is favorable.” by Seneca.

  4. #5 by viagra online on 30 de abril de 2017 - 9:46 am

    Very rightly conveyed, that its basically a duel between a Pro and Mr. Resistance! The more focused you are, the more professional you become and the greater the chance of winning against Mr. Resistance…. Thnku sir for sharing!

  5. #6 by for details on 30 de abril de 2017 - 9:54 am

    That could be the good reason that pay check services are becoming quite popular super real the challenge

  6. #7 by viagra online on 30 de abril de 2017 - 10:20 am

    I liked the bit about if your rifle jams, just throw it away, unless you want to be dead. I think my Drill would have come nine different kinds of uncorked had someone suggested that to him.NB

  7. #8 by http://autoversicherungtech.top/kfz-versicherung-vergleich-online.html on 30 de abril de 2017 - 10:31 am

    Alweer zo’n geweldig MM-blogje! Alhoewel het natuurlijk wel een SCHANDE is dat jullie materiele bezit zo explosief aan het stijgen is. Konden we vroeger nog grappend roepen: ‘Geen geld, wel spullen’, nu klinkt het oorverdovend luid in mijn oren: ‘WEL geld, VEEL spullen’ !!!

  8. #9 by gsa ser footprint extractor on 30 de abril de 2017 - 11:43 am

    I have been browsing online greater than 3 hours as of late, but I by no means found
    any interesting article like yours. It is lovely worth enough
    for me. Personally, if all site owners and bloggers made good content material as you probably did, the net will likely
    be a lot more helpful than ever before.

  9. #10 by adsense account on 30 de abril de 2017 - 12:01 pm

    You made some good points there. I looked on the internet for the subject and found most individuals will go along with with your blog.

  10. #11 by buy viagra online on 30 de abril de 2017 - 12:16 pm

    I have to say I have tried it both ways and both have a good and a bad side. I think you can make either work for you. Carin mawmom at gmail dot com

  11. #12 by dating american men on 30 de abril de 2017 - 12:19 pm

    please take a look at the internet sites we comply with, including this one, as it represents our picks through the web

  12. #13 by Home Improvement on 30 de abril de 2017 - 12:23 pm

    Thank you for each of your hard work on this web page. Kate takes pleasure in conducting investigations and it’s obvious why. All of us hear all concerning the dynamic means you make worthwhile tips via your blog and as well welcome participation from some other people on that theme and my simple princess is now being taught a lot. Take pleasure in the remaining portion of the year. You are doing a stunning job.

  13. #14 by how to get a date on 30 de abril de 2017 - 12:32 pm

    that would be the end of this article. Right here you will uncover some web-sites that we believe youll enjoy, just click the links over

  14. #15 by generic viagra on 30 de abril de 2017 - 12:50 pm

    Cassell playing for the Chiefs is what will validate your theory that he will be nothing more than Scott Mitchell quality.Why must you taunt me?The tears! The tears just won’t stop!

  15. #16 by contractions on 30 de abril de 2017 - 1:11 pm

    What i don’t realize is in reality how you are now not actually much more well-liked than you might be right now. You’re very intelligent. You understand thus significantly on the subject of this topic, made me in my opinion believe it from numerous various angles. Its like women and men aren’t fascinated until it is one thing to accomplish with Lady gaga! Your individual stuffs nice. Always handle it up!

  16. #17 by small business ideas on 30 de abril de 2017 - 1:12 pm

    I simply couldn’t leave your site before suggesting that I extremely enjoyed the usual info a person provide to your visitors? Is going to be again frequently to check up on new posts

  17. #18 by womens health on 30 de abril de 2017 - 1:30 pm

    You really make it appear really easy together with your presentation but I in finding this matter to be actually something that I feel I would by no means understand. It sort of feels too complicated and very large for me. I’m having a look forward in your subsequent publish, I¡¦ll try to get the cling of it!

  18. #19 by viagra online on 30 de abril de 2017 - 1:30 pm

    Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which we all need, thanks for all the enthusiasm to offer such helpful information here.

  19. #20 by Donald Mitchell Innes Oamps on 30 de abril de 2017 - 1:40 pm

    It’s awesome to go to see this web page and reading the views of all colleagues concerning this post, while I am also keen of getting knowledge.|

  20. #21 by www.krogerfeedback.com on 30 de abril de 2017 - 2:05 pm

    Wow, incredible blog layout! How long have you been blogging for?
    you make blogging look easy. The overall look of your web site is excellent,
    as well as the content!

  21. #22 by lowe's home improvement on 30 de abril de 2017 - 2:09 pm

    I’ve been absent for a while, but now I remember why I used to love this blog. Thanks , I¡¦ll try and check back more often. How frequently you update your website?

  22. #23 by virginia movers on 30 de abril de 2017 - 2:10 pm

    Pretty! This was an extremely wonderful article. Thank you for supplying this information.

  23. #24 by togel online on 30 de abril de 2017 - 2:27 pm

    Awesome write-up. I’m a regular visitor of your web site and appreciate you taking the time to maintain the excellent site. I will be a regular visitor for a really long time.

  24. #25 by std safe sex on 30 de abril de 2017 - 2:31 pm

    Sites of interest we have a link to

  25. #26 by island on 30 de abril de 2017 - 2:32 pm

    Excellent read, I just passed this onto a colleague who was doing a little research on that. And he actually bought me lunch since I found it for him smile So let me rephrase that: Thank you for lunch!

  26. #27 by bandarQ on 30 de abril de 2017 - 2:33 pm

    Awesome write-up. I’m a normal visitor of your website and appreciate you taking the time to maintain the nice site. I will be a frequent visitor for a long time.

  27. #28 by http://kreditvergleich365.top/kreditrechner.html on 30 de abril de 2017 - 3:43 pm

    For better or worse, my kids never had a lovey that was this important to them.I say for worse because this meant there was no easy fix or method of calming them during a meltdown.On the upside, however, I was never on the lookout for a shady character in a trench coat…julie gardner’s last awesome post…

  28. #29 by Alat pemadam kebakaran on 30 de abril de 2017 - 4:07 pm

    You should take part in a contest for one of the best blogs on the web. I will recommend this site!

  29. #30 by cantiksehatgue.blogspot.com on 30 de abril de 2017 - 4:12 pm

    Hey there. I discovered your blog via Google while looking for a similar matter, your site came up. It seems to be good. I’ve bookmarked it in my google bookmarks to come back then.

  30. #31 by Office movers in Virginia on 30 de abril de 2017 - 4:16 pm

    Well I truly enjoyed studying it. This article provided by you is very useful for good planning.

  31. #32 by sbobet on 30 de abril de 2017 - 4:30 pm

    Hello there. I found your website by the use of Google while searching for a similar matter, your web site got here up. It seems great. I’ve bookmarked it in my google bookmarks to visit then.

  32. #33 by review ibosport on 30 de abril de 2017 - 4:34 pm

    You actually make it appear really easy along with your presentation however I in finding this topic to be really one thing which I feel I’d by no means understand. It kind of feels too complex and extremely extensive for me. I’m taking a look ahead to your next publish, I will attempt to get the dangle of it!

  33. #34 by patagonia outlet maine on 30 de abril de 2017 - 5:02 pm

    Great points altogether, you just gained a brand new reader. Do you have any feedback on your most recent post though?
    patagonia outlet maine http://www.joessmogtestonly.com/patagonia/

  34. #35 by buy viagra online on 30 de abril de 2017 - 5:19 pm

    it's fake–what more do you need?? God, what is it with these people that they can hear the truth, hear the facts, and still they pretend like nothing is wrong. I JUST DON'T GET IT!

  35. #36 by http://bestviagraonlinesales.top/ on 30 de abril de 2017 - 5:36 pm

    Hope for the best, expect the worst….love itI’ve been bitching about the O-line for 2 seasons now. You can’t have the most sacked QB in the NFL & win games; unless of course, you have a defense that shows up….SHIT! We’re FUCKED!I take that last bit back. No we aren’t. Time to find a way to win.GO PACK GO!

  36. #37 by free google play gift card codes on 30 de abril de 2017 - 5:38 pm

    Hiya, I am really glad I’ve found this information. Today bloggers publish just about gossip and web stuff and this is really annoying. A good website with exciting content, that is what I need. Thanks for making this site, and I will be visiting again. Do you do newsletters by email?

  37. #38 by generic viagra on 30 de abril de 2017 - 6:15 pm

    C’est une prise pour la masse (le – de l’alimentation). Ce n’est pas bien grave si elle reste sans être branchée. Normalement elle est reliée à la partie métallique du clavier.

  38. #39 by dishtv online recharge on 30 de abril de 2017 - 9:04 pm

    This piece of writing will help the internet visitors for creating new blog or even a
    weblog from start to end.

  39. #40 by His and Hers Sex Toys on 30 de abril de 2017 - 9:49 pm

    below youll discover the link to some sites that we think you need to visit

  40. #41 by kittens for sale near me on 30 de abril de 2017 - 9:50 pm

    {Interesting|Lovely!!!!! :D|Beautiful|Congrat for almost reaching 2k subbies|You’re very welcome!

     :) Of course!!!!|+My EcoKids Club Thank you !
    So nice of you to take the time to watch our article and comment >Please keep watching
    and let us know if you would like a specific reading .|Thank
    you !!|Thank you!! We made it!! Yay|no dis likes wow YOU
    MUST BE A GREAT PERSON and this was posted last year|I love
    dogs|i like trainz|i love cats|i love cats|this reminds me of
    Yurio Plisetsky|I love cats|I can’t have a
    cat my dad’s allergic. :'(|In our place theirs a cat running
    around in our house named sunny you should get her
    or him.|i’m allergic to cats|im bunny and every
    animal and plushie lover|i love cats or you|like meeeeeeee|I
    can relate so much from this|me too bloody i FREAKING LOVE CATS IM
    A CRAZY CAT GIRLLLL!!!!!!|yaaaasssss me I love kitty’s lol|I love CATs too there so CUTE|Alexis: THIS IS HOW I FEEL ABOUT
    CATSSSSSSSSS (Ima srry life -.-)|and i luv u!!!!!!!|there’s know a game
    and the cats sleep walk play and I got it for free|* gives u a neko cat a real one not the ones u see at China house *|Clicking subscribe now…..|I can be
    your cat :3|meow~ (=^・ω・^=)|LOL ME TOO I LUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUV CATS|my cat has 1
    eye. it ssaadd|me too I am cat lover|awwwwwwwwww, that’s so cute!|Are you somehow related to Sebastian in black butler?
    XD|I love cats too :3|I OHMYGAWD I LOVE CATS SO MUCH I GOTTA MAKE THIS OMG!!!!
    (i used to have a cat….)|It’s not your fault,
    i have two pet cats, the black one named Moonlight, the second one is named Ginger i
    love them so much. X3|Sqeeeeeeee SAME|I love cats too |im a dog lover and cat lover DONT JUDGE ME!|GEEZZ!!
    TAKE MY FREAKING CAT!!!!!! PLZZZ!!!btw i loved it!|I’m
    A CAT LOVER TOO!!!! |same im a cat lover|oh this
    so cut QuQ|you haven’t made my request yet ;-;|OMG I LOVE CAT(ALL
    ANIMALS)|awwww this is just cute, and my grandmothernever wanted me to have a cat cuz I just keep
    on loosing them >^<3|Ma sono meravigliosiiii! *_*|:) sei gentilissima come sempre ^^|Grazie mille <3|thanks! ^.^|Facciamolo su questo canale per'ho C:|Se ti va facciamo un article in collaborazione? scegli tu il tema! Mandami un mex su posta personale sarebbe divertente.. P.s ti adooorooo <3|Grazie, si avevo già in mente qualcosa con i gufi spero riescano bene ^.^|che cariniiiiiiii *_* la feresti con dei gufi diversi tra loro? *_*|Sono felice che ti piacciano ^.^ <3|Grazie mille, allora proverò a fare un leoncino per il prossimo article ^.^|carinissimi! Brava! sono davvero dolcissimi… mmmm un… leone? :)|Visiti il mio canale??|Grazie sono felice ti piacciano ^.^|I love coat hangers too…..Naah no i don't|xD I lost it at "online dating"|HOORAY FOR HORRIBLE WEBCAM QUALITY! GO FRAWN! |Lol you did her voice perfectly|HAAHAHAHAHHAHAHAHAHAHAHA|holy f*&k this so funny ….loved it.|

  41. #42 by cheap viagra on 30 de abril de 2017 - 10:18 pm

    Olá Bruno, obrigado pelo comentárioE agradeço muito a frase que colocou: “Se quer mudar a vida para si, primeiro mude você para a vida.” …..excelente!Abraço Responder16/10/2011

1 543 544 545
(não será publicado)