three
Version:
JavaScript 3D library
47 lines (26 loc) • 794 B
JavaScript
export default /* glsl */`
float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
vec3 fdx = dFdx( vViewPosition );
vec3 fdy = dFdy( vViewPosition );
vec3 normal = normalize( cross( fdx, fdy ) );
vec3 normal = normalize( vNormal );
normal = normal * faceDirection;
vec3 tangent = normalize( vTangent );
vec3 bitangent = normalize( vBitangent );
tangent = tangent * faceDirection;
bitangent = bitangent * faceDirection;
mat3 vTBN = mat3( tangent, bitangent, normal );
// non perturbed normal for clearcoat among others
vec3 geometryNormal = normal;
`;