FinalComposite.ankiprog 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/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 texture2D u_lightShadingRt;
  22. layout(set = 0, binding = 4) uniform texture2D u_ppsBloomLfRt;
  23. layout(set = 0, binding = 5) uniform texture3D u_lut;
  24. layout(set = 0, binding = 6) uniform 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 texture2D u_dbgOutlineRt;
  29. #endif
  30. layout(push_constant, row_major, std430) uniform pc_
  31. {
  32. UVec4 u_frameCountPad3;
  33. };
  34. layout(location = 0) in Vec2 in_uv;
  35. layout(location = 0) out Vec3 out_color;
  36. Vec3 colorGrading(Vec3 color)
  37. {
  38. const Vec3 LUT_SCALE = Vec3((F32(LUT_SIZE) - 1.0) / F32(LUT_SIZE));
  39. const Vec3 LUT_OFFSET = Vec3(1.0 / (2.0 * F32(LUT_SIZE)));
  40. color = min(color, Vec3(1.0));
  41. const Vec3 lutCoords = color * LUT_SCALE + LUT_OFFSET;
  42. return textureLod(u_lut, u_trilinearRepeatSampler, lutCoords, 0.0).rgb;
  43. }
  44. void main()
  45. {
  46. const Vec2 uv = in_uv.xy;
  47. if(MOTION_BLUR_SAMPLES > 0u)
  48. {
  49. out_color = motionBlur(u_motionVectorsRt, u_nearestAnyClampSampler, u_lightShadingRt, Vec2(FB_SIZE),
  50. u_linearAnyClampSampler, uv, MOTION_BLUR_SAMPLES);
  51. }
  52. else
  53. {
  54. out_color = textureLod(u_lightShadingRt, u_linearAnyClampSampler, uv, 0.0).rgb;
  55. }
  56. #if BLOOM_ENABLED
  57. const Vec3 bloom = textureLod(u_ppsBloomLfRt, u_linearAnyClampSampler, uv, 0.0).rgb;
  58. out_color += bloom;
  59. #endif
  60. out_color = colorGrading(out_color);
  61. #if BLUE_NOISE
  62. const Vec2 bnUvw = Vec2(FB_SIZE) / Vec2(64.0) * uv;
  63. Vec3 blueNoise = textureLod(u_blueNoise, u_trilinearRepeatSampler, bnUvw, 0.0).rgb;
  64. blueNoise = animateBlueNoise(blueNoise, u_frameCountPad3.x);
  65. blueNoise = blueNoise * 2.0 - 1.0;
  66. blueNoise = sign(blueNoise) * (1.0 - sqrt(1.0 - abs(blueNoise)));
  67. out_color += blueNoise / 255.0;
  68. #endif
  69. #if DBG_ENABLED
  70. const Vec4 dbg = textureLod(u_dbgOutlineRt, u_linearAnyClampSampler, uv, 0.0);
  71. out_color = mix(out_color, dbg.rgb, dbg.a);
  72. #endif
  73. }
  74. #pragma anki end