normal.fragment.fx 1.9 KB

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