simple.fragment.fx 1.6 KB

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