Dual Paraboloid Mapping in the Vertex Shader
Accessing Paraboloid MapsNow that we have generated the paraboloid map, we need to be able to access it to put it to good use. How the data is accessed depends on what you are using the maps for, but the general idea applies to any paraboloid map access. The process of calculating the texture coordinates to access the paraboloid maps is quite similar to the method used to generate the map. As an overview of the algorithm, we will follow these steps:
In the case of environment mapping, the vector from P to the desired object is a vector from the camera to the point on the environment-mapped object, which is then reflected about that point's normal vector. So the camera sees what is reflected off of the environment-mapped object. So the first step is to generate the reflected vector: float3 N = normalize( IN.normal ); float3 E = normalize( IN.eye ); float3 R = reflect( E, N ); This reflected vector is now in world space. It is necessary to transform this vector into the paraboloid map's basis. This is essentially done by multiplying by the view transform from the generation phase: R = mul( R, (float3x3)ParaboloidBasis ); With the reflected vector now available, the texture coordinates are calculated in the same way as when generating the paraboloid map. The resulting values are then scaled and biased to account for the texture addressing modes of Direct3D: float2 front; front.x = (R.x / (2*(1 + R.z))) + 0.5; front.y = 1-((R.y / (2*(1 + R.z))) + 0.5); float2 back; back.x = (R.x / (2*(1 - R.z))) + 0.5; back.y = 1-((R.y / (2*(1 - R.z))) + 0.5); These coordinates are then used to sample the two paraboloid maps: float4 forward = tex2D( FrontSampler, front ); float4 backward = tex2D( BackSampler, back ); I chose to use border texture addressing with a black color outside of the texture so that I could simply take the max of the two sampled values to get the environment color at that point. This is shown here: OUT.color = max(forward, backward); The resulting color should be the reflected environment color at that point. Here is a screen shot from rendering a poorly tessellated sphere using the dual paraboloid environment map:
For a complete effect file that implements this dual paraboloid environment mapped effect, see the included file: dual_paraboloid_environment_map.fx ConclusionNow that we understand how paraboloid mapping works, lets consider some of the downsides associated with it. Paraboloid mapping is not perfect. If you examine the wire frame views in Figure 4, you will see that the triangle edges are still straight lines. This is because we apply the paraboloid warping to the vertices of a model when generating the map. The triangle is still rasterized in the same manner – a line segment from vertex to vertex in clip space forms each edge. At first this does not seem to be that big of a deal. However, if you look closely at Figure 5 you will see a couple of areas where artifacts are introduced into the reflected image. This is the area where the front and back maps meet. Around the edges of the paraboloid map shown in Figure 3, there are small areas that appear to be cut into straight lines. This is caused by the scene not being tessellated highly enough to counteract the rasterization effects we just described. Even so, the paraboloid parameterization is still a useful tool to have at your disposal. When used properly it is capable of providing a significant performance increase as opposed to cube mapping, and a quality increase as opposed to spherical mapping. I decided to write this article due to the lack of implementation details available on the web. Hopefully this guide has provided you with some insight into the world of paraboloid mapping. If you feel that this document could be improved or have questions or comments on it please feel free to contact me as 'Jason Z' at gamedev.net. About the AuthorJason Zink is an electrical engineer currently working in the automotive industry. He is currently working towards a M.S. in Computer Science, and has a received a B.S. in Electrical Engineering. He has been writing software for about 8 years in various fields such as industrial controls, embedded computing, business applications, automotive communication systems, and most recently game development with a great interest in graphics programming. |
|