State orthonormalization policy for input normals and tangents
This issue was highlighted by Arnon Marcus in a Slack discussion:
I have a question about tangent vs normal inputs. For each pair (coat or geometry), is it expected that they are always provided already perpendicular to each over? If not, is the normal expected to be the "primary" one and the tangent is expected to be realigned to the normal internally by the material? What is the exact expectation there?
In my view, I agree that we should really explain in the specification how the supplied shading normal N and anisotropy tangent T are supposed to be made consistent, if they are not orthogonal.
In detail, I would propose we assume in general the shader is supplied
- The final bumped/perturbed shading normal $N'$.
- The desired tangent vector defining the specular reflection anisotropy, say $T'$.
- (These will usually be based on some reference normal $N$ and reference tangent $T$, via normal and flow mapping, but the shader does not necessarily have direct access to those).
Then we state that we do not assume that the supplied $N'$ and $T'$ are necessarily orthonormal, but if they are not, the shader should make $T'$ orthonormal to $N'$, by projecting
T' \rightarrow T' - (N'\cdot T') N'
and renormalizing.
Then the proejcted $T'$ used for anisotropy lies in the local $xy$-plane, which makes sense for the microfacet theory we discuss.
One point to make though is that the proposed projection of $T'$ onto the $N'$ plane alters the tangent vector field away from original $T'$, which presumably was designed to lie in the plane normal to the $N$ before bump mapping was applied (giving the flow map before bumping the geometry).
Of course if $T'$ was carefully authored to follow the bumped surface not the original geometry, it would already be orthogonal to $N'$. (Maybe tools that allow users to paint flow maps via vector fields do account for bump, but I guess the bump map could always get changed).
It's not necessarily obvious that the direct projection onto the $N'$ plane is the best choice of $T'$ direction in the plane (it seems a reasonable interpretation though). It at least preserves the continuity of curves defined relative to the $T$ frame, if not the derivative.