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);
                    case CubeMapFace.NegativeY:
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos - Vector3.Down,-Vector3.Forward);
                    case CubeMapFace.NegativeZ:
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos + Vector3.Backward, Vector3.Up);
                    case CubeMapFace.PositiveX:
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos - Vector3.Right, Vector3.Up);
                    case CubeMapFace.PositiveY:
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos - Vector3.Up, -Vector3.Backward);
                    case CubeMapFace.PositiveZ:
                            viewMatrix = Matrix.CreateLookAt(objPos, objPos + Vector3.Forward, Vector3.Up);
                // Set the cubemap render target, using the selected face
                SetCubeRenderTarget(renderTargetCube, cubeMapFace);
                RenderSceneWithBasicMaterial(world, gt, objListException, ref viewMatrix, ref proj, drawComponentsPreDraw, useCuller);

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. #1 by kontraktor rumah jogja on 21 de julho de 2017 - 4:57 am

    Hi there. I found your website by way of Google whilst looking for a similar topic, your site came up. It looks good. I’ve bookmarked it in my google bookmarks to visit then.

  2. #2 by Buat kaos murah on 21 de julho de 2017 - 6:02 am

    Hello there. I found your website by means of Google while searching for a comparable topic, your website came up. It appears to be good. I have bookmarked it in my google bookmarks to visit then.

  3. #3 by Kaos kampanye on 21 de julho de 2017 - 6:07 am

    Awesome post. I am a normal visitor of your web site and appreciate you taking the time to maintain the nice site. I’ll be a regular visitor for a long time.

  4. #4 by frameless shower enclosures north vancouver on 21 de julho de 2017 - 6:15 am

    Sites of interest we’ve a link to

  5. #5 by Health and Fitness on 21 de julho de 2017 - 6:25 am

    I view something really special in this site.

  6. #6 by php open source code on 21 de julho de 2017 - 6:39 am

    we came across a cool internet site which you may well get pleasure from. Take a search in the event you want

  7. #7 by Loker kuningan terbaru on 21 de julho de 2017 - 6:56 am

    Hey there. I found your web site by the use of Google whilst looking for a similar topic, your website came up. It seems great. I have bookmarked it in my google bookmarks to come back then.

  8. #8 by ostrich egg on 21 de julho de 2017 - 6:58 am

    Amaze, splendid blog page design! The best way long were you writing a blog with regard to? you . ostrich egghave made running a blog search straightforward. The whole glimpse of your respective site is astounding, aside from the content substance!

  9. #9 by Luvenia Shorkey on 21 de julho de 2017 - 7:42 am

    Hi there would you mind sharing which blog platform you’re using? I’m planning to start my own blog in the near future but I’m having a difficult time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I’m looking for something unique. P.S My apologies for getting off-topic but I had to ask!

  10. #10 by green fascinators for weddings on 21 de julho de 2017 - 8:46 am

    I like what you guys are up too. Such smart work and reporting! Carry on the excellent works guys I have incorporated you guys to my blogroll. I think it’ll improve the value of my site :).

  11. #11 by Buat kaos murah on 21 de julho de 2017 - 9:04 am

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

  12. #12 by خرید اپل ایدی on 21 de julho de 2017 - 9:11 am

    usually posts some very intriguing stuff like this. If youre new to this site

  13. #13 by camera on 21 de julho de 2017 - 9:36 am

    Of course, what a fantastic site and instructive posts, I surely will bookmark your site.Best Regards!

  14. #14 by Auto Care and Service on 21 de julho de 2017 - 9:48 am

    Very interesting topic , appreciate it for putting up. “Challenge is a dragon with a gift in its mouthTame the dragon and the gift is yours.” by Noela Evans.

  15. #15 by Health and Fitness on 21 de julho de 2017 - 10:13 am

    fantastic points altogether, you just received a new reader. What might you recommend about your submit that you simply made some days ago? Any positive?

  16. #16 by خرید اپل ایدی on 21 de julho de 2017 - 10:46 am

    we prefer to honor several other internet websites around the net, even though they arent linked to us, by linking to them. Under are some webpages really worth checking out

  17. #17 by oliverzok on 21 de julho de 2017 - 10:51 am

    It is in reality a great and helpful piece of info. I’m
    satisfied that you simply shared this helpful information with us.
    Please keep us up to date like this. Thanks for sharing.

  18. #18 by horse emoji - cute horse stickers on 21 de julho de 2017 - 10:59 am

    although websites we backlink to below are considerably not related to ours, we feel they’re in fact worth a go via, so possess a look

  19. #19 by yến mạch quaker oats quick 1 minute on 21 de julho de 2017 - 12:16 pm

    Heya i’m for the first time here. I found this board and I find
    It truly useful & it helped me out much. I hope to give something
    back and aid others like you helped me.

  20. #20 by album jul je ne me vois pas briller on 21 de julho de 2017 - 1:18 pm

    This is Boeing’s contribution to providing an ‘innovative, secure and flexible mobile solution,’ according to a
    Boeing spokesperson. You can use a free of charge telephone tracker app but they are really
    effortless to detect and do not do close to as very much as this app
    does. Do you suspect that your employee is performing something mistaken with your

  21. #21 by Health and Fitness on 21 de julho de 2017 - 1:22 pm

    Thank you a lot for giving everyone an extremely spectacular opportunity to read in detail from this web site. It is always very cool and as well , packed with fun for me personally and my office fellow workers to search the blog particularly 3 times weekly to learn the latest guides you will have. And of course, we are always impressed with all the good tips and hints you serve. Certain 3 areas in this article are absolutely the very best we have had.

  22. #22 by This post will appeal to your interest > on 21 de julho de 2017 - 1:41 pm

    The disc allure has Kate’s monogram on one aspect, and Camilla’s on the opposite.
    Both Cs are below a coronet, however Kate’s C
    has an additional curl, while Camilla’s is surrounded by a circle.

  23. #23 by Shopping on 21 de julho de 2017 - 2:13 pm

    I think this is among the most vital information for me. And i’m glad reading your article. But wanna remark on some general things, The site style is wonderful, the articles is really great : D. Good job, cheers

  24. #24 by www.fobesa.com on 21 de julho de 2017 - 3:07 pm

    We are referring to your base of cash flow right here.
    In order not to sound like that, you need a voice changer
    that has more than 2 or 3 adjustments. Today, I and Bianca have become best friends again.

1 622 623 624
(não será publicado)