normal.fragment.fx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. precision highp float;
  2. // Constants
  3. uniform vec3 vEyePosition;
  4. uniform vec4 vDiffuseColor;
  5. // Input
  6. varying vec3 vPositionW;
  7. #ifdef NORMAL
  8. varying vec3 vNormalW;
  9. #endif
  10. #ifdef VERTEXCOLOR
  11. varying vec4 vColor;
  12. #endif
  13. // Helper functions
  14. #include<helperFunctions>
  15. // Lights
  16. #include<__decl__lightFragment>[0]
  17. #include<__decl__lightFragment>[1]
  18. #include<__decl__lightFragment>[2]
  19. #include<__decl__lightFragment>[3]
  20. #include<lightsFragmentFunctions>
  21. #include<shadowsFragmentFunctions>
  22. // Samplers
  23. #ifdef DIFFUSE
  24. varying vec2 vDiffuseUV;
  25. uniform sampler2D diffuseSampler;
  26. uniform vec2 vDiffuseInfos;
  27. #endif
  28. #include<clipPlaneFragmentDeclaration>
  29. // Fog
  30. #include<fogFragmentDeclaration>
  31. void main(void) {
  32. #include<clipPlaneFragment>
  33. vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
  34. // Base color
  35. vec4 baseColor = vec4(1., 1., 1., 1.);
  36. vec3 diffuseColor = vDiffuseColor.rgb;
  37. // Alpha
  38. float alpha = vDiffuseColor.a;
  39. #ifdef DIFFUSE
  40. baseColor = texture2D(diffuseSampler, vDiffuseUV);
  41. #ifdef ALPHATEST
  42. if (baseColor.a < 0.4)
  43. discard;
  44. #endif
  45. #include<depthPrePass>
  46. baseColor.rgb *= vDiffuseInfos.y;
  47. #endif
  48. #ifdef NORMAL
  49. baseColor = mix(baseColor, vec4(vNormalW, 1.0), 0.5);
  50. #endif
  51. #ifdef VERTEXCOLOR
  52. baseColor.rgb *= vColor.rgb;
  53. #endif
  54. // Normal
  55. #ifdef NORMAL
  56. vec3 normalW = normalize(vNormalW);
  57. #else
  58. vec3 normalW = vec3(1.0, 1.0, 1.0);
  59. #endif
  60. // Lighting
  61. vec3 diffuseBase = vec3(0., 0., 0.);
  62. lightingInfo info;
  63. float shadow = 1.;
  64. float glossiness = 0.;
  65. #include<lightFragment>[0]
  66. #include<lightFragment>[1]
  67. #include<lightFragment>[2]
  68. #include<lightFragment>[3]
  69. #ifdef VERTEXALPHA
  70. alpha *= vColor.a;
  71. #endif
  72. vec3 finalDiffuse = clamp(diffuseBase * diffuseColor, 0.0, 1.0) * baseColor.rgb;
  73. // Composition
  74. vec4 color = vec4(finalDiffuse, alpha);
  75. #include<fogFragment>
  76. gl_FragColor = color;
  77. }