FinalComposite.ankiprog 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright (C) 2009-2021, 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/Tonemapping.glsl>
  17. #include <AnKi/Shaders/Functions.glsl>
  18. #include <AnKi/Shaders/MotionBlur.glsl>
  19. #define TONEMAPPING_BINDING 0
  20. #define TONEMAPPING_SET 0
  21. #include <AnKi/Shaders/TonemappingResources.glsl>
  22. layout(set = 0, binding = 1) uniform sampler u_nearestAnyClampSampler;
  23. layout(set = 0, binding = 2) uniform sampler u_linearAnyClampSampler;
  24. layout(set = 0, binding = 3) uniform sampler u_trilinearRepeatSampler;
  25. layout(set = 0, binding = 4) uniform texture2D u_lightShadingRt;
  26. layout(set = 0, binding = 5) uniform texture2D u_ppsBloomLfRt;
  27. layout(set = 0, binding = 6) uniform texture3D u_lut;
  28. layout(set = 0, binding = 7) uniform texture2D u_blueNoise;
  29. layout(set = 0, binding = 8) uniform texture2D u_motionVectorsRt;
  30. layout(set = 0, binding = 9) uniform texture2D u_depthRt;
  31. #if DBG_ENABLED
  32. layout(set = 0, binding = 10) uniform texture2D u_dbgOutlineRt;
  33. #endif
  34. layout(push_constant, row_major, std430) uniform pc_
  35. {
  36. UVec4 u_frameCountPad3;
  37. Mat4 u_prevViewProjMatMulInvViewProjMat;
  38. };
  39. layout(location = 0) in Vec2 in_uv;
  40. layout(location = 0) out Vec3 out_color;
  41. Vec3 colorGrading(Vec3 color)
  42. {
  43. const Vec3 LUT_SCALE = Vec3((F32(LUT_SIZE) - 1.0) / F32(LUT_SIZE));
  44. const Vec3 LUT_OFFSET = Vec3(1.0 / (2.0 * F32(LUT_SIZE)));
  45. color = min(color, Vec3(1.0));
  46. const Vec3 lutCoords = color * LUT_SCALE + LUT_OFFSET;
  47. return textureLod(u_lut, u_trilinearRepeatSampler, lutCoords, 0.0).rgb;
  48. }
  49. void main()
  50. {
  51. const Vec2 uv = in_uv.xy;
  52. if(MOTION_BLUR_SAMPLES > 0u)
  53. {
  54. out_color = motionBlur(u_motionVectorsRt, u_nearestAnyClampSampler, u_lightShadingRt, Vec2(FB_SIZE),
  55. u_linearAnyClampSampler, uv, MOTION_BLUR_SAMPLES);
  56. }
  57. else
  58. {
  59. out_color = textureLod(u_lightShadingRt, u_linearAnyClampSampler, uv, 0.0).rgb;
  60. }
  61. out_color = tonemap(out_color, u_exposureThreshold0);
  62. #if BLOOM_ENABLED
  63. const Vec3 bloom = textureLod(u_ppsBloomLfRt, u_linearAnyClampSampler, uv, 0.0).rgb;
  64. out_color += bloom;
  65. #endif
  66. out_color = colorGrading(out_color);
  67. #if BLUE_NOISE
  68. const Vec2 bnUvw = Vec2(FB_SIZE) / Vec2(64.0) * uv;
  69. Vec3 blueNoise = textureLod(u_blueNoise, u_trilinearRepeatSampler, bnUvw, 0.0).rgb;
  70. blueNoise = animateBlueNoise(blueNoise, u_frameCountPad3.x);
  71. blueNoise = blueNoise * 2.0 - 1.0;
  72. blueNoise = sign(blueNoise) * (1.0 - sqrt(1.0 - abs(blueNoise)));
  73. out_color += blueNoise / 255.0;
  74. #endif
  75. #if DBG_ENABLED
  76. const Vec4 dbg = textureLod(u_dbgOutlineRt, u_linearAnyClampSampler, uv, 0.0);
  77. out_color = mix(out_color, dbg.rgb, dbg.a);
  78. #endif
  79. }
  80. #pragma anki end