resolve_raster.glsl 952 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* clang-format off */
  2. #[vertex]
  3. #version 450
  4. #VERSION_DEFINES
  5. layout(location = 0) out vec2 uv_interp;
  6. /* clang-format on */
  7. void main() {
  8. vec2 base_arr[3] = vec2[](vec2(-1.0, -1.0), vec2(-1.0, 3.0), vec2(3.0, -1.0));
  9. gl_Position = vec4(base_arr[gl_VertexIndex], 0.0, 1.0);
  10. uv_interp = clamp(gl_Position.xy, vec2(0.0, 0.0), vec2(1.0, 1.0)) * 2.0; // saturate(x) * 2.0
  11. }
  12. /* clang-format off */
  13. #[fragment]
  14. #version 450
  15. #VERSION_DEFINES
  16. layout(location = 0) in vec2 uv_interp;
  17. layout(set = 0, binding = 0) uniform sampler2DMS source_depth;
  18. layout(push_constant, std430) uniform Params {
  19. ivec2 pad;
  20. int sample_count;
  21. int pad2;
  22. }
  23. params;
  24. layout (location = 0) out float out_depth;
  25. void main() {
  26. ivec2 pos = ivec2(gl_FragCoord.xy);
  27. float depth_avg = 0.0;
  28. for (int i = 0; i < params.sample_count; i++) {
  29. depth_avg += texelFetch(source_depth, pos, i).r;
  30. }
  31. depth_avg /= float(params.sample_count);
  32. out_depth = depth_avg;
  33. }