forked from crosire/reshade-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdaptiveFog.fx
126 lines (109 loc) · 4.53 KB
/
AdaptiveFog.fx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
///////////////////////////////////////////////////////////////////
// Simple depth-based fog powered with bloom to fake light diffusion.
// The bloom is borrowed from SweetFX's bloom by CeeJay.
//
// As Reshade 3 lets you tweak the parameters in-game, the mouse-oriented
// feature of the v2 Adaptive Fog is no longer needed: you can select the
// fog color in the reshade settings GUI instead.
//
///////////////////////////////////////////////////////////////////
// By Otis / Infuse Project
///////////////////////////////////////////////////////////////////
uniform float3 FogColor <
ui_type= "color";
ui_tooltip = "Color of the fog, in (red , green, blue)";
> = float3(0.9,0.9,0.9);
uniform float MaxFogFactor <
ui_type = "drag";
ui_min = 0.0; ui_max=1.0;
ui_tooltip = "The maximum fog factor. 1.0 makes distant objects completely fogged out, a lower factor will shimmer them through the fog.";
> = 0.8;
uniform float FogCurve <
ui_type = "drag";
ui_min = 0.0; ui_max=175.0;
ui_tooltip = "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.";
> = 1.5;
uniform float FogStart <
ui_type = "drag";
ui_min = 0.0; ui_max=1.0;
ui_tooltip = "Start of the fog. 0.0 is at the camera, 1.0 is at the horizon, 0.5 is halfway towards the horizon. Before this point no fog will appear.";
> = 0.05;
uniform float BloomThreshold <
ui_type = "drag";
ui_min = 0.00; ui_max=50.00;
ui_tooltip = "Threshold for what is a bright light (that causes bloom) and what isn't.";
> = 10.25;
uniform float BloomPower <
ui_type = "drag";
ui_min = 0.000; ui_max=100.000;
ui_tooltip = "Strength of the bloom";
> = 10.0;
uniform float BloomWidth <
ui_type = "drag";
ui_min = 0.0000; ui_max=1.0000;
ui_tooltip = "Width of the bloom";
> = 0.2;
#include "Reshade.fxh"
//////////////////////////////////////
// textures
//////////////////////////////////////
texture Otis_BloomTarget { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8;};
//////////////////////////////////////
// samplers
//////////////////////////////////////
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*BloomWidth;
float CurDistance = 0;
float Samplecount = 25.0;
float2 blurtempvalue = texcoord * ReShade::PixelSize * 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 * 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 * 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 - (BloomPower - BloomThreshold*5)));
float Bloomamount = (dot(color.rgb,float3(0.299f, 0.587f, 0.114f)));
float3 BlurColor = BlurColor2.rgb * (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 = ReShade::GetLinearizedDepth(texcoord).r;
depth = (depth * (1.0+FogStart)) - FogStart;
float4 bloomedFragment = tex2D(Otis_BloomSampler, texcoord);
float4 colorFragment = tex2D(ReShade::BackBuffer, texcoord);
float fogFactor = clamp(depth * FogCurve, 0.0, MaxFogFactor);
float4 bloomedBlendedWithFogFragment = lerp(bloomedFragment, float4(FogColor, 1.0), fogFactor);
fragment = lerp(colorFragment, bloomedBlendedWithFogFragment, fogFactor);
}
technique AdaptiveFog
{
pass Otis_AFG_PassBloom0
{
VertexShader = PostProcessVS;
PixelShader = PS_Otis_AFG_PerformBloom;
RenderTarget = Otis_BloomTarget;
}
pass Otis_AFG_PassBlend
{
VertexShader = PostProcessVS;
PixelShader = PS_Otis_AFG_BlendFogWithNormalBuffer;
}
}