The vertex shader starts by transforming the vertex normal and the tangent vectors into eye coordinates by multiplying by the normal matrix (and renormalizing). The binormal vector is then computed as the cross product of the normal and tangent vectors. The result is multiplied by the w coordinate of the vertex tangent vector, which determines the handedness of the tangent space coordinate system. Its value will be either -1 or +1.
Next, we create the transformation matrix used to convert from eye coordinates to tangent space and store the matrix in toObjectLocal. The position is converted to eye space and stored in pos, and we compute the light direction by subtracting pos from the light position. The result is multiplied ...