Guest User

CAS "optimized"

a guest
Jul 11th, 2019
3,305
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. float3 max3rgb(float3 x, float3 y, float3 z)
  32. {
  33. return max(x, max(y, z));
  34. }
  35.  
  36. float3 CASPass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
  37. {
  38. // fetch a 3x3 neighborhood around the pixel 'e',
  39. // a b c
  40. // d(e)f
  41. // g h i
  42. float pixelX = ReShade::PixelSize.x;
  43. float pixelY = ReShade::PixelSize.y;
  44.  
  45. float3 a = tex2D(ReShade::BackBuffer, texcoord + float2(-pixelX, -pixelY)).rgb;
  46. float3 b = tex2D(ReShade::BackBuffer, texcoord + float2(0.0, -pixelY)).rgb;
  47. float3 c = tex2D(ReShade::BackBuffer, texcoord + float2(pixelX, -pixelY)).rgb;
  48. float3 d = tex2D(ReShade::BackBuffer, texcoord + float2(-pixelX, 0.0)).rgb;
  49. float3 e = tex2D(ReShade::BackBuffer, texcoord).rgb;
  50. float3 f = tex2D(ReShade::BackBuffer, texcoord + float2(pixelX, 0.0)).rgb;
  51. float3 g = tex2D(ReShade::BackBuffer, texcoord + float2(-pixelX, pixelY)).rgb;
  52. float3 h = tex2D(ReShade::BackBuffer, texcoord + float2(0.0, pixelY)).rgb;
  53. float3 i = tex2D(ReShade::BackBuffer, texcoord + float2(pixelX, pixelY)).rgb;
  54.  
  55. //McFly: vectorize math, even with scalar gcn hardware this should work
  56. //out the same, order of operations has not changed
  57.  
  58. // Soft min and max.
  59. // a b c b
  60. // d e f * 0.5 + d e f * 0.5
  61. // g h i h
  62. // These are 2.0x bigger (factored out the extra multiply).
  63.  
  64. float3 mnRGB = min3rgb(min3rgb(d, e, f), b, h);
  65. float3 mnRGB2 = min3rgb(min3rgb(mnRGB, a, c), g, i);
  66. mnRGB += mnRGB2;
  67.  
  68. float3 mxRGB = max3rgb(max3rgb(d, e, f), b, h);
  69. float3 mxRGB2 = max3rgb(max3rgb(mxRGB, a, c), g, i);
  70. mxRGB += mxRGB2;
  71.  
  72. // Smooth minimum distance to signal limit divided by smooth max.
  73. float3 rcpMRGB = rcp(mxRGB);
  74. float3 ampRGB = saturate(min(mnRGB, 2.0 - mxRGB) * rcpMRGB);
  75.  
  76. // Shaping amount of sharpening.
  77. ampRGB = sqrt(ampRGB);
  78.  
  79. // Filter shape.
  80. // 0 w 0
  81. // w 1 w
  82. // 0 w 0
  83. float peak = -rcp(lerp(8.0, 5.0, saturate(Sharpness)));
  84. float3 wRGB = ampRGB * peak;
  85.  
  86. float3 rcpWeightRGB = rcp(1.0 + 4.0 * wRGB);
  87.  
  88. //McFly: less instructions that way
  89. float3 window = (b + d) + (f + h);
  90. float3 outColor = saturate((window * wRGB + e) * rcpWeightRGB);
  91.  
  92. return outColor;
  93. }
  94.  
  95. technique CAS
  96. {
  97. pass
  98. {
  99. VertexShader = PostProcessVS;
  100. PixelShader = CASPass;
  101. }
  102. }
RAW Paste Data