canvas_shadow.glsl 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* clang-format off */
  2. [vertex]
  3. uniform highp mat4 projection_matrix;
  4. /* clang-format on */
  5. uniform highp mat4 light_matrix;
  6. uniform highp mat4 world_matrix;
  7. uniform highp float distance_norm;
  8. layout(location = 0) in highp vec3 vertex;
  9. out highp vec4 position_interp;
  10. void main() {
  11. gl_Position = projection_matrix * (light_matrix * (world_matrix * vec4(vertex, 1.0)));
  12. position_interp = gl_Position;
  13. }
  14. /* clang-format off */
  15. [fragment]
  16. in highp vec4 position_interp;
  17. /* clang-format on */
  18. #ifdef USE_RGBA_SHADOWS
  19. layout(location = 0) out lowp vec4 distance_buf;
  20. #else
  21. layout(location = 0) out highp float distance_buf;
  22. #endif
  23. void main() {
  24. highp float depth = ((position_interp.z / position_interp.w) + 1.0) * 0.5 + 0.0; // bias
  25. #ifdef USE_RGBA_SHADOWS
  26. highp vec4 comp = fract(depth * vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0));
  27. comp -= comp.xxyz * vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
  28. distance_buf = comp;
  29. #else
  30. distance_buf = depth;
  31. #endif
  32. }