simple.fragment.fx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. // Lights
  14. #include<light0FragmentDeclaration>
  15. #include<light1FragmentDeclaration>
  16. #include<light2FragmentDeclaration>
  17. #include<light3FragmentDeclaration>
  18. #include<lightsFragmentFunctions>
  19. #include<shadowsFragmentFunctions>
  20. // Samplers
  21. #ifdef DIFFUSE
  22. varying vec2 vDiffuseUV;
  23. uniform sampler2D diffuseSampler;
  24. uniform vec2 vDiffuseInfos;
  25. #endif
  26. #include<clipPlaneFragmentDeclaration>
  27. // Fog
  28. #include<fogFragmentDeclaration>
  29. void main(void) {
  30. #include<clipPlaneFragment>
  31. vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
  32. // Base color
  33. vec4 baseColor = vec4(1., 1., 1., 1.);
  34. vec3 diffuseColor = vDiffuseColor.rgb;
  35. // Alpha
  36. float alpha = vDiffuseColor.a;
  37. #ifdef DIFFUSE
  38. baseColor = texture2D(diffuseSampler, vDiffuseUV);
  39. #ifdef ALPHATEST
  40. if (baseColor.a < 0.4)
  41. discard;
  42. #endif
  43. baseColor.rgb *= vDiffuseInfos.y;
  44. #endif
  45. #ifdef VERTEXCOLOR
  46. baseColor.rgb *= vColor.rgb;
  47. #endif
  48. // Normal
  49. #ifdef NORMAL
  50. vec3 normalW = normalize(vNormalW);
  51. #else
  52. vec3 normalW = vec3(1.0, 1.0, 1.0);
  53. #endif
  54. // Lighting
  55. vec3 diffuseBase = vec3(0., 0., 0.);
  56. float shadow = 1.;
  57. float glossiness = 0.;
  58. #include<light0Fragment>
  59. #include<light1Fragment>
  60. #include<light2Fragment>
  61. #include<light3Fragment>
  62. #ifdef VERTEXALPHA
  63. alpha *= vColor.a;
  64. #endif
  65. vec3 finalDiffuse = clamp(diffuseBase * diffuseColor, 0.0, 1.0) * baseColor.rgb;
  66. // Composition
  67. vec4 color = vec4(finalDiffuse, alpha);
  68. #include<fogFragment>
  69. gl_FragColor = color;
  70. }