FinalComposite.ankiprog 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 BLUE_NOISE 0 1
  6. #pragma anki mutator BLOOM_ENABLED 0 1
  7. #pragma anki mutator DBG_ENABLED 0 1
  8. ANKI_SPECIALIZATION_CONSTANT_U32(LUT_SIZE, 0u);
  9. ANKI_SPECIALIZATION_CONSTANT_UVEC2(FB_SIZE, 1u);
  10. ANKI_SPECIALIZATION_CONSTANT_U32(MOTION_BLUR_SAMPLES, 3u);
  11. #pragma anki start vert
  12. #include <AnKi/Shaders/QuadVert.glsl>
  13. #pragma anki end
  14. #pragma anki start frag
  15. #include <AnKi/Shaders/Common.glsl>
  16. #include <AnKi/Shaders/Functions.glsl>
  17. #include <AnKi/Shaders/MotionBlur.glsl>
  18. layout(set = 0, binding = 0) uniform sampler u_nearestAnyClampSampler;
  19. layout(set = 0, binding = 1) uniform sampler u_linearAnyClampSampler;
  20. layout(set = 0, binding = 2) uniform sampler u_trilinearRepeatSampler;
  21. layout(set = 0, binding = 3) uniform ANKI_RP texture2D u_lightShadingRt;
  22. layout(set = 0, binding = 4) uniform ANKI_RP texture2D u_ppsBloomLfRt;
  23. layout(set = 0, binding = 5) uniform ANKI_RP texture3D u_lut;
  24. layout(set = 0, binding = 6) uniform ANKI_RP texture2D u_blueNoise;
  25. layout(set = 0, binding = 7) uniform texture2D u_motionVectorsRt;
  26. layout(set = 0, binding = 8) uniform texture2D u_depthRt;
  27. #if DBG_ENABLED
  28. layout(set = 0, binding = 9) uniform ANKI_RP texture2D u_dbgOutlineRt;
  29. #endif
  30. layout(push_constant, std140) uniform b_pc
  31. {
  32. Vec3 u_padding0;
  33. U32 u_frameCount;
  34. };
  35. layout(location = 0) in Vec2 in_uv;
  36. layout(location = 0) out ANKI_RP Vec3 out_color;
  37. ANKI_RP Vec3 colorGrading(ANKI_RP Vec3 color)
  38. {
  39. const ANKI_RP Vec3 LUT_SCALE = Vec3((F32(LUT_SIZE) - 1.0) / F32(LUT_SIZE));
  40. const ANKI_RP Vec3 LUT_OFFSET = Vec3(1.0 / (2.0 * F32(LUT_SIZE)));
  41. color = min(color, Vec3(1.0));
  42. const ANKI_RP Vec3 lutCoords = color * LUT_SCALE + LUT_OFFSET;
  43. return textureLod(u_lut, u_trilinearRepeatSampler, lutCoords, 0.0).rgb;
  44. }
  45. void main()
  46. {
  47. const Vec2 uv = in_uv;
  48. if(MOTION_BLUR_SAMPLES > 0u)
  49. {
  50. out_color = motionBlur(u_motionVectorsRt, u_nearestAnyClampSampler, u_lightShadingRt, Vec2(FB_SIZE),
  51. u_linearAnyClampSampler, uv, MOTION_BLUR_SAMPLES);
  52. }
  53. else
  54. {
  55. out_color = textureLod(u_lightShadingRt, u_linearAnyClampSampler, uv, 0.0).rgb;
  56. }
  57. #if BLOOM_ENABLED
  58. const ANKI_RP Vec3 bloom = textureLod(u_ppsBloomLfRt, u_linearAnyClampSampler, uv, 0.0).rgb;
  59. out_color += bloom;
  60. #endif
  61. out_color = colorGrading(out_color);
  62. #if BLUE_NOISE
  63. const Vec2 bnUvw = Vec2(FB_SIZE) / Vec2(64.0) * uv;
  64. ANKI_RP Vec3 blueNoise = textureLod(u_blueNoise, u_trilinearRepeatSampler, bnUvw, 0.0).rgb;
  65. blueNoise = animateBlueNoise(blueNoise, u_frameCount);
  66. blueNoise = blueNoise * 2.0 - 1.0;
  67. blueNoise = sign(blueNoise) * (1.0 - sqrt(1.0 - abs(blueNoise)));
  68. out_color += blueNoise / 255.0;
  69. #endif
  70. #if DBG_ENABLED
  71. const ANKI_RP Vec4 dbg = textureLod(u_dbgOutlineRt, u_linearAnyClampSampler, uv, 0.0);
  72. out_color = mix(out_color, dbg.rgb, dbg.a);
  73. #endif
  74. }
  75. #pragma anki end