Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////
- // Simple depth-based fog powered with bloom to fake light diffusion.
- // The bloom is borrowed from SweetFX's bloom by CeeJay.
- // Original shader by OtisLnf, Reshade 3 port by v00d00m4n
- ///////////////////////////////////////////////////////////////////
- #include "ReShade.fxh"
- //#include EFFECT_CONFIG(Otis)
- ////---------------//
- ///**ADAPTIVEFOG**///
- //---------------////
- #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.
- //>ADAPTIVE FOG General Settings<\\
- #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.
- #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.
- #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.
- #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.
- #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.
- #define AFG_ToggleKey RESHADE_TOGGLE_KEY //[undef] //-Key to toggle the effect on or off
- //>ADAPTIVE FOG Bloom Settings<\\
- #define AFG_BloomThreshold 2.25 //[0.00:50.00] //-Threshold for what is a bright light (that causes bloom) and what isn't.
- #define AFG_BloomPower 10.000 //[0.000:100.000] //-Strength of the bloom
- #define AFG_BloomWidth 0.3 //[0.0000:1.0000] //-Width of the bloom
- //#include "Common.fx"
- ///
- // Stuff all/most of Otis shared shaders need
- define HDR_MODE
- #if( HDR_MODE == 0)
- #define Otis_RENDERMODE RGBA8
- #elif( HDR_MODE == 1)
- #define Otis_RENDERMODE RGBA16F
- #else
- #define Otis_RENDERMODE RGBA32F
- #endif
- //namespace Otis
- //{
- // textures
- texture Otis_FragmentBuffer1 { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; MipLevels = 8; Format = Otis_RENDERMODE;};
- texture Otis_FragmentBuffer2 { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; MipLevels = 8; Format = Otis_RENDERMODE;};
- // samplers
- sampler2D Otis_SamplerFragmentBuffer2
- {
- Texture = Otis_FragmentBuffer2;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = Clamp;
- AddressV = Clamp;
- };
- sampler2D Otis_SamplerFragmentBuffer1
- {
- Texture = Otis_FragmentBuffer1;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = Clamp;
- AddressV = Clamp;
- };
- // general pixel shaders
- void PS_Otis_Init(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 colFragment : SV_Target0)
- {
- colFragment = tex2D(ReShade::BackBuffer, texcoord.xy);
- }
- float4 PS_Otis_Overlay(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
- {
- return tex2D(Otis_SamplerFragmentBuffer2, texcoord.xy);
- }
- // init technique to read the back buffer into the two fragment buffers. Disabled for now as they're not used
- /*
- technique Otis_Init_Tech < enabled = false; >
- {
- pass Init_Otis_FragmentBuffer2
- {
- VertexShader = ReShade::VS_PostProcess;
- PixelShader = PS_Otis_Init;
- RenderTarget = Otis_FragmentBuffer2;
- }
- pass Init_Otis_FragmentBuffer1
- {
- VertexShader = ReShade::VS_PostProcess;
- PixelShader = PS_Otis_Init;
- RenderTarget = Otis_FragmentBuffer1;
- }
- }
- */
- //}
- ///
- //#if USE_ADAPTIVEFOG
- //#pragma message "Adaptive Fog by Otis, with bloom code from CeeJay.\n"
- //namespace Otis
- //{
- //uniform bool Otis_MouseToggleKeyDown < source = "key"; keycode = MOL_ToggleKey; toggle = true; >;
- // Two small 1x1 textures to preserve a value across frames. We need 2 as each target is cleared before it's bound so
- // we have to copy from 1 to 2 and then either read from 2 into 1 or read the new value.
- texture Otis_FogColorFromMouseTarget1 { Width=1; Height=1; Format= Otis_RENDERMODE;};
- sampler2D Otis_FogColorFromMouseSampler1 { Texture = Otis_FogColorFromMouseTarget1;};
- texture Otis_FogColorFromMouseTarget2 { Width=1; Height=1; Format= Otis_RENDERMODE;};
- sampler2D Otis_FogColorFromMouseSampler2 { Texture = Otis_FogColorFromMouseTarget2;};
- texture Otis_BloomTarget { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = Otis_RENDERMODE;};
- sampler2D Otis_BloomSampler { Texture = Otis_BloomTarget; };
- // pixel shader which performs bloom, by CeeJay.
- void PS_Otis_AFG_PerformBloom(float4 position : SV_Position, float2 texcoord : TEXCOORD0, out float4 fragment: SV_Target0)
- {
- float4 color = tex2D(ReShade::BackBuffer, texcoord);
- float3 BlurColor2 = 0;
- float3 Blurtemp = 0;
- float MaxDistance = 8*AFG_BloomWidth;
- float CurDistance = 0;
- float Samplecount = 25.0;
- float2 blurtempvalue = texcoord * ReShade::PixelSize * AFG_BloomWidth;
- float2 BloomSample = float2(2.5,-2.5);
- float2 BloomSampleValue;
- for(BloomSample.x = (2.5); BloomSample.x > -2.0; BloomSample.x = BloomSample.x - 1.0)
- {
- BloomSampleValue.x = BloomSample.x * blurtempvalue.x;
- float2 distancetemp = BloomSample.x * BloomSample.x * AFG_BloomWidth;
- for(BloomSample.y = (- 2.5); BloomSample.y < 2.0; BloomSample.y = BloomSample.y + 1.0)
- {
- distancetemp.y = BloomSample.y * BloomSample.y;
- CurDistance = (distancetemp.y * AFG_BloomWidth) + distancetemp.x;
- BloomSampleValue.y = BloomSample.y * blurtempvalue.y;
- Blurtemp.rgb = tex2D(ReShade::BackBuffer, float2(texcoord + BloomSampleValue)).rgb;
- BlurColor2.rgb += lerp(Blurtemp.rgb,color.rgb, sqrt(CurDistance / MaxDistance));
- }
- }
- BlurColor2.rgb = (BlurColor2.rgb / (Samplecount - (AFG_BloomPower - AFG_BloomThreshold*5)));
- float Bloomamount = (dot(color.rgb,float3(0.299f, 0.587f, 0.114f)));
- float3 BlurColor = BlurColor2.rgb * (AFG_BloomPower + 4.0);
- color.rgb = lerp(color.rgb,BlurColor.rgb, Bloomamount);
- fragment = saturate(color);
- }
- void PS_Otis_AFG_BlendFogWithNormalBuffer(float4 vpos: SV_Position, float2 texcoord: TEXCOORD, out float4 fragment: SV_Target0)
- {
- float depth = tex2D(ReShade::LinearizedDepth, texcoord).r;
- depth = (depth * (1.0+AFG_FogStart)) - AFG_FogStart;
- float4 bloomedFragment = tex2D(Otis_BloomSampler, texcoord);
- float4 colorFragment = tex2D(ReShade::BackBuffer, texcoord);
- float4 fogColor = float4(AFG_Color, 1.0);
- #if AFG_MouseDrivenFogColorSelect
- fogColor = tex2D(Otis_FogColorFromMouseSampler1, float2(0,0)); //tex2Dfetch(Otis_FogColorFromMouseSampler, int2(0, 0)); //
- #endif
- float fogFactor = clamp(depth * AFG_FogCurve, 0.0, AFG_MaxFogFactor);
- float4 bloomedBlendedWithFogFragment = lerp(bloomedFragment, fogColor, fogFactor);
- fragment = lerp(colorFragment, bloomedBlendedWithFogFragment, fogFactor);
- }
- void PS_Otis_AFG_CopyFogColorFrom1To2(float4 vpos: SV_Position, float2 texcoord: TEXCOORD, out float4 fragment: SV_Target0)
- {
- fragment = tex2D(Otis_FogColorFromMouseSampler1, texcoord);
- }
- void PS_Otis_AFG_PerformGetFogColorFromFrameBuffer(float4 vpos: SV_Position, float2 texcoord: TEXCOORD, out float4 fragment: SV_Target0)
- {
- fragment = Otis_MouseToggleKeyDown
- ? tex2D(ReShade::BackBuffer, ReShade::MouseCoords * ReShade::PixelSize) // read new value
- : tex2D(Otis_FogColorFromMouseSampler2, float2(0,0)); // preserve old value
- }
- technique AdaptiveFog
- {
- pass Otis_AFG_PassCopyOldFogValueFrom1To2
- {
- VertexShader = ReShade::VS_PostProcess;
- PixelShader = PS_Otis_AFG_CopyFogColorFrom1To2;
- RenderTarget = Otis_FogColorFromMouseTarget2;
- }
- pass Otis_AFG_PassFogColorFromMouse
- {
- VertexShader = ReShade::VS_PostProcess;
- PixelShader = PS_Otis_AFG_PerformGetFogColorFromFrameBuffer;
- RenderTarget = Otis_FogColorFromMouseTarget1;
- }
- pass Otis_AFG_PassBloom0
- {
- VertexShader = ReShade::VS_PostProcess;
- PixelShader = PS_Otis_AFG_PerformBloom;
- RenderTarget = Otis_BloomTarget;
- }
- pass Otis_AFG_PassBlend
- {
- VertexShader = ReShade::VS_PostProcess;
- PixelShader = PS_Otis_AFG_BlendFogWithNormalBuffer;
- }
- }
- //}
- //#endif
- //#include EFFECT_CONFIG_UNDEF(Otis)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement