DepthDownscale.ankiprog 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. </mutators>
  12. <shaders>
  13. <shader type="vert">
  14. <source><![CDATA[
  15. #include "shaders/QuadVert.glsl"
  16. ]]></source>
  17. </shader>
  18. <shader type="frag">
  19. <source><![CDATA[
  20. #include "shaders/Common.glsl"
  21. #define AVG 0
  22. #define MIN 1
  23. #define MAX 2
  24. layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthRt;
  25. layout(location = 0) in vec2 in_uv;
  26. layout(location = 0) out float out_color;
  27. void main()
  28. {
  29. vec4 depths = textureGather(u_depthRt, in_uv, 0);
  30. #if SAMPLE_RESOLVE_TYPE == MIN
  31. vec2 mind2 = min(depths.xy, depths.zw);
  32. out_color = min(mind2.x, mind2.y);
  33. #elif SAMPLE_RESOLVE_TYPE == MAX
  34. vec2 max2 = max(depths.xy, depths.zw);
  35. out_color = max(max2.x, max2.y);
  36. #elif SAMPLE_RESOLVE_TYPE == AVG
  37. out_color = dot(depths, vec4(1.0 / 4.0));
  38. #else
  39. # error See file
  40. #endif
  41. #if TYPE == 0
  42. gl_FragDepth = out_color;
  43. #endif
  44. }
  45. ]]></source>
  46. </shader>
  47. </shaders>
  48. </shaderProgram>