Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 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. float Min3(float x, float y, float z)
  28. {
  29. return min(x, min(y, z));
  30. }
  31.  
  32. float Max3(float x, float y, float 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. // Soft min and max.
  57. // a b c b
  58. // d e f * 0.5 + d e f * 0.5
  59. // g h i h
  60. // These are 2.0x bigger (factored out the extra multiply).
  61. float mnR = Min3( Min3(d.r, e.r, f.r), b.r, h.r);
  62. float mnG = Min3( Min3(d.g, e.g, f.g), b.g, h.g);
  63. float mnB = Min3( Min3(d.b, e.b, f.b), b.b, h.b);
  64.  
  65. float mnR2 = Min3( Min3(mnR, a.r, c.r), g.r, i.r);
  66. float mnG2 = Min3( Min3(mnG, a.g, c.g), g.g, i.g);
  67. float mnB2 = Min3( Min3(mnB, a.b, c.b), g.b, i.b);
  68. mnR = mnR + mnR2;
  69. mnG = mnG + mnG2;
  70. mnB = mnB + mnB2;
  71.  
  72. float mxR = Max3( Max3(d.r, e.r, f.r), b.r, h.r);
  73. float mxG = Max3( Max3(d.g, e.g, f.g), b.g, h.g);
  74. float mxB = Max3( Max3(d.b, e.b, f.b), b.b, h.b);
  75.  
  76. float mxR2 = Max3( Max3(mxR, a.r, c.r), g.r, i.r);
  77. float mxG2 = Max3( Max3(mxG, a.g, c.g), g.g, i.g);
  78. float mxB2 = Max3( Max3(mxB, a.b, c.b), g.b, i.b);
  79. mxR = mxR + mxR2;
  80. mxG = mxG + mxG2;
  81. mxB = mxB + mxB2;
  82.  
  83. // Smooth minimum distance to signal limit divided by smooth max.
  84. float rcpMR = rcp(mxR);
  85. float rcpMG = rcp(mxG);
  86. float rcpMB = rcp(mxB);
  87.  
  88. float ampR = saturate(min(mnR, 2.0 - mxR) * rcpMR);
  89. float ampG = saturate(min(mnG, 2.0 - mxG) * rcpMG);
  90. float ampB = saturate(min(mnB, 2.0 - mxB) * rcpMB);
  91.  
  92. // Shaping amount of sharpening.
  93. ampR = sqrt(ampR);
  94. ampG = sqrt(ampG);
  95. ampB = sqrt(ampB);
  96.  
  97. // Filter shape.
  98. // 0 w 0
  99. // w 1 w
  100. // 0 w 0
  101. float peak = -rcp(lerp(8.0, 5.0, saturate(Sharpness)));
  102.  
  103. float wR = ampR * peak;
  104. float wG = ampG * peak;
  105. float wB = ampB * peak;
  106.  
  107. float rcpWeightR = rcp(1.0 + 4.0 * wR);
  108. float rcpWeightG = rcp(1.0 + 4.0 * wG);
  109. float rcpWeightB = rcp(1.0 + 4.0 * wB);
  110.  
  111. float3 outColor = float3(saturate((b.r*wR+d.r*wR+f.r*wR+h.r*wR+e.r)*rcpWeightR),
  112. saturate((b.g*wG+d.g*wG+f.g*wG+h.g*wG+e.g)*rcpWeightG),
  113. saturate((b.b*wB+d.b*wB+f.b*wB+h.b*wB+e.b)*rcpWeightB));
  114. return outColor;
  115. }
  116.  
  117. technique CAS
  118. {
  119. pass
  120. {
  121. VertexShader = PostProcessVS;
  122. PixelShader = CASPass;
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement