fsr_scaling.glsl 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #version 430 core
  2. precision mediump float;
  3. layout (local_size_x = 64) in;
  4. layout(rgba8, binding = 0, location=0) uniform image2D imgOutput;
  5. layout( location=1 ) uniform sampler2D Source;
  6. layout( location=2 ) uniform float srcX0;
  7. layout( location=3 ) uniform float srcX1;
  8. layout( location=4 ) uniform float srcY0;
  9. layout( location=5 ) uniform float srcY1;
  10. layout( location=6 ) uniform float dstX0;
  11. layout( location=7 ) uniform float dstX1;
  12. layout( location=8 ) uniform float dstY0;
  13. layout( location=9 ) uniform float dstY1;
  14. layout( location=10 ) uniform float scaleX;
  15. layout( location=11 ) uniform float scaleY;
  16. #define A_GPU 1
  17. #define A_GLSL 1
  18. #include "ffx_a.h"
  19. #define FSR_EASU_F 1
  20. AU4 con0, con1, con2, con3;
  21. float srcW, srcH, dstW, dstH;
  22. vec2 bLeft, tRight;
  23. AF2 translate(AF2 pos) {
  24. return AF2(pos.x * scaleX, pos.y * scaleY);
  25. }
  26. void setBounds(vec2 bottomLeft, vec2 topRight) {
  27. bLeft = bottomLeft;
  28. tRight = topRight;
  29. }
  30. AF2 translateDest(AF2 pos) {
  31. AF2 translatedPos = AF2(pos.x, pos.y);
  32. translatedPos.x = dstX1 < dstX0 ? dstX1 - translatedPos.x : translatedPos.x;
  33. translatedPos.y = dstY0 > dstY1 ? dstY0 + dstY1 - translatedPos.y - 1: translatedPos.y;
  34. return translatedPos;
  35. }
  36. AF4 FsrEasuRF(AF2 p) { AF4 res = textureGather(Source, translate(p), 0); return res; }
  37. AF4 FsrEasuGF(AF2 p) { AF4 res = textureGather(Source, translate(p), 1); return res; }
  38. AF4 FsrEasuBF(AF2 p) { AF4 res = textureGather(Source, translate(p), 2); return res; }
  39. #include "ffx_fsr1.h"
  40. float insideBox(vec2 v) {
  41. vec2 s = step(bLeft, v) - step(tRight, v);
  42. return s.x * s.y;
  43. }
  44. void CurrFilter(AU2 pos)
  45. {
  46. if((insideBox(vec2(pos.x, pos.y))) == 0) {
  47. imageStore(imgOutput, ASU2(pos.x, pos.y), AF4(0,0,0,1));
  48. return;
  49. }
  50. AF3 c;
  51. FsrEasuF(c, AU2(pos.x - bLeft.x, pos.y - bLeft.y), con0, con1, con2, con3);
  52. imageStore(imgOutput, ASU2(translateDest(pos)), AF4(c, 1));
  53. }
  54. void main() {
  55. srcW = abs(srcX1 - srcX0);
  56. srcH = abs(srcY1 - srcY0);
  57. dstW = abs(dstX1 - dstX0);
  58. dstH = abs(dstY1 - dstY0);
  59. AU2 gxy = ARmp8x8(gl_LocalInvocationID.x) + AU2(gl_WorkGroupID.x << 4u, gl_WorkGroupID.y << 4u);
  60. setBounds(vec2(dstX0 < dstX1 ? dstX0 : dstX1, dstY0 < dstY1 ? dstY0 : dstY1),
  61. vec2(dstX1 > dstX0 ? dstX1 : dstX0, dstY1 > dstY0 ? dstY1 : dstY0));
  62. // Upscaling
  63. FsrEasuCon(con0, con1, con2, con3,
  64. srcW, srcH, // Viewport size (top left aligned) in the input image which is to be scaled.
  65. srcW, srcH, // The size of the input image.
  66. dstW, dstH); // The output resolution.
  67. CurrFilter(gxy);
  68. gxy.x += 8u;
  69. CurrFilter(gxy);
  70. gxy.y += 8u;
  71. CurrFilter(gxy);
  72. gxy.x -= 8u;
  73. CurrFilter(gxy);
  74. }