Skip to content

at_tangent

in vec4 at_tangent;

Valid Programs: gbuffers_*.vsh, shadow.vsh


The xyz components store an approximation of the current tangent vector in model space, and the sign of the w component the handedness of the normal/tangent.

The handedness should be used to invert the bitangent in cases where a texture is mirrored and the cross product of the normal and tangent vectors would produce an inverted bitangent vector. For example, in view space:

vec3 normal = normalMatrix * normalize(vaNormal);
vec3 tangent = normalMatrix * normalize(at_tangent.xyz);
vec3 normal = gl_NormalMatrix * normalize(gl_Normal);
vec3 tangent = gl_NormalMatrix * normalize(at_tangent.xyz);
const float inf = uintBitsToFloat(0x7f800000u);
float handedness = clamp(at_tangent.w * inf, -1.0, 1.0); // -1.0 when at_tangent.w is negative, and 1.0 when it's positive
vec3 bitangent = cross(tangent, normal) * handedness;