normal_fragment_maps.glsl.js 779 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. export default /* glsl */`
  2. #ifdef OBJECTSPACE_NORMALMAP
  3. normal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0; // overrides both flatShading and attribute normals
  4. #ifdef FLIP_SIDED
  5. normal = - normal;
  6. #endif
  7. #ifdef DOUBLE_SIDED
  8. normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
  9. #endif
  10. normal = normalize( normalMatrix * normal );
  11. #elif defined( TANGENTSPACE_NORMALMAP )
  12. vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
  13. mapN.xy *= normalScale;
  14. #ifdef USE_TANGENT
  15. mat3 vTBN = mat3( tangent, bitangent, normal );
  16. normal = normalize( vTBN * mapN );
  17. #else
  18. normal = perturbNormal2Arb( -vViewPosition, normal, mapN );
  19. #endif
  20. #elif defined( USE_BUMPMAP )
  21. normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );
  22. #endif
  23. `;