FinalComposite.ankiprog 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (C) 2009-present, 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 FILM_GRAIN 0 1
  6. #pragma anki mutator BLOOM 0 1
  7. #pragma anki mutator DBG 0 1
  8. #pragma anki mutator SHARPEN 0 1
  9. #pragma anki technique vert pixel
  10. #include <AnKi/Shaders/QuadVert.hlsl>
  11. #if ANKI_PIXEL_SHADER
  12. # include <AnKi/Shaders/Functions.hlsl>
  13. SamplerState g_linearAnyClampSampler : register(s0);
  14. Texture2D<Vec4> g_lightShadingRt : register(t0);
  15. Texture2D<Vec4> g_ppsBloomLfRt : register(t1);
  16. # if DBG
  17. Texture2D<Vec4> g_dbgOutlineRt : register(t2);
  18. # endif
  19. struct Constants
  20. {
  21. UVec4 m_fsrConsts0;
  22. F32 m_filmGrainStrength;
  23. U32 m_frameCount;
  24. U32 m_padding1;
  25. U32 m_padding2;
  26. };
  27. ANKI_FAST_CONSTANTS(Constants, g_consts)
  28. // FSR begin
  29. # define A_GPU 1
  30. # define A_HLSL 1
  31. # define A_HALF 1
  32. # include <ThirdParty/FidelityFX/ffx_a.h>
  33. AH4 FsrRcasLoadH(ASW2 p)
  34. {
  35. return AH4(g_lightShadingRt.Load(IVec3(p, 0)));
  36. }
  37. void FsrRcasInputH(inout AH1 r, inout AH1 g, inout AH1 b)
  38. {
  39. ANKI_MAYBE_UNUSED(r);
  40. ANKI_MAYBE_UNUSED(g);
  41. ANKI_MAYBE_UNUSED(b);
  42. }
  43. # define FSR_RCAS_H 1
  44. # include <ThirdParty/FidelityFX/ffx_fsr1.h>
  45. // FSR end
  46. Vec4 main(VertOut input) : SV_TARGET0
  47. {
  48. const Vec2 uv = input.m_uv;
  49. ANKI_MAYBE_UNUSED(uv);
  50. HVec3 outColor;
  51. # if SHARPEN
  52. FsrRcasH(outColor.r, outColor.g, outColor.b, input.m_svPosition.xy, g_consts.m_fsrConsts0);
  53. # else
  54. outColor = g_lightShadingRt.SampleLevel(g_linearAnyClampSampler, uv, 0.0).rgb;
  55. # endif
  56. # if BLOOM
  57. const HVec3 bloom = g_ppsBloomLfRt.SampleLevel(g_linearAnyClampSampler, uv, 0.0).rgb;
  58. outColor += bloom;
  59. # endif
  60. # if FILM_GRAIN
  61. const F32 dt = 1.0;
  62. outColor = filmGrain<F32>(outColor, uv, g_consts.m_filmGrainStrength, F32(g_consts.m_frameCount % 0xFFFFu) * dt);
  63. # endif
  64. # if DBG
  65. const HVec4 dbg = g_dbgOutlineRt.SampleLevel(g_linearAnyClampSampler, uv, 0.0);
  66. outColor = lerp(outColor, dbg.rgb, dbg.a);
  67. # endif
  68. return Vec4(outColor, 0.0);
  69. }
  70. #endif // ANKI_PIXEL_SHADER