### [[Function|Transformation]] to TBN Space:
Assumptions: We have a surface $P \subset \R^{3}$ with verticies $P(x,y,z)\in P$, as well as [[Texture Coordinates]] $\vec T(u,v)$.
The $\vec N$ [[Vector|vector]] will align with the $z$-axis in [[Object Space]] after the transformation.
Given a [[Triangle]] $\triangle P_{0}P_{1}P_{2} \in P$.
$
\huge \begin{matrix}
P_{0}=\mat{x_{0}\\ y_{0}\\ z_{0}}&
P_{1}=\mat{x_{1}\\ y_{1}\\ z_{1}}&
P_{2}=\mat{x_{2}\\ y_{2}\\ z_{2}}&\\ \\
T_{0}=\mat{u_{0}\\v_{0}}&
T_{1}=\mat{u_{1}\\v_{1}}&
T_{2}=\mat{u_{2}\\v_{2}}&
\end{matrix}
$
We can define these vectors relating to the edges of the triangle
$\huge \begin{align}
\vec T_{01} = \mat{u_{01}\\v_{01}} &= P_{1} - P_{0} \\
\vec T_{02} = \mat{u_{02}\\v_{02}} &= P_{2} - P_{0} \\
\end{align} $
$\huge \begin{align}
P_{1} &= P_{0} + u_{01}\vec T + v_{01} \vec \beta \\
P_{2} &= P_{0} + u_{02}\vec T + v_{02} \vec \beta \\
\vec P_{01} &= u_{01}\vec T + \vec v_{01}\vec \beta\\
\vec P_{02} &= u_{02}\vec T + \vec v_{02}\vec \beta
\end{align}$
This can be broken into this [[System of Linear Equations]]:
$\begin{align}
x_{01} &= u_{01}T_{x} + v_{01} \beta_{x}\\
y_{01} &= u_{01}T_{y} + v_{01} \beta_{y}\\
z_{01} &= u_{01}T_{z} + v_{01} \beta_{z}\\
x_{02} &= u_{02}T_{x} + v_{02} \beta_{x}\\
y_{02} &= u_{02}T_{y} + v_{02} \beta_{y}\\
z_{02} &= u_{02}T_{z} + v_{02} \beta_{z}\\
\end{align}$
$\huge \begin{align}
\mat{
x_{01} & y_{01} & z_{01}\\
x_{02} & y_{02} & z_{02}\\
} &=
\mat{ u_{01} & v_{01} \\ u_{02} & v_{02}}
\mat{
T_{x} & T_{y} & T_{z} \\
\beta_{x} & \beta_{y} & \beta_{z}
}\\
\mat{
\vec P_{01}^{\intercal} \\
\vec P_{02}^{\intercal}
} &=
\mat{ \vec T_{01}^{\intercal} \\ \vec T_{02}^{\intercal}}
\mat{
T^{\intercal} \\
\beta^{\intercal}
}
\end{align}$
You can than solve for $T$ and $\beta$ by finding the inverse to $\mat{ \vec T_{01}^{\intercal} \\ \vec T_{02}^{\intercal}}$.
The [[Function|Transformation]] [[Matrix]] from tangeant space to object space
$ \huge \begin{align}
\mathcal C_{O\to \mathrm{TBN}} &= \mat{ \vec T & \vec \beta & \vec N}
\end{align} $
Object Space:
- Do lighting in object space
- Convert $L,V,H, \dots$ to object space per vertex
- Convert $N$ from TBN to object space per [[Pixel]]
Tangent Space: