triplanar.fragment.fx.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { Effect } from "babylonjs";
  2. let name = 'triplanarPixelShader';
  3. let shader = `precision highp float;
  4. uniform vec3 vEyePosition;
  5. uniform vec4 vDiffuseColor;
  6. #ifdef SPECULARTERM
  7. uniform vec4 vSpecularColor;
  8. #endif
  9. varying vec3 vPositionW;
  10. #ifdef VERTEXCOLOR
  11. varying vec4 vColor;
  12. #endif
  13. #include<helperFunctions>
  14. #include<__decl__lightFragment>[0..maxSimultaneousLights]
  15. #ifdef DIFFUSEX
  16. varying vec2 vTextureUVX;
  17. uniform sampler2D diffuseSamplerX;
  18. #ifdef BUMPX
  19. uniform sampler2D normalSamplerX;
  20. #endif
  21. #endif
  22. #ifdef DIFFUSEY
  23. varying vec2 vTextureUVY;
  24. uniform sampler2D diffuseSamplerY;
  25. #ifdef BUMPY
  26. uniform sampler2D normalSamplerY;
  27. #endif
  28. #endif
  29. #ifdef DIFFUSEZ
  30. varying vec2 vTextureUVZ;
  31. uniform sampler2D diffuseSamplerZ;
  32. #ifdef BUMPZ
  33. uniform sampler2D normalSamplerZ;
  34. #endif
  35. #endif
  36. #ifdef NORMAL
  37. varying mat3 tangentSpace;
  38. #endif
  39. #include<lightsFragmentFunctions>
  40. #include<shadowsFragmentFunctions>
  41. #include<clipPlaneFragmentDeclaration>
  42. #include<fogFragmentDeclaration>
  43. void main(void) {
  44. #include<clipPlaneFragment>
  45. vec3 viewDirectionW=normalize(vEyePosition-vPositionW);
  46. vec4 baseColor=vec4(0.,0.,0.,1.);
  47. vec3 diffuseColor=vDiffuseColor.rgb;
  48. float alpha=vDiffuseColor.a;
  49. #ifdef NORMAL
  50. vec3 normalW=tangentSpace[2];
  51. #else
  52. vec3 normalW=vec3(1.0,1.0,1.0);
  53. #endif
  54. vec4 baseNormal=vec4(0.0,0.0,0.0,1.0);
  55. normalW*=normalW;
  56. #ifdef DIFFUSEX
  57. baseColor+=texture2D(diffuseSamplerX,vTextureUVX)*normalW.x;
  58. #ifdef BUMPX
  59. baseNormal+=texture2D(normalSamplerX,vTextureUVX)*normalW.x;
  60. #endif
  61. #endif
  62. #ifdef DIFFUSEY
  63. baseColor+=texture2D(diffuseSamplerY,vTextureUVY)*normalW.y;
  64. #ifdef BUMPY
  65. baseNormal+=texture2D(normalSamplerY,vTextureUVY)*normalW.y;
  66. #endif
  67. #endif
  68. #ifdef DIFFUSEZ
  69. baseColor+=texture2D(diffuseSamplerZ,vTextureUVZ)*normalW.z;
  70. #ifdef BUMPZ
  71. baseNormal+=texture2D(normalSamplerZ,vTextureUVZ)*normalW.z;
  72. #endif
  73. #endif
  74. #ifdef NORMAL
  75. normalW=normalize((2.0*baseNormal.xyz-1.0)*tangentSpace);
  76. #endif
  77. #ifdef ALPHATEST
  78. if (baseColor.a<0.4)
  79. discard;
  80. #endif
  81. #include<depthPrePass>
  82. #ifdef VERTEXCOLOR
  83. baseColor.rgb*=vColor.rgb;
  84. #endif
  85. vec3 diffuseBase=vec3(0.,0.,0.);
  86. lightingInfo info;
  87. float shadow=1.;
  88. #ifdef SPECULARTERM
  89. float glossiness=vSpecularColor.a;
  90. vec3 specularBase=vec3(0.,0.,0.);
  91. vec3 specularColor=vSpecularColor.rgb;
  92. #else
  93. float glossiness=0.;
  94. #endif
  95. #include<lightFragment>[0..maxSimultaneousLights]
  96. #ifdef VERTEXALPHA
  97. alpha*=vColor.a;
  98. #endif
  99. #ifdef SPECULARTERM
  100. vec3 finalSpecular=specularBase*specularColor;
  101. #else
  102. vec3 finalSpecular=vec3(0.0);
  103. #endif
  104. vec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;
  105. vec4 color=vec4(finalDiffuse+finalSpecular,alpha);
  106. #include<fogFragment>
  107. gl_FragColor=color;
  108. }
  109. `;
  110. Effect.ShadersStore[name] = shader;
  111. export { shader, name };