canvas_shadow.glsl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* clang-format off */
  2. [vertex]
  3. #ifdef USE_GLES_OVER_GL
  4. #define lowp
  5. #define mediump
  6. #define highp
  7. #else
  8. precision highp float;
  9. precision highp int;
  10. #endif
  11. layout(location = 0) in highp vec3 vertex;
  12. uniform highp mat4 projection_matrix;
  13. /* clang-format on */
  14. uniform highp mat4 light_matrix;
  15. uniform highp mat4 model_matrix;
  16. uniform highp float distance_norm;
  17. out highp vec4 position_interp;
  18. void main() {
  19. gl_Position = projection_matrix * (light_matrix * (model_matrix * vec4(vertex, 1.0)));
  20. position_interp = gl_Position;
  21. }
  22. /* clang-format off */
  23. [fragment]
  24. #ifdef USE_GLES_OVER_GL
  25. #define lowp
  26. #define mediump
  27. #define highp
  28. #else
  29. #if defined(USE_HIGHP_PRECISION)
  30. precision highp float;
  31. precision highp int;
  32. #else
  33. precision mediump float;
  34. precision mediump int;
  35. #endif
  36. #endif
  37. in highp vec4 position_interp;
  38. /* clang-format on */
  39. void main() {
  40. highp float depth = ((position_interp.z / position_interp.w) + 1.0) * 0.5 + 0.0; // bias
  41. #ifdef USE_RGBA_SHADOWS
  42. highp vec4 comp = fract(depth * vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0));
  43. comp -= comp.xxyz * vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);
  44. frag_color = comp;
  45. #else
  46. frag_color = vec4(depth);
  47. #endif
  48. }