triplanar.fragment.fx 2.9 KB

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