three
Version:
JavaScript 3D library
47 lines (26 loc) • 1.02 kB
JavaScript
export default /* glsl */`
// Workaround for Adreno/Nexus5 not able able to do dFdx( vViewPosition ) ...
vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );
vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
vec3 normal = normalize( cross( fdx, fdy ) );
vec3 normal = normalize( vNormal );
normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
vec3 tangent = normalize( vTangent );
vec3 bitangent = normalize( vBitangent );
tangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
bitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
mat3 vTBN = mat3( tangent, bitangent, normal );
// non perturbed normal for clearcoat among others
vec3 geometryNormal = normal;
`;