2
0

FinalComposite.ankiprog 3.3 KB

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