CS6554 Computer Graphics 2 – Lab 4 – Texture Mapping

For this assignment, our goal was to extend our Renderer Project to include texture mapping, e.g. UV mapping, and use the Phong Shader we had already implemented. Texture mapping is akin to shrink wrapping, gift wrapping or wallpapering a flat sheet onto a complex shape. In order to support texture mapping, additional uv coordinates must be assigned to each vertex in a polygon. Loading and rendering a mesh file that already includes uv coordinates is trivial, but for our project, there are no uv coordinates precalculated in the file data so a critical requirement was to use a texture map algorithm to generate the uv coordinates for any mesh. There are several algorithms that can accomplish this, planar mapping, cylinder mapping, spherical mapping, etc. I chose cylinder mapping as it can be used to map rectangular topographical maps onto spherical bodies and I had already done the early research leg work to understand and apply this approach using 3ds max in my Earth rendering project.

UV coordinates are a normalized approach to addressing texture space. Because Textures or images have varying resolutions and can be scaled, a normalized system allows a texture to be easily replaced with another whether the replacement is with a different resolution of the same texture because the distance to the object changes, as in MIP mapping, or the replacement is with an entirely different texture.

There are varying approaches to cylinder mapping, but the most straight forward is to simply map the x,y,z coordinates of a vertex onto the surface of a cylinder. The vertex x and y components can be transformed to u by projecting them onto the unit circle, measuring the angle from the x-axis to that point and then dividing by 2PI to produce a value clamped between zero and one. The vertex z component can be transformed to v by simply dividing z by the height of the mesh.

The first developmental step required the loading of textures from file. Because of the overall requirement to not utilize any libraries I chose to work with 24-bit bitmaps as parsing them is straightforward and their header information is well documented. Once the bitmap loader was properly vetted through unit testing, I moved on to rendering the texture to a trivial surface.

Isometric View Checker Textured Plane

The plane is straightforward as each corner maps to an extens of the texture. This developmental step afforded me the ability to debug the trilinear interpolation of the uv coordinates and the mapping from screen space pixel to texture space uv coordinate. After proving the ability to load and render a basic texture to a basic surface, I validated that the system would render a more complex topographical texture which would move me one step toward the overall goal that I had set.

Isometric View Earth Textured Plane

After validating the rendering of the topographical texture, I began working on the cylinder map. In order to visualize what the system was calculating, I wrote a function to procedurally generate a cylinder mesh and then used the cylinder texture map function to see the results and to facilitate debugging of the map function.

Once the texture map was validated for the well-controlled cylinder, I applied it to a model from the wild, the better-ball. While the better-ball is a sphere, it contains imperfect data. Because of the floating point math used to generate it, values that approach zero are not actually zero and so some uncertainty was introduced that was not present in the cylinder mesh. Better-ball enabled the texture map function to be validated for these less than perfect models.

Below are renders of the composite scene of the better-ball sphere inside the procedurally generated cylinder. Both models are mapped with the same texture. The cylinder points map to the sphere so you should be able to visualize a line drawn from the central axis of the sphere along a perpendicular plane which intersects with the skin of the sphere. If you extend that line out to the cylinder, you will note that the same color appears on the surface of the cylinder at the point of intersection. The renders include the use of an Earth, Earth at Night, Moon, Sun and Io topographical texture borrowed from NASA.

Isometric View Earth Textured Sphere and Cylinder Map Visualization

Top View Earth Textured Sphere and Cylinder Map Visualization

Isometric View Earth Lights Textured Sphere and Cylinder Map Visualization

Top View Earth Lights Textured Sphere and Cylinder Map Visualization

Isometric View Moon Textured Sphere and Cylinder Map Visualization

Isometric View Sun Textured Sphere and Cylinder Map Visualization

Isometric View Io Textured Sphere and Cylinder Map Visualization

Finally, the cylinder map is applied to an odd non-uniform mesh. In this case the Utah teapot has had the Earth texture applied to it via cylinder map where the cylinder's z axis is aligned in the first case along the x axis of the teapot, in the second case along the y axis of the teapot and in the third case along the z axis of the teapot.

Isometric View Textured Utah Teapot Cylinder Map Along X Axis

Isometric View Textured Utah Teapot Cylinder Map Along Y Axis

Isometric View Textured Utah Teapot Cylinder Map Along Z Axis

Comments are closed.