DepthDownscale.ankiprog 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!--
  2. Copyright (C) 2009-2017, 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="TO_COLOR_RT" values="0 1"/>
  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/Quad.vert.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. #if TO_COLOR_RT
  27. layout(location = 0) out float out_color;
  28. # define out_depth out_color
  29. #else
  30. # define out_depth gl_FragDepth
  31. #endif
  32. void main()
  33. {
  34. vec4 depths = textureGather(u_depthRt, in_uv, 0);
  35. #if SAMPLE_RESOLVE_TYPE == MIN
  36. vec2 mind2 = min(depths.xy, depths.zw);
  37. out_depth = min(mind2.x, mind2.y);
  38. #elif SAMPLE_RESOLVE_TYPE == MAX
  39. vec2 max2 = max(depths.xy, depths.zw);
  40. out_depth = max(max2.x, max2.y);
  41. #elif SAMPLE_RESOLVE_TYPE == AVG
  42. out_depth = dot(depths, vec4(1.0 / 4.0));
  43. #else
  44. # error See file
  45. #endif
  46. }
  47. ]]></source>
  48. </shader>
  49. </shaders>
  50. </shaderProgram>