Advertisement
Guest User

Untitled

a guest
May 31st, 2018
1,526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. /**
  2. * Copyright (C) 2015 Lucifer Hawk ()
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software with restriction, including without limitation the rights to
  7. * use and/or sell copies of the Software, and to permit persons to whom the Software
  8. * is furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and the permission notices (this and below) shall
  11. * be included in all copies or substantial portions of the Software.
  12. *
  13. * Permission needs to be specifically granted by the author of the software to any
  14. * person obtaining a copy of this software and associated documentation files
  15. * (the "Software"), to deal in the Software without restriction, including without
  16. * limitation the rights to copy, modify, merge, publish, distribute, and/or
  17. * sublicense the Software, and subject to the following conditions:
  18. *
  19. * The above copyright notice and the permission notices (this and above) shall
  20. * be included in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28. * SOFTWARE.
  29. */
  30.  
  31. #include "ReShade.fxh"
  32.  
  33. uniform bool ambDepth_Check <
  34. ui_type = "boolean";
  35. ui_label = "Depth dependent motion blur [Adv. MBlur]";
  36. > = true;
  37.  
  38. uniform float ambDepthRatio <
  39. ui_type = "drag";
  40. ui_min = 0.0;
  41. ui_max = 1.0;
  42. ui_step = 0.001;
  43. ui_label = "Motion Blur Depth Ratio [Adv. MBlur]";
  44. ui_tooltip = "Amount of addition MB due to distance; Lower Value => Higher Amount";
  45. > = 0;
  46.  
  47. uniform float ambRecall <
  48. ui_type = "drag";
  49. ui_min = 0.0;
  50. ui_max = 1.0;
  51. ui_step = 0.001;
  52. ui_label = "Motion Blur Recall [Adv. MBlur]";
  53. ui_tooltip = "Increases detection level of relevant smart motion blur";
  54. > = 1;
  55.  
  56. uniform float ambPrecision <
  57. ui_type = "drag";
  58. ui_min = 0.0;
  59. ui_max = 1.0;
  60. ui_step = 0.001;
  61. ui_label = "Motion Blur Precision [Adv. MBlur]";
  62. ui_tooltip = "Increases relevance level of detected smart motion blur";
  63. > = 0;
  64.  
  65. uniform float ambSoftness <
  66. ui_type = "drag";
  67. ui_min = 0.0;
  68. ui_max = 10.0;
  69. ui_step = 0.001;
  70. ui_label = "Softness [Adv. MBlur]";
  71. ui_tooltip = "Softness of consequential streaks";
  72. > = 10.0;
  73.  
  74. uniform float ambSmartMult <
  75. ui_type = "drag";
  76. ui_min = 0.0;
  77. ui_max = 10.0;
  78. ui_step = 0.001;
  79. ui_label = "Smart Multiplication [Adv. MBlur]";
  80. ui_tooltip = "Multiplication of relevant smart motion blur";
  81. > = 10.0;
  82.  
  83. uniform float ambIntensity <
  84. ui_type = "drag";
  85. ui_min = 0.0;
  86. ui_max = 1.0;
  87. ui_step = 0.001;
  88. ui_label = "Intensity [Adv. MBlur]";
  89. ui_tooltip = "Intensity of base motion blur effect";
  90. > = 0;
  91.  
  92. uniform float ambSmartInt <
  93. ui_type = "drag";
  94. ui_min = 0.0;
  95. ui_max = 1.0;
  96. ui_step = 0.001;
  97. ui_label = "Smart Intensity [Adv. MBlur]";
  98. ui_tooltip = "Intensity of smart motion blur effect";
  99. > = 0;
  100.  
  101. texture2D ambCurrBlurTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
  102. texture2D ambPrevBlurTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
  103. texture2D ambPrevTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
  104. sampler2D ambCurrBlurColor { Texture = ambCurrBlurTex; };
  105. sampler2D ambPrevBlurColor { Texture = ambPrevBlurTex; };
  106. sampler2D ambPrevColor { Texture = ambPrevTex; };
  107.  
  108. float4 PS_AMBCombine(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
  109. {
  110. float4 prev = tex2D(ambPrevBlurColor, texcoord);
  111. float4 curr = tex2D(ReShade::BackBuffer, texcoord);
  112. float4 currBlur = tex2D(ambCurrBlurColor, texcoord);
  113.  
  114. float diff = (abs(currBlur.r - prev.r) + abs(currBlur.g - prev.g) + abs(currBlur.b - prev.b)) / 3;
  115. diff = min(max(diff - ambPrecision, 0.0f)*ambSmartMult, ambRecall);
  116.  
  117. if (ambDepth_Check != 0){
  118. float depth = tex2D(ReShade::DepthBuffer, texcoord).r;
  119. return lerp(curr, prev, min(ambIntensity+diff*ambSmartInt, 1.0f)/(depth.r+ambDepthRatio));
  120. } else {
  121. return lerp(curr, prev, min(ambIntensity+diff*ambSmartInt, 1.0f));
  122. }
  123. }
  124.  
  125. void PS_AMBCopyPreviousFrame(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 prev : SV_Target0)
  126. {
  127. prev = tex2D(ReShade::BackBuffer, texcoord);
  128. }
  129.  
  130. void PS_AMBBlur(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 curr : SV_Target0, out float4 prev : SV_Target1)
  131. {
  132. float4 currVal = tex2D(ReShade::BackBuffer, texcoord);
  133. float4 prevVal = tex2D(ambPrevColor, texcoord);
  134.  
  135. float weight[11] = { 0.082607, 0.040484, 0.038138, 0.034521, 0.030025, 0.025094, 0.020253, 0.015553, 0.011533, 0.008218, 0.005627 };
  136. currVal *= weight[0];
  137. prevVal *= weight[0];
  138.  
  139. float ratio = -1.0f;
  140.  
  141. float pixelBlur = ambSoftness/max(1.0f,1.0f+(-1.0f)*ratio) * (BUFFER_RCP_HEIGHT);
  142.  
  143. [unroll]
  144. for (int z = 1; z < 11; z++) //set quality level by user
  145. {
  146. currVal += tex2D(ReShade::BackBuffer, texcoord + float2(z*pixelBlur, 0)) * weight[z];
  147. currVal += tex2D(ReShade::BackBuffer, texcoord - float2(z*pixelBlur, 0)) * weight[z];
  148. currVal += tex2D(ReShade::BackBuffer, texcoord + float2(0, z*pixelBlur)) * weight[z];
  149. currVal += tex2D(ReShade::BackBuffer, texcoord - float2(0, z*pixelBlur)) * weight[z];
  150.  
  151. prevVal += tex2D(ambPrevColor, texcoord + float2(z*pixelBlur, 0)) * weight[z];
  152. prevVal += tex2D(ambPrevColor, texcoord - float2(z*pixelBlur, 0)) * weight[z];
  153. prevVal += tex2D(ambPrevColor, texcoord + float2(0, z*pixelBlur)) * weight[z];
  154. prevVal += tex2D(ambPrevColor, texcoord - float2(0, z*pixelBlur)) * weight[z];
  155. }
  156.  
  157. curr = currVal;
  158. prev = prevVal;
  159. }
  160.  
  161. technique AdvancedMotionBlur_Tech
  162. {
  163. pass AMBBlur
  164. {
  165. VertexShader = PostProcessVS;
  166. PixelShader = PS_AMBBlur;
  167. RenderTarget0 = ambCurrBlurTex;
  168. RenderTarget1 = ambPrevBlurTex;
  169. }
  170.  
  171. pass AMBCombine
  172. {
  173. VertexShader = PostProcessVS;
  174. PixelShader = PS_AMBCombine;
  175. }
  176.  
  177. pass AMBPrev
  178. {
  179. VertexShader = PostProcessVS;
  180. PixelShader = PS_AMBCopyPreviousFrame;
  181. RenderTarget0 = ambPrevTex;
  182. }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement