canvas_occlusion.glsl 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #[vertex]
  2. #version 450
  3. #VERSION_DEFINES
  4. layout(location = 0) in highp vec3 vertex;
  5. layout(push_constant, std430) uniform Constants {
  6. mat4 projection;
  7. mat2x4 modelview;
  8. vec2 direction;
  9. float z_far;
  10. float pad;
  11. }
  12. constants;
  13. #ifdef MODE_SHADOW
  14. layout(location = 0) out highp float depth;
  15. #endif
  16. void main() {
  17. highp vec4 vtx = vec4(vertex, 1.0) * mat4(constants.modelview[0], constants.modelview[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));
  18. #ifdef MODE_SHADOW
  19. depth = dot(constants.direction, vtx.xy);
  20. #endif
  21. gl_Position = constants.projection * vtx;
  22. }
  23. #[fragment]
  24. #version 450
  25. #VERSION_DEFINES
  26. layout(push_constant, std430) uniform Constants {
  27. mat4 projection;
  28. mat2x4 modelview;
  29. vec2 direction;
  30. float z_far;
  31. float pad;
  32. }
  33. constants;
  34. #ifdef MODE_SHADOW
  35. layout(location = 0) in highp float depth;
  36. layout(location = 0) out highp float distance_buf;
  37. #else
  38. layout(location = 0) out highp float sdf_buf;
  39. #endif
  40. void main() {
  41. #ifdef MODE_SHADOW
  42. distance_buf = depth / constants.z_far;
  43. #else
  44. sdf_buf = 1.0;
  45. #endif
  46. }