CSC572 Final Project: Texture Atlas Synthesis

Author: Wesley Hamilton (wdhamilt calpoly edu)

Download

here

Description

The goal of the project was to render a tiger bunny similar to the paper Lapped Textures [4]. The process of Lapped Texturing involves pasting parts of a sample texture onto the bunny. The result can then be saved to another texture called a texture atlas. As a simpler solution to this problem, I decided to to map the texture once onto the whole mesh and while still using a texture atlas to store the results.

I did the texture atlas renderings to an internal datastructure instead of relying on OpenGL calls. I could have saved myself a lot of time and had better results by drawing to a framebuffer object (FBO). The algorithm I made linearly interpolates across an output triangle in 2D. From the generated X,Y coordinates I calculate the input texture position using barycentric coordinates.

Texture Mapping

The basic idea was to plot UV coordinates (positions on the 2D texture) based on a mapping that works for a generic mesh. I chose to use spherical texture mapping seen in the figure below [3,7]. The UV coordinates are calculated using the formula:

tu = asin(Nx)/PI + 0.5
tv = asin(Ny)/PI + 0.5 

The normal (Nx, Ny, Nz) could be estimated as the average of the normal of each polygonal face connected to that vertex. As a shortcut, I approximated the normal at a vertex as the normalized form of the vertex position. This works because the bunny is centered around the origin.

Texture Baking/Atlasing

Texture baking is the the process of drawing material properties of a mesh onto a texture. These material properties can include normals, shadows, lighting conditions, displacements, textures, specularity, or color (normal mapping, shadow mapping, etc). These can then be used to speed up the calculation later by mapping into the texture atlas to retrieve the properties at that given position on a polygon.

The results texture baking from the Lapped Textures paper can be seen below. Image (a) shows the output of the tiger stripes without texture baking. Image (b) shows the output of the bunny with texture baking. Note that it has some aliasing effects that cause distortions. The texture atlas that had the patches baked onto it can be seen in (c).

Screenshots

Previous bugs:

Flat shaded bug
Incorrect interpolation

Bunny renderings from my texture atlas (first) versus texture mapped by coordinates (second). There are many problems with my solution which are listed later.

Current solution:











Mouse Controls

Key Controls

Issues

This section describes problems with my solution that are results of the algorithm choice and not bugs.

  1. White pixels show up without extending the atlased triangles one pixel. Even extending one pixel does not remove the problem completely but removes most noticable ones. A workaround would be to push the UV coordinates towards the center of the triangle when rasterizing to the screen (not the atlas).

  2. 256x256 versus 2048x2048 atlases close up of a bunny. There is aliasing of texture coordinates when the texture atlases becomes too small.


Problems

This section describes unintended results from bugs.

  1. There's a random white triangle on the bunny. All triangles are at least drawing 1 pixel, so I don't even know which one this should be.

  2. The borders of many triangles have the wrong color.

  3. Some atlased triangles stretch to the right due to incorrect interpolation, causing them to be drawn over other triangles.

Future Work

Code/Libraries

  1. Blender
  2. FreeImage Library
  3. 3DS Model Loader
  4. Irrlicht Engine - Quaternion code
  5. Quaternion camera rotations

Tutorials/Resources

  1. Spherical Texture Mapping
  2. Lapped Textures
  3. Blender Texture Baking Tutorial - helped generate a 3ds model with UV coordinates
  4. Wikipedia UV mapping - images used
  5. Renderbuffer/Framebuffer Objects