normal_fragment_begin.glsl.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. export default /* glsl */`
  2. float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
  3. #ifdef FLAT_SHADED
  4. vec3 fdx = dFdx( vViewPosition );
  5. vec3 fdy = dFdy( vViewPosition );
  6. vec3 normal = normalize( cross( fdx, fdy ) );
  7. #else
  8. vec3 normal = normalize( vNormal );
  9. #ifdef DOUBLE_SIDED
  10. normal *= faceDirection;
  11. #endif
  12. #endif
  13. #ifdef USE_NORMALMAP_TANGENTSPACE
  14. #ifdef USE_TANGENT
  15. mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
  16. #else
  17. mat3 tbn = getTangentFrame( - vViewPosition, normal, vNormalMapUv );
  18. #endif
  19. #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
  20. tbn[0] *= faceDirection;
  21. tbn[1] *= faceDirection;
  22. #endif
  23. #endif
  24. #ifdef USE_CLEARCOAT_NORMALMAP
  25. #ifdef USE_TANGENT
  26. mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
  27. #else
  28. mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );
  29. #endif
  30. #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
  31. tbn2[0] *= faceDirection;
  32. tbn2[1] *= faceDirection;
  33. #endif
  34. #endif
  35. // non perturbed normal for clearcoat among others
  36. vec3 geometryNormal = normal;
  37. `;