triplanar.fragment.fx 2.9 KB

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