Advertisement
Zacam

AMD_FFX_CAS.fx

Oct 29th, 2019
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. // LICENSE
  2. // =======
  3. // Copyright (c) 2017-2019 Advanced Micro Devices, Inc. All rights reserved.
  4. // -------
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
  6. // files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
  7. // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
  8. // Software is furnished to do so, subject to the following conditions:
  9. // -------
  10. // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  11. // Software.
  12. // -------
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14. // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  16. // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
  17.  
  18. uniform float Sharpness <
  19. ui_type = "drag";
  20. ui_label = "Sharpening Strength";
  21. ui_tooltip = "0 := no sharpening, to 1 := full sharpening.\nScaled by the sharpness knob while being transformed to a negative lobe (values from -1/5 to -1/8 for A=1)";
  22. ui_min = 0.0; ui_max = 1.0;
  23. > = 0.0;
  24.  
  25. #include "ReShade.fxh"
  26.  
  27. float3 min3rgb(float3 x, float3 y, float3 z)
  28. {
  29. return min(x, min(y, z));
  30. }
  31.  
  32. float3 max3rgb(float3 x, float3 y, float3 z)
  33. {
  34. return max(x, max(y, z));
  35. }
  36.  
  37. float3 CASPass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
  38. {
  39. // fetch a 3x3 neighborhood around the pixel 'e',
  40. // a b c
  41. // d(e)f
  42. // g h i
  43. float pixelX = ReShade::PixelSize.x;
  44. float pixelY = ReShade::PixelSize.y;
  45.  
  46. float3 a = tex2D(ReShade::BackBuffer, texcoord + float2(-pixelX, -pixelY)).rgb;
  47. float3 b = tex2D(ReShade::BackBuffer, texcoord + float2(0.0, -pixelY)).rgb;
  48. float3 c = tex2D(ReShade::BackBuffer, texcoord + float2(pixelX, -pixelY)).rgb;
  49. float3 d = tex2D(ReShade::BackBuffer, texcoord + float2(-pixelX, 0.0)).rgb;
  50. float3 e = tex2D(ReShade::BackBuffer, texcoord).rgb;
  51. float3 f = tex2D(ReShade::BackBuffer, texcoord + float2(pixelX, 0.0)).rgb;
  52. float3 g = tex2D(ReShade::BackBuffer, texcoord + float2(-pixelX, pixelY)).rgb;
  53. float3 h = tex2D(ReShade::BackBuffer, texcoord + float2(0.0, pixelY)).rgb;
  54. float3 i = tex2D(ReShade::BackBuffer, texcoord + float2(pixelX, pixelY)).rgb;
  55.  
  56. // McFly: vectorize math, even with scalar gcn hardware this should work out the same, order of operations has not changed
  57. // Soft min and max.
  58. // a b c b
  59. // d e f * 0.5 + d e f * 0.5
  60. // g h i h
  61. // These are 2.0x bigger (factored out the extra multiply).
  62.  
  63. float3 mnRGB = min3rgb(min3rgb(d, e, f), b, h);
  64. float3 mnRGB2 = min3rgb(min3rgb(mnRGB, a, c), g, i);
  65. mnRGB += mnRGB2;
  66.  
  67. float3 mxRGB = max3rgb(max3rgb(d, e, f), b, h);
  68. float3 mxRGB2 = max3rgb(max3rgb(mxRGB, a, c), g, i);
  69. mxRGB += mxRGB2;
  70.  
  71. // Smooth minimum distance to signal limit divided by smooth max.
  72. float3 rcpMRGB = rcp(mxRGB);
  73. float3 ampRGB = saturate(min(mnRGB, 2.0 - mxRGB) * rcpMRGB);
  74.  
  75. // Shaping amount of sharpening.
  76. ampRGB = sqrt(ampRGB);
  77.  
  78. // Filter shape:
  79. // 0 w 0
  80. // w 1 w
  81. // 0 w 0
  82. float peak = -rcp(lerp(8.0, 5.0, saturate(Sharpness)));
  83. float3 wRGB = ampRGB * peak;
  84.  
  85. float3 rcpWeightRGB = rcp(1.0 + 4.0 * wRGB);
  86.  
  87. // McFly: less instructions that way
  88. float3 window = (b + d) + (f + h);
  89. float3 outColor = saturate((window * wRGB + e) * rcpWeightRGB);
  90.  
  91. return outColor;
  92. }
  93.  
  94. technique CAS
  95. {
  96. pass
  97. {
  98. VertexShader = PostProcessVS;
  99. PixelShader = CASPass;
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement