canvas_shadow.glsl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. attribute highp vec3 vertex; // attrib:0
  12. uniform highp mat4 projection_matrix;
  13. /* clang-format on */
  14. uniform highp mat4 light_matrix;
  15. uniform highp mat4 world_matrix;
  16. uniform highp float distance_norm;
  17. varying highp vec4 position_interp;
  18. void main() {
  19. gl_Position = projection_matrix * (light_matrix * (world_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. precision mediump float;
  30. precision mediump int;
  31. #endif
  32. varying highp vec4 position_interp;
  33. /* clang-format on */
  34. void main() {
  35. highp float depth = ((position_interp.z / position_interp.w) + 1.0) * 0.5 + 0.0; // bias
  36. #ifdef USE_RGBA_SHADOWS
  37. highp vec4 comp = fract(depth * vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0));
  38. comp -= comp.xxyz * vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
  39. gl_FragColor = comp;
  40. #else
  41. gl_FragColor = vec4(depth);
  42. #endif
  43. }