Guest User

Detailsodikzz2.fx

a guest
May 18th, 2025
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. /**
  2. Details filter from GeForce Experience. Provided by NVIDIA Corporation.
  3.  
  4. Copyright 2019 Suketu J. Shah. All rights reserved.
  5.  
  6. Redistribution and use in source and binary forms, with or without modification, are permitted provided
  7. that the following conditions are met:
  8.  
  9. 1. Redistributions of source code must retain the above copyright notice, this list of conditions
  10. and the following disclaimer.
  11. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
  12. and the following disclaimer in the documentation and/or other materials provided with the distribution.
  13. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
  14. or promote products derived from this software without specific prior written permission.
  15.  
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  17. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  18. PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  19. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  20. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  22. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  23. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25.  
  26. #include "ReShadeUI.fxh"
  27.  
  28. uniform float g_sldSharpen < __UNIFORM_SLIDER_FLOAT1
  29. ui_min = 0.000; ui_max=1.000;
  30. ui_label = "Sharpen";
  31. ui_step = 0.001;
  32. > = 0.5;
  33.  
  34. uniform float g_sldClarity < __UNIFORM_SLIDER_FLOAT1
  35. ui_min = -1.000; ui_max=1.000;
  36. ui_label = "Clarity";
  37. ui_step = 0.001;
  38. > = 0.7;
  39.  
  40. uniform float g_sldHDR < __UNIFORM_SLIDER_FLOAT1
  41. ui_min = -1.000; ui_max=1.000;
  42. ui_label = "HDR Toning";
  43. ui_step = 0.001;
  44. > = 0.6;
  45.  
  46. uniform float g_sldBloom < __UNIFORM_SLIDER_FLOAT1
  47. ui_min = 0.000; ui_max=1.000;
  48. ui_label = "Bloom";
  49. ui_step = 0.001;
  50. > = 0.15;
  51.  
  52. #include "NvCommon.fxh"
  53.  
  54. texture LargeBlurTex { Width = BUFFER_WIDTH*0.5; Height = BUFFER_HEIGHT*0.5; Format = RGBA16F; }; //requires recent changes to support this
  55. sampler sLargeBlurTex { Texture = LargeBlurTex;};
  56.  
  57. float4 gaussian(sampler sinput, float2 uv, int nSteps, float2 axis)
  58. {
  59. float norm = -1.35914091423 / (nSteps * nSteps);
  60. float4 accum = tex2D(sinput, uv) * 0.5;
  61. float2 offsetinc = axis * BUFFER_PIXEL_SIZE;
  62.  
  63. float divisor = 0.5; //exp(0) * 0.5
  64.  
  65. [loop]
  66. for(float iStep = 1; iStep <= nSteps; iStep++)
  67. {
  68. //linear sample, gathers 2 texels at once
  69. //only texel not being sampled that way is center, hence it needs 1/2 the weight
  70. float tapOffset = iStep * 2.0 - 0.5;
  71. float tapWeight = exp(iStep * iStep * norm);
  72.  
  73. accum += tex2Dlod(sinput, float4(uv + offsetinc * tapOffset, 0, 0)) * tapWeight;
  74. accum += tex2Dlod(sinput, float4(uv - offsetinc * tapOffset, 0, 0)) * tapWeight;
  75. divisor += tapWeight;
  76. }
  77. accum /= 2.0 * divisor;
  78. return accum;
  79. }
  80.  
  81. float4 box(sampler sinput, float2 uv)
  82. {
  83. const float3 blurData[8] =
  84. {
  85. float3( 0.5, 1.5,1.50),
  86. float3( 1.5,-0.5,1.50),
  87. float3(-0.5,-1.5,1.50),
  88. float3(-1.5, 0.5,1.50),
  89. float3( 2.5, 1.5,1.00),
  90. float3( 1.5,-2.5,1.00),
  91. float3(-2.5,-1.5,1.00),
  92. float3(-1.5, 2.5,1.00),
  93. };
  94.  
  95. float4 blur = 0.0;
  96. for(int i=0; i<8; i++)
  97. blur += tex2Dlod(sinput, float4(uv + blurData[i].xy * BUFFER_PIXEL_SIZE, 0, 0)) * blurData[i].z;
  98.  
  99. blur /= (4 * 1.5) + (4 * 1.0);
  100. return blur;
  101. }
  102.  
  103. float getluma(float3 color)
  104. {
  105. return dot(color,float3(0.299,0.587,0.114));
  106. }
  107.  
  108. void PSGaussian1(in VSOut i, out float4 color : SV_Target)
  109. {
  110. color = gaussian(NV::ColorInput, i.uv, 15, float2(1, 0));
  111. }
  112. void PSGaussian2AndBlend(in VSOut i, out float4 color : SV_Target)
  113. {
  114. float4 largeblur = gaussian(sLargeBlurTex, i.uv, 15, float2(0, 1));
  115. float4 smallblur = box(NV::ColorInput, i.uv);
  116. color = tex2D(NV::ColorInput, i.uv);
  117.  
  118. float a = getluma(color.rgb);
  119. float b = getluma(largeblur.rgb);
  120. float c = getluma(smallblur.rgb);
  121.  
  122. //HDR Toning
  123. float sqrta = sqrt(a);
  124. float HDRToning = sqrta * lerp(sqrta*(2*a*b-a-2*b+2.0), (2*sqrta*b-2*b+1), b > 0.5); //modified soft light v1
  125. color = color / (a+1e-6) * lerp(a,HDRToning,g_sldHDR);
  126.  
  127. //sharpen
  128. float Sharpen = getluma(color.rgb - smallblur.rgb); //need to recompute, as luma of color changed by hdr toning
  129. float sharplimit = lerp(0.25,0.6,g_sldSharpen);
  130. Sharpen = clamp(Sharpen,-sharplimit, sharplimit);
  131. color.rgb = color.rgb / a * lerp(a,a+Sharpen,g_sldSharpen);
  132.  
  133. //clarity
  134. float Clarity = (0.5 + a - b);
  135. Clarity = lerp(2*Clarity + a*(1-2*Clarity), 2*(1-Clarity)+(2*Clarity-1)*rsqrt(a), a > b); //modified soft light v2
  136. color.rgb *= lerp(1.0,Clarity,g_sldClarity);
  137.  
  138. //bloom
  139. color.rgb = 1-(1-color.rgb)*(1-largeblur.rgb * g_sldBloom);
  140.  
  141. }
  142.  
  143. technique Details
  144. {
  145. pass
  146. {
  147. VertexShader = VSMain;
  148. PixelShader = PSGaussian1;
  149. RenderTarget = LargeBlurTex;
  150. }
  151. pass
  152. {
  153. VertexShader = VSMain;
  154. PixelShader = PSGaussian2AndBlend;
  155. }
  156. }
  157.  
Add Comment
Please, Sign In to add comment