Thursday 19 October 2017

Dual-Paraboloid Environment Mapping in HLSL (XNA 4.0)

"Dual-Paraboloid Reflections" demo

Hey, guys! Today I want to talk a little about Dual-Paraboloid Reflections and show their implementation in High-Level Shader Language using XNA 4.0 environment. The code and explanation are partially based on the post of Kyle Hayward from 2008, so I have decided to revive this topic because it's still popular among game developers these days. That means that you won't find anything new if you are familiar with this technique, but if not, it will be a great chance to discover or at least look at some fancy pictures :) 

Dual-Paraboloid Mapping is another way of doing the environment mapping in your scene besides cube or sphere maps. This method is cheaper than cube-mapping, as we have to update only 2 textures, not 6 as for the cube map

Let me explain what is actually going on with all this stuff. So as you may have guessed this method uses two hemispheres (front and rear) that reflect all incident rays in a constant direction.  

   
An example chart of elliptic paraboloid
Sample function equation of elliptic paraboloid
Image courtesy of Imagination Technologies


Now we have to calculate the mapped coordinate. A normal vector at the point of intersection is the result of an addition of an incident and a reflection vectors. We should also divide its x, y and z components by z to get a scaled result. 


The vertex shader should be pretty clear now: 


In the pixel shader, we will generate and sample our textures. Remember that we have to store only front and back.

So that's it! Nothing overcomplicated, because the method is quite similar to cube mapping. Unfortunately, the results will not be as good as with cube maps. Some of you could have noticed the artifacts on the spheres from the top picture. If not, here is another, more evident, example:


In general, this method can be very useful in some situations during the development, although the quality of reflections will be lower compared to cube mapping. Some great examples of using dual-paraboloid mapping are "Grand Theft Auto IV" and "Grand Theft Auto V" by Rockstar Games. These amazing games have some beautiful visuals, including the reflections :)

"Grand Theft Auto IV" by Rockstar Games

"Grand Theft Auto V" by Rockstar Games
Links:

No comments:

Post a Comment