DepthDownscaleRaster.ankiprog 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma anki mutator REDUCTION_SAMPLER 0 1
  6. #pragma anki start vert
  7. #include <AnKi/Shaders/QuadVert.glsl>
  8. #pragma anki end
  9. #pragma anki start frag
  10. #include <AnKi/Shaders/Common.glsl>
  11. layout(location = 0) in Vec2 in_uv;
  12. layout(location = 0) out F32 out_depth;
  13. layout(set = 0, binding = 0) uniform texture2D u_inputTex;
  14. layout(set = 0, binding = 1) uniform sampler u_sampler;
  15. layout(std430, set = 0, binding = 2) writeonly buffer b_cb
  16. {
  17. F32 u_clientBuf[];
  18. };
  19. layout(push_constant, std140) uniform b_pc
  20. {
  21. Vec3 u_padding;
  22. U32 u_lastMipWidth;
  23. };
  24. void main()
  25. {
  26. #if !REDUCTION_SAMPLER
  27. out_depth = textureLod(u_inputTex, u_sampler, in_uv, 0.0).x;
  28. #else
  29. const Vec4 depths = textureGather(sampler2D(u_inputTex, u_sampler), in_uv, 0);
  30. out_depth = max(depths.x, max(depths.y, max(depths.z, depths.w)));
  31. #endif
  32. if(u_lastMipWidth != 0u)
  33. {
  34. const UVec2 p = UVec2(gl_FragCoord.xy);
  35. const U32 idx = p.y * u_lastMipWidth + p.x;
  36. u_clientBuf[idx] = out_depth;
  37. }
  38. }
  39. #pragma anki end