Guest User

DetailsYF.fx

a guest
May 18th, 2025
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. //
  2. // Shader file for NVIDIA Ansel
  3. //
  4.  
  5. //
  6. // Constants
  7. //
  8.  
  9. #include "ReShadeUI.fxh"
  10.  
  11. uniform float g_sldSharpen < __UNIFORM_SLIDER_FLOAT1
  12. ui_min = 0.000; ui_max=1.000;
  13. ui_label = "Sharpen";
  14. ui_step = 0.001;
  15. > = 0.5;
  16.  
  17. uniform float g_sldClarity < __UNIFORM_SLIDER_FLOAT1
  18. ui_min = -1.000; ui_max=1.000;
  19. ui_label = "Clarity";
  20. ui_step = 0.001;
  21. > = 0.7;
  22.  
  23. uniform float g_sldHDR < __UNIFORM_SLIDER_FLOAT1
  24. ui_min = -1.000; ui_max=1.000;
  25. ui_label = "HDR Toning";
  26. ui_step = 0.001;
  27. > = 0.6;
  28.  
  29. uniform float g_sldBloom < __UNIFORM_SLIDER_FLOAT1
  30. ui_min = 0.000; ui_max=1.000;
  31. ui_label = "Bloom";
  32. ui_step = 0.001;
  33. > = 0.15;
  34.  
  35. #include "ReShade.fxh"
  36.  
  37. texture texOriginal
  38. {
  39. Width = BUFFER_WIDTH * 0.5;
  40. Height = BUFFER_HEIGHT * 0.5;
  41. Format = RGBA16F;
  42. };
  43.  
  44. sampler samplerOriginal { Texture = texOriginal; };
  45. static const float2 PixelSize = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT);
  46.  
  47. //#define vec2 float2
  48. //#define vec3 float3
  49. //#define vec4 float4
  50. //#define mix lerp
  51.  
  52. float4 ScaleableGaussianBlurLinear(sampler SamplerLinear, float2 texcoord, int nSteps, float2 axis, float2 texelsize)
  53. {
  54. float norm = -1.35914091423/(nSteps*nSteps);
  55. float4 accum = tex2D(SamplerLinear,texcoord.xy);
  56. float2 offsetinc = axis * texelsize;
  57. float divisor = 0.5; //exp(0) * 0.5
  58. [loop]
  59. for(float iStep = 1; iStep <= nSteps; iStep++)
  60. {
  61. float2 tapOffsetD = iStep * 2.0 + float2(-1.0,0.0);
  62. float2 tapWeightD = exp(tapOffsetD*tapOffsetD*norm);
  63. float tapWeightL = dot(tapWeightD,1.0);
  64. float tapOffsetL = dot(tapOffsetD,tapWeightD)/tapWeightL;
  65. accum += tex2D(SamplerLinear,texcoord.xy + offsetinc * tapOffsetL) * tapWeightL;
  66. accum += tex2D(SamplerLinear,texcoord.xy - offsetinc * tapOffsetL) * tapWeightL;
  67. divisor += tapWeightL;
  68. }
  69. accum /= 2.0 * divisor;
  70. return accum;
  71. }
  72.  
  73. float4 BoxBlur(sampler SamplerLinear, float2 texcoord, float2 texelsize)
  74. {
  75. float3 blurData[8] =
  76. {
  77. float3( 0.5, 1.5,1.50),
  78. float3( 1.5,-0.5,1.50),
  79. float3(-0.5,-1.5,1.50),
  80. float3(-1.5, 0.5,1.50),
  81. float3( 2.5, 1.5,1.00),
  82. float3( 1.5,-2.5,1.00),
  83. float3(-2.5,-1.5,1.00),
  84. float3(-1.5, 2.5,1.00),
  85. };
  86.  
  87. float4 blur = 0.0;
  88. for(int i=0; i<8; i++) {blur += tex2D(SamplerLinear,texcoord.xy + blurData[i].xy * texelsize.xy,0) * blurData[i].z;}
  89. blur /= (4 * 1.5) + (4 * 1.0);
  90. return blur;
  91. }
  92.  
  93. float4 PS_LargeBlur1(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target
  94. {
  95. return ScaleableGaussianBlurLinear(ReShade::BackBuffer,texcoord.xy,15,float2(1,0),PixelSize.xy);
  96. }
  97.  
  98. float4 PS_SharpenClarity(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target
  99. {
  100. float4 largeblur = ScaleableGaussianBlurLinear(samplerOriginal,texcoord.xy,15,float2(0,1),PixelSize.xy);
  101. float4 smallblur = BoxBlur(ReShade::BackBuffer,texcoord.xy,PixelSize);
  102. float4 color = tex2D(ReShade::BackBuffer,texcoord.xy);
  103.  
  104. float a = dot(color.rgb,float3(0.299,0.587,0.114));
  105. float sqrta = sqrt(a);
  106. float b = dot(largeblur.rgb,float3(0.299,0.587,0.114));
  107. float c = dot(smallblur.rgb,float3(0.299,0.587,0.114));
  108.  
  109. //HDR Toning
  110. 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
  111. color = color / (a+1e-6) * lerp(a,HDRToning,g_sldHDR);
  112.  
  113. //sharpen
  114. //float Sharpen = (a-c)/(g_sldSharpen*2.0+1e-6); //clamp to +- 1.0 / SHARPEN_AMOUNT with smooth falloff
  115. //Sharpen = sign(Sharpen)*(pow(Sharpen,6)-abs(Sharpen))/(pow(Sharpen,6)-1);
  116. //color += Sharpen*color*g_sldSharpen*2.0;
  117. float Sharpen = dot(color.rgb - smallblur.rgb,float3(0.299,0.587,0.114));
  118. float sharplimit = lerp(0.25,0.6,g_sldSharpen);
  119. Sharpen = clamp(Sharpen,-sharplimit,sharplimit);
  120. color.rgb = color.rgb / a * lerp(a,a+Sharpen,g_sldSharpen);
  121.  
  122. //clarity
  123. float Clarity = (0.5 + a - b);
  124. Clarity = lerp(2*Clarity + a*(1-2*Clarity), 2*(1-Clarity)+(2*Clarity-1)*rsqrt(a), a > b); //modified soft light v2
  125. color.rgb *= lerp(1.0,Clarity,g_sldClarity);
  126.  
  127. //bloom
  128. color.rgb = 1-(1-color.rgb)*(1-largeblur.rgb * g_sldBloom);
  129.  
  130. return color;
  131. }
  132.  
  133. technique Details
  134. {
  135. pass
  136. {
  137. VertexShader = PostProcessVS;
  138. PixelShader = PS_LargeBlur1;
  139. RenderTarget = texOriginal;
  140. }
  141. pass
  142. {
  143. VertexShader = PostProcessVS;
  144. PixelShader = PS_SharpenClarity;
  145. }
  146. }
  147.  
Advertisement
Add Comment
Please, Sign In to add comment