Fsr.glsl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 SHARPEN 0 1
  6. #pragma anki mutator FSR_QUALITY 0 1
  7. #include <AnKi/Shaders/Functions.glsl>
  8. layout(set = 0, binding = 0) uniform sampler u_linearAnyClampSampler;
  9. layout(set = 0, binding = 1) uniform ANKI_RP texture2D u_tex;
  10. #if defined(ANKI_COMPUTE_SHADER)
  11. layout(set = 0, binding = 2) writeonly uniform ANKI_RP image2D u_outImg;
  12. layout(local_size_x = 8, local_size_y = 8) in;
  13. #else
  14. layout(location = 0) out ANKI_RP Vec3 out_color;
  15. #endif
  16. layout(push_constant, std430) uniform b_pc
  17. {
  18. UVec4 u_fsrConsts0;
  19. UVec4 u_fsrConsts1;
  20. UVec4 u_fsrConsts2;
  21. UVec4 u_fsrConsts3;
  22. UVec2 u_viewportSize;
  23. UVec2 u_padding;
  24. };
  25. // FSR begin
  26. #define A_GPU 1
  27. #define A_GLSL 1
  28. #define A_HALF 1
  29. #include <ThirdParty/FidelityFX/ffx_a.h>
  30. #if SHARPEN
  31. # define FSR_RCAS_H 1
  32. AH4 FsrRcasLoadH(ASW2 p)
  33. {
  34. return AH4(texelFetch(sampler2D(u_tex, u_linearAnyClampSampler), ASU2(p), 0));
  35. }
  36. void FsrRcasInputH(inout AH1 r, inout AH1 g, inout AH1 b)
  37. {
  38. }
  39. #else // !SHARPEN
  40. # define FSR_EASU_H 1
  41. AH4 FsrEasuRH(AF2 p)
  42. {
  43. return AH4(textureGather(sampler2D(u_tex, u_linearAnyClampSampler), p, 0));
  44. }
  45. AH4 FsrEasuGH(AF2 p)
  46. {
  47. return AH4(textureGather(sampler2D(u_tex, u_linearAnyClampSampler), p, 1));
  48. }
  49. AH4 FsrEasuBH(AF2 p)
  50. {
  51. return AH4(textureGather(sampler2D(u_tex, u_linearAnyClampSampler), p, 2));
  52. }
  53. AH3 FsrEasuSampleH(AF2 p)
  54. {
  55. return AH3(textureLod(u_tex, u_linearAnyClampSampler, p, 0.0).xyz);
  56. }
  57. #endif
  58. #include <ThirdParty/FidelityFX/ffx_fsr1.h>
  59. // FSR end
  60. void main()
  61. {
  62. #if defined(ANKI_COMPUTE_SHADER)
  63. if(skipOutOfBoundsInvocations(UVec2(8u), u_viewportSize))
  64. {
  65. return;
  66. }
  67. const UVec2 uv = gl_GlobalInvocationID.xy;
  68. #else
  69. const UVec2 uv = UVec2(gl_FragCoord.xy);
  70. #endif
  71. HVec3 color;
  72. #if SHARPEN
  73. FsrRcasH(color.r, color.g, color.b, uv, u_fsrConsts0);
  74. #elif FSR_QUALITY == 0
  75. FsrEasuL(color, uv, u_fsrConsts0, u_fsrConsts1, u_fsrConsts2, u_fsrConsts3);
  76. #else
  77. FsrEasuH(color, uv, u_fsrConsts0, u_fsrConsts1, u_fsrConsts2, u_fsrConsts3);
  78. #endif
  79. #if defined(ANKI_COMPUTE_SHADER)
  80. imageStore(u_outImg, IVec2(gl_GlobalInvocationID.xy), Vec4(color, 0.0));
  81. #else
  82. out_color = Vec3(color);
  83. #endif
  84. }