SHARE
TWEET

Adaptive Fog Reashade 3 port alpha

a guest Mar 2nd, 2017 223 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///////////////////////////////////////////////////////////////////
  2. // Simple depth-based fog powered with bloom to fake light diffusion.
  3. // The bloom is borrowed from SweetFX's bloom by CeeJay.
  4. // Original shader by OtisLnf, Reshade 3 port by v00d00m4n
  5. ///////////////////////////////////////////////////////////////////
  6.  
  7. #include "ReShade.fxh"
  8.  
  9. //#include EFFECT_CONFIG(Otis)
  10.  
  11. ////---------------//
  12. ///**ADAPTIVEFOG**///
  13. //---------------////
  14. #define USE_ADAPTIVEFOG 0 //[AdaptiveFog] //-Bloom driven depth-based fog. It uses an overly bloomed version of the frame buffer combined with the depth buffer to create a fog volume in the scene. The bloom is used to fake light diffusion around lights. This effect is toggled off by default, you need to define a toggle key to enable it.
  15.  
  16. //>ADAPTIVE FOG General Settings<\\
  17. #define AFG_MouseDrivenFogColorSelect 0 //[0,1] //-If 1, you can use the mouse overlay (enabled with the MOL_ToggleKey defined in the MouseOverlay effect) to select the fog color from the scene. If 0, it will use AFG_Color as fog color.
  18. #define AFG_Color float3(0.9,0.9,0.9) //[0.0:1.0] //-Color of the fog (r, g, b). Ignored if AFG_MouseDrivenFogColorSelect is 1.
  19. #define AFG_MaxFogFactor 0.9 //[0.0:1.0] //-The maximum fog factor. 1.0 makes distant objects completely fogged out, a lower factor will shimmer them through the fog.
  20. #define AFG_FogCurve 2.0 //[0.1:175.0] //-The curve how quickly distant objects get fogged. A low value will make the fog appear just slightly. A high value will make the fog kick in rather quickly. The max value in the rage makes it very hard in general to view any objects outside fog.
  21. #define AFG_FogStart 0.0 //[0.0:1.0] //-The start of the fog. 0.0 is at the camera position, 1.0 is horizon.
  22. #define AFG_ToggleKey RESHADE_TOGGLE_KEY //[undef] //-Key to toggle the effect on or off
  23.  
  24. //>ADAPTIVE FOG Bloom Settings<\\
  25. #define AFG_BloomThreshold 2.25 //[0.00:50.00] //-Threshold for what is a bright light (that causes bloom) and what isn't.
  26. #define AFG_BloomPower 10.000 //[0.000:100.000] //-Strength of the bloom
  27. #define AFG_BloomWidth 0.3 //[0.0000:1.0000] //-Width of the bloom
  28.  
  29.  
  30. //#include "Common.fx"
  31.  
  32. ///
  33.  
  34. // Stuff all/most of Otis shared shaders need
  35.  
  36. define HDR_MODE
  37.  
  38. #if( HDR_MODE == 0)
  39.  #define Otis_RENDERMODE RGBA8
  40. #elif( HDR_MODE == 1)
  41.  #define Otis_RENDERMODE RGBA16F
  42. #else
  43.  #define Otis_RENDERMODE RGBA32F
  44. #endif
  45.  
  46. //namespace Otis
  47. //{
  48.  
  49. // textures
  50. texture   Otis_FragmentBuffer1  { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; MipLevels = 8; Format = Otis_RENDERMODE;}; 
  51. texture   Otis_FragmentBuffer2  { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; MipLevels = 8; Format = Otis_RENDERMODE;}; 
  52.  
  53. // samplers
  54. sampler2D Otis_SamplerFragmentBuffer2
  55. {
  56.     Texture = Otis_FragmentBuffer2;
  57.     MinFilter = LINEAR;
  58.     MagFilter = LINEAR;
  59.     MipFilter = LINEAR;
  60.     AddressU = Clamp;
  61.     AddressV = Clamp;
  62. };
  63.  
  64. sampler2D Otis_SamplerFragmentBuffer1
  65. {
  66.     Texture = Otis_FragmentBuffer1;
  67.     MinFilter = LINEAR;
  68.     MagFilter = LINEAR;
  69.     MipFilter = LINEAR;
  70.     AddressU = Clamp;
  71.     AddressV = Clamp;
  72. };
  73.  
  74. // general pixel shaders
  75. void PS_Otis_Init(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 colFragment : SV_Target0)
  76. {
  77.     colFragment = tex2D(ReShade::BackBuffer, texcoord.xy);
  78. }
  79.  
  80. float4 PS_Otis_Overlay(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
  81. {
  82.     return tex2D(Otis_SamplerFragmentBuffer2, texcoord.xy);
  83. }
  84.  
  85. // init technique to read the back buffer into the two fragment buffers. Disabled for now as they're not used
  86. /*
  87. technique Otis_Init_Tech  < enabled = false; >
  88. {
  89.     pass Init_Otis_FragmentBuffer2
  90.     {
  91.         VertexShader = ReShade::VS_PostProcess;        
  92.         PixelShader = PS_Otis_Init;
  93.         RenderTarget = Otis_FragmentBuffer2;
  94.     }
  95.     pass Init_Otis_FragmentBuffer1
  96.     {
  97.         VertexShader = ReShade::VS_PostProcess;        
  98.         PixelShader = PS_Otis_Init;
  99.         RenderTarget = Otis_FragmentBuffer1;
  100.     }
  101. }
  102. */
  103.  
  104. //}
  105.  
  106.  
  107. ///
  108.  
  109. //#if USE_ADAPTIVEFOG
  110.  
  111. //#pragma message "Adaptive Fog by Otis, with bloom code from CeeJay.\n"
  112.  
  113. //namespace Otis
  114. //{
  115.  
  116. //uniform bool Otis_MouseToggleKeyDown < source = "key"; keycode = MOL_ToggleKey; toggle = true; >;
  117.  
  118. // Two small 1x1 textures to preserve a value across frames. We need 2 as each target is cleared before it's bound so
  119. // we have to copy from 1 to 2 and then either read from 2 into 1 or read the new value.
  120. texture Otis_FogColorFromMouseTarget1 { Width=1; Height=1; Format= Otis_RENDERMODE;};
  121. sampler2D Otis_FogColorFromMouseSampler1 { Texture = Otis_FogColorFromMouseTarget1;};
  122. texture Otis_FogColorFromMouseTarget2 { Width=1; Height=1; Format= Otis_RENDERMODE;};
  123. sampler2D Otis_FogColorFromMouseSampler2 { Texture = Otis_FogColorFromMouseTarget2;};
  124.  
  125. texture   Otis_BloomTarget  { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = Otis_RENDERMODE;};
  126. sampler2D Otis_BloomSampler { Texture = Otis_BloomTarget; };
  127.  
  128. // pixel shader which performs bloom, by CeeJay.
  129. void PS_Otis_AFG_PerformBloom(float4 position : SV_Position, float2 texcoord : TEXCOORD0, out float4 fragment: SV_Target0)
  130. {
  131.     float4 color = tex2D(ReShade::BackBuffer, texcoord);
  132.     float3 BlurColor2 = 0;
  133.     float3 Blurtemp = 0;
  134.     float MaxDistance = 8*AFG_BloomWidth;
  135.     float CurDistance = 0;
  136.     float Samplecount = 25.0;
  137.     float2 blurtempvalue = texcoord * ReShade::PixelSize * AFG_BloomWidth;
  138.     float2 BloomSample = float2(2.5,-2.5);
  139.     float2 BloomSampleValue;
  140.    
  141.     for(BloomSample.x = (2.5); BloomSample.x > -2.0; BloomSample.x = BloomSample.x - 1.0)
  142.     {
  143.         BloomSampleValue.x = BloomSample.x * blurtempvalue.x;
  144.         float2 distancetemp = BloomSample.x * BloomSample.x * AFG_BloomWidth;
  145.        
  146.         for(BloomSample.y = (- 2.5); BloomSample.y < 2.0; BloomSample.y = BloomSample.y + 1.0)
  147.         {
  148.             distancetemp.y = BloomSample.y * BloomSample.y;
  149.             CurDistance = (distancetemp.y * AFG_BloomWidth) + distancetemp.x;
  150.             BloomSampleValue.y = BloomSample.y * blurtempvalue.y;
  151.             Blurtemp.rgb = tex2D(ReShade::BackBuffer, float2(texcoord + BloomSampleValue)).rgb;
  152.             BlurColor2.rgb += lerp(Blurtemp.rgb,color.rgb, sqrt(CurDistance / MaxDistance));
  153.         }
  154.     }
  155.     BlurColor2.rgb = (BlurColor2.rgb / (Samplecount - (AFG_BloomPower - AFG_BloomThreshold*5)));
  156.     float Bloomamount = (dot(color.rgb,float3(0.299f, 0.587f, 0.114f)));
  157.     float3 BlurColor = BlurColor2.rgb * (AFG_BloomPower + 4.0);
  158.     color.rgb = lerp(color.rgb,BlurColor.rgb, Bloomamount);
  159.     fragment = saturate(color);
  160. }
  161.  
  162.  
  163. void PS_Otis_AFG_BlendFogWithNormalBuffer(float4 vpos: SV_Position, float2 texcoord: TEXCOORD, out float4 fragment: SV_Target0)
  164. {
  165.     float depth = tex2D(ReShade::LinearizedDepth, texcoord).r;
  166.     depth = (depth * (1.0+AFG_FogStart)) - AFG_FogStart;
  167.     float4 bloomedFragment = tex2D(Otis_BloomSampler, texcoord);
  168.     float4 colorFragment = tex2D(ReShade::BackBuffer, texcoord);
  169.     float4 fogColor = float4(AFG_Color, 1.0);
  170. #if AFG_MouseDrivenFogColorSelect
  171.     fogColor = tex2D(Otis_FogColorFromMouseSampler1, float2(0,0));  //tex2Dfetch(Otis_FogColorFromMouseSampler, int2(0, 0)); //
  172. #endif
  173.     float fogFactor = clamp(depth * AFG_FogCurve, 0.0, AFG_MaxFogFactor);
  174.     float4 bloomedBlendedWithFogFragment = lerp(bloomedFragment, fogColor, fogFactor);
  175.     fragment = lerp(colorFragment, bloomedBlendedWithFogFragment, fogFactor);
  176. }
  177.  
  178.  
  179. void PS_Otis_AFG_CopyFogColorFrom1To2(float4 vpos: SV_Position, float2 texcoord: TEXCOORD, out float4 fragment: SV_Target0)
  180. {
  181.     fragment = tex2D(Otis_FogColorFromMouseSampler1, texcoord);
  182. }
  183.  
  184.  
  185. void PS_Otis_AFG_PerformGetFogColorFromFrameBuffer(float4 vpos: SV_Position, float2 texcoord: TEXCOORD, out float4 fragment: SV_Target0)
  186. {
  187.     fragment = Otis_MouseToggleKeyDown
  188.                 ? tex2D(ReShade::BackBuffer, ReShade::MouseCoords * ReShade::PixelSize)  // read new value
  189.                 : tex2D(Otis_FogColorFromMouseSampler2, float2(0,0)); // preserve old value
  190. }
  191.  
  192.  
  193. technique AdaptiveFog
  194. {
  195.     pass Otis_AFG_PassCopyOldFogValueFrom1To2
  196.     {
  197.         VertexShader = ReShade::VS_PostProcess;
  198.         PixelShader = PS_Otis_AFG_CopyFogColorFrom1To2;
  199.         RenderTarget = Otis_FogColorFromMouseTarget2;
  200.     }
  201.  
  202.     pass Otis_AFG_PassFogColorFromMouse
  203.     {
  204.         VertexShader = ReShade::VS_PostProcess;
  205.         PixelShader = PS_Otis_AFG_PerformGetFogColorFromFrameBuffer;
  206.         RenderTarget = Otis_FogColorFromMouseTarget1;
  207.     }
  208.    
  209.     pass Otis_AFG_PassBloom0
  210.     {
  211.         VertexShader = ReShade::VS_PostProcess;
  212.         PixelShader = PS_Otis_AFG_PerformBloom;
  213.         RenderTarget = Otis_BloomTarget;
  214.     }
  215.    
  216.     pass Otis_AFG_PassBlend
  217.     {
  218.         VertexShader = ReShade::VS_PostProcess;
  219.         PixelShader = PS_Otis_AFG_BlendFogWithNormalBuffer;
  220.     }
  221. }
  222. //}
  223.  
  224. //#endif
  225.  
  226. //#include EFFECT_CONFIG_UNDEF(Otis)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top