shadowMap.fragment.fx 836 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef FLOAT
  2. vec4 pack(float depth)
  3. {
  4. const vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);
  5. const vec4 bit_mask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);
  6. vec4 res = fract(depth * bit_shift);
  7. res -= res.xxyz * bit_mask;
  8. return res;
  9. }
  10. #endif
  11. varying float vDepthMetric;
  12. #ifdef ALPHATEST
  13. varying vec2 vUV;
  14. uniform sampler2D diffuseSampler;
  15. #endif
  16. uniform vec3 biasAndScale;
  17. uniform vec2 depthValues;
  18. void main(void)
  19. {
  20. #ifdef ALPHATEST
  21. if (texture2D(diffuseSampler, vUV).a < 0.4)
  22. discard;
  23. #endif
  24. float depth = vDepthMetric;
  25. #ifdef ESM
  26. depth = clamp(exp(-min(87., biasAndScale.z * depth)), 0., 1.);
  27. #endif
  28. #ifdef FLOAT
  29. gl_FragColor = vec4(depth, 1.0, 1.0, 1.0);
  30. #else
  31. gl_FragColor = pack(depth);
  32. #endif
  33. }