# CSC572 Final Project: Texture Atlas Synthesis

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:

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

• hold left - translates the camera up/down/left/right
• hold right - rotates the camera up/down/left/right
• hold right and left - translates the camera forward/backward

## Key Controls

• ESC - quit
• w - forward
• s - backward
• s - left
• d - right
• r - reorients camera (the quaternions can be buggy).
• e - toggles expanding triangles while rendering to the texture atlas. Unexpanded triangles removes white outlining but can cause some bleeding in from other triangles due to aliasing problems. Default is on.
• p - renders the texture on the box to the bunny. This is saved as a texture atlas in outfileXXXX.bmp.
• t - changes the selected texture on the box.
• y - changes the selected texture atlas to render to (bunny texture). Every atlas has a different resolution.
• u - toggles between texture atlasing and spherical coordinates.

## 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

• Fix problems above.
• Extend to different models/textures.
• Try different generic UV mappings besides spherical coordinates.
• Allow for user control in mappings.
• Generate atlas using texture patching (lapped textures).