# Least-Squares Estimation of Tangent Space for a Triangular Mesh
## 1 Introduction  
Texture mapping is ubiquitous in computer graphics applications, including computer games, computer animations, and feature films. In particular, normal mapping is widely used to enhance geometric details significantly while keeping a relatively low polygon count. It perturbs the normal vector at each surface point based on a normal map defined in planar texture space. When applying normal mapping to a curved surface, the perturbation in the planar surface must be mapped onto the curved surface. To achieve this, a tangent space is required at each surface point, defined by three mutually orthogonal vectors: a tangent vector, a bitangent vector, and a normal vector. These vectors correspond to the \(u\)- and \(v\)-axes of texture space and the out-of-plane \(w\)-axis, respectively. Together, they form a local coordinate frame known as the TBN (Tangent, Bitangent, Normal) coordinate frame at the surface point.  
In highly detailed models found in recent computer games, a normal map is typically created either during the model development phase or by baking data from a high-resolution model while reducing polygonal complexity. This process involves storing per-vertex tangent space information for per-pixel shading or constructing per-vertex tangent spaces consistently from the texture coordinates during both the normal map generation and application phases [1; 2; 3; 4]. Subsequently, modern computer graphics pipelines facilitate the efficient computation of tangent spaces at surface points by utilizing per-pixel linear interpolation from per-vertex data.  
A straightforward and commonly used approach to obtaining a tangent space for a vertex from texture coordinates is to estimate the tangent spaces of the triangles sharing the vertex through linear mapping of the texture coordinates [2; 3; 5; 6; 7]. These estimated tangent spaces are then averaged to generate a tangent space at the vertex, which can be further orthonormalized. This approach relies on the assumption that the tangent spaces of adjacent triangles and vertices are similar. However, it does require somewhat intricate operations, such as averaging and orthonormalization. Nevertheless, it is widelyused and effective when applied consistently during both the normal map generation and application phases.  
In this paper, we develop a novel method for computing the per-vertex tangent spaces of a triangular mesh in a rigorous way, ensuring that the resulting tangent spaces are inherently orthonormal without requiring intricate operations. Our method employs least-squares estimation of rotation between two sets of corresponding points [8; 9; 10; 11]. One set is from the 1-ring neighbors of a vertex in texture space, and the other set is from the corresponding vertices in world space. Thus, our method directly computes the per-vertex tangent space and does not necessitate further orthonormalization because the optimal rotation itself corresponds to the orthonormal tangent space.  
We also introduce a novel approach to address seams, which are inevitable in texture mapping to a closed surface mesh. A vertex on a seam has other duplicates at the same spatial position but with distinct texture coordinates, leading to the independent computation of the tangent space without special consideration. In contrast to previous methods [2; 3; 5; 6; 7] that average similar tangent spaces only, our method employs a rigid transformation in texture space for each set of triangles adjacent to each duplicated vertex to align both sides of every seam as closely as possible. The vertices aligned in this manner within texture space are then used to estimate the optimal rotation for the corresponding vertices in world space. This texture space alignment can also be utilized to average tangent spaces in the previous methods.