Zebrafish
Zebrafish

Reputation: 14252

How are normals and tangents still orthogonal when they reach the pixel/fragment shader?

I intuitively thought that if you linearly interpolated from two orthogonal vectors to another two orthogonal vectors that the resulting two vectors would also be orthogonal to each other. I assumed that if you have basis axes X, Y, Z, and these are unit vectors orthogonal to each other, that you can interpolate through a rotation and the result will still be three orthogonal vectors. Apparently that's not case (question I asked on Mathematics Stack Exchange.

So my plan to average tangents and normals to create a smooth-looking was not possible. However I just thought, when the vertex shader sends values to the fragment/pixel shader they are given 'linearly interpolated' values, right? Meaning if I have normal and tangent vectors which are orthogonal, when they get to the fragment/pixel shader they are no longer orthogonal to each other, right? Isn't this a problem?

Upvotes: 0

Views: 318

Answers (1)

Spektre
Spektre

Reputation: 51873

  1. normals and tangents might not be orthogonal after interpolation

    that is because interpolation is interpolating position not angle. That means if you linearly interpolate position the angle usually changes non linearly. So in most cases your interpolated vectors does not correspond to each other anymore (except starting and ending value).

  2. smooth TBN

    that is possible but you need to ortogonalise the vectors again like:

    t = cross(b,n)
    b = cross(n,t)
    t=normalize(t);
    b=normalize(b);
    n=normalize(n);
    

    However in most cases the dis-orthogonality is not that bad and stuff works also without this step.

Upvotes: 1

Related Questions