DepthDownscale.ankiprog 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <!--
  2. Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
  3. All rights reserved.
  4. Code licensed under the BSD License.
  5. http://www.anki3d.org/LICENSE
  6. -->
  7. <shaderProgram>
  8. <mutators>
  9. <mutator name="TYPE" values="0 1"/> <!-- 0: write to depth&color, 1: write to depth -->
  10. <mutator name="SAMPLE_RESOLVE_TYPE" values="0 1 2"/> <!-- 0: average, 1: min, 2: max -->
  11. <mutator name="COPY_TO_CLIENT" values="0 1"/>
  12. </mutators>
  13. <shaders>
  14. <shader type="vert">
  15. <source><![CDATA[
  16. #include "shaders/QuadVert.glsl"
  17. ]]></source>
  18. </shader>
  19. <shader type="frag">
  20. <source><![CDATA[
  21. #include "shaders/Common.glsl"
  22. #define AVG 0
  23. #define MIN 1
  24. #define MAX 2
  25. #if COPY_TO_CLIENT
  26. struct PushConsts
  27. {
  28. uvec4 textureSize;
  29. };
  30. ANKI_PUSH_CONSTANTS(PushConsts, u_regs);
  31. layout(std430, ANKI_SS_BINDING(0, 0)) writeonly buffer s1_
  32. {
  33. float u_clientBuf[];
  34. };
  35. #endif
  36. layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthRt;
  37. layout(location = 0) in vec2 in_uv;
  38. layout(location = 0) out float out_color;
  39. void main()
  40. {
  41. vec4 depths = textureGather(u_depthRt, in_uv, 0);
  42. #if SAMPLE_RESOLVE_TYPE == MIN
  43. vec2 mind2 = min(depths.xy, depths.zw);
  44. out_color = min(mind2.x, mind2.y);
  45. #elif SAMPLE_RESOLVE_TYPE == MAX
  46. vec2 max2 = max(depths.xy, depths.zw);
  47. out_color = max(max2.x, max2.y);
  48. #elif SAMPLE_RESOLVE_TYPE == AVG
  49. out_color = dot(depths, vec4(1.0 / 4.0));
  50. #else
  51. # error See file
  52. #endif
  53. #if TYPE == 0
  54. gl_FragDepth = out_color;
  55. #endif
  56. #if COPY_TO_CLIENT
  57. u_clientBuf[uint(gl_FragCoord.y) * u_regs.textureSize.x + uint(gl_FragCoord.x)] = out_color;
  58. #endif
  59. }
  60. ]]></source>
  61. </shader>
  62. </shaders>
  63. </shaderProgram>