bumpFragment.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Do not edit.
  2. import { ShaderStore } from "../../Engines/shaderStore.js";
  3. const name = "bumpFragment";
  4. const shader = `vec2 uvOffset=vec2(0.0,0.0);
  5. #if defined(BUMP) || defined(PARALLAX) || defined(DETAIL)
  6. #ifdef NORMALXYSCALE
  7. float normalScale=1.0;
  8. #elif defined(BUMP)
  9. float normalScale=vBumpInfos.y;
  10. #else
  11. float normalScale=1.0;
  12. #endif
  13. #if defined(TANGENT) && defined(NORMAL)
  14. mat3 TBN=vTBN;
  15. #elif defined(BUMP)
  16. vec2 TBNUV=gl_FrontFacing ? vBumpUV : -vBumpUV;mat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vTangentSpaceParams);
  17. #else
  18. vec2 TBNUV=gl_FrontFacing ? vDetailUV : -vDetailUV;mat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vec2(1.,1.));
  19. #endif
  20. #elif defined(ANISOTROPIC)
  21. #if defined(TANGENT) && defined(NORMAL)
  22. mat3 TBN=vTBN;
  23. #else
  24. vec2 TBNUV=gl_FrontFacing ? vMainUV1 : -vMainUV1;mat3 TBN=cotangent_frame(normalW,vPositionW,TBNUV,vec2(1.,1.));
  25. #endif
  26. #endif
  27. #ifdef PARALLAX
  28. mat3 invTBN=transposeMat3(TBN);
  29. #ifdef PARALLAXOCCLUSION
  30. uvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);
  31. #else
  32. uvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);
  33. #endif
  34. #endif
  35. #ifdef DETAIL
  36. vec4 detailColor=texture2D(detailSampler,vDetailUV+uvOffset);vec2 detailNormalRG=detailColor.wy*2.0-1.0;float detailNormalB=sqrt(1.-saturate(dot(detailNormalRG,detailNormalRG)));vec3 detailNormal=vec3(detailNormalRG,detailNormalB);
  37. #endif
  38. #ifdef BUMP
  39. #ifdef OBJECTSPACE_NORMALMAP
  40. #define CUSTOM_FRAGMENT_BUMP_FRAGMENT
  41. normalW=normalize(texture2D(bumpSampler,vBumpUV).xyz *2.0-1.0);normalW=normalize(mat3(normalMatrix)*normalW);
  42. #elif !defined(DETAIL)
  43. normalW=perturbNormal(TBN,texture2D(bumpSampler,vBumpUV+uvOffset).xyz,vBumpInfos.y);
  44. #else
  45. vec3 bumpNormal=texture2D(bumpSampler,vBumpUV+uvOffset).xyz*2.0-1.0;
  46. #if DETAIL_NORMALBLENDMETHOD==0
  47. detailNormal.xy*=vDetailInfos.z;vec3 blendedNormal=normalize(vec3(bumpNormal.xy+detailNormal.xy,bumpNormal.z*detailNormal.z));
  48. #elif DETAIL_NORMALBLENDMETHOD==1
  49. detailNormal.xy*=vDetailInfos.z;bumpNormal+=vec3(0.0,0.0,1.0);detailNormal*=vec3(-1.0,-1.0,1.0);vec3 blendedNormal=bumpNormal*dot(bumpNormal,detailNormal)/bumpNormal.z-detailNormal;
  50. #endif
  51. normalW=perturbNormalBase(TBN,blendedNormal,vBumpInfos.y);
  52. #endif
  53. #elif defined(DETAIL)
  54. detailNormal.xy*=vDetailInfos.z;normalW=perturbNormalBase(TBN,detailNormal,vDetailInfos.z);
  55. #endif
  56. `;
  57. // Sideeffect
  58. ShaderStore.IncludesShadersStore[name] = shader;
  59. /** @internal */
  60. export const bumpFragment = { name, shader };
  61. //# sourceMappingURL=bumpFragment.js.map