2
0

TransparentAlphaChannelRef.fsh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #version 100
  2. precision mediump float;
  3. /* Uniforms */
  4. uniform float uAlphaRef;
  5. uniform int uTextureUsage0;
  6. uniform sampler2D uTextureUnit0;
  7. uniform int uFogEnable;
  8. uniform int uFogType;
  9. uniform vec4 uFogColor;
  10. uniform float uFogStart;
  11. uniform float uFogEnd;
  12. uniform float uFogDensity;
  13. /* Varyings */
  14. varying vec2 vTextureCoord0;
  15. varying vec4 vVertexColor;
  16. varying float vFogCoord;
  17. float computeFog()
  18. {
  19. const float LOG2 = 1.442695;
  20. float FogFactor = 0.0;
  21. if (uFogType == 0) // Exp
  22. {
  23. FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
  24. }
  25. else if (uFogType == 1) // Linear
  26. {
  27. float Scale = 1.0 / (uFogEnd - uFogStart);
  28. FogFactor = (uFogEnd - vFogCoord) * Scale;
  29. }
  30. else if (uFogType == 2) // Exp2
  31. {
  32. FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
  33. }
  34. FogFactor = clamp(FogFactor, 0.0, 1.0);
  35. return FogFactor;
  36. }
  37. void main()
  38. {
  39. vec4 Color = vVertexColor;
  40. if (bool(uTextureUsage0))
  41. Color *= texture2D(uTextureUnit0, vTextureCoord0);
  42. if (Color.a < uAlphaRef)
  43. discard;
  44. if (bool(uFogEnable))
  45. {
  46. float FogFactor = computeFog();
  47. vec4 FogColor = uFogColor;
  48. FogColor.a = 1.0;
  49. Color = mix(FogColor, Color, FogFactor);
  50. }
  51. gl_FragColor = Color;
  52. }