forked from crosire/reshade-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilmicPass.fx
179 lines (146 loc) · 3.92 KB
/
FilmicPass.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
* FilmicPass
*
* Applies some common color adjustments to mimic a more cinema-like look.
*/
uniform float Strength <
ui_type = "drag";
ui_min = 0.05; ui_max = 1.5;
ui_toolip = "Strength of the color curve altering";
> = 0.85;
uniform float Fade <
ui_type = "drag";
ui_min = 0.0; ui_max = 0.6;
ui_tooltip = "Decreases contrast to imitate faded image";
> = 0.4;
uniform float Contrast <
ui_type = "drag";
ui_min = 0.5; ui_max = 2.0;
> = 1.0;
uniform float Linearization <
ui_type = "drag";
ui_min = 0.5; ui_max = 2.0;
> = 0.5;
uniform float Bleach <
ui_type = "drag";
ui_min = -0.5; ui_max = 1.0;
ui_tooltip = "More bleach means more contrasted and less colorful image";
> = 0.0;
uniform float Saturation <
ui_type = "drag";
ui_min = -1.0; ui_max = 1.0;
> = -0.15;
uniform float RedCurve <
ui_type = "drag";
ui_min = 0.0; ui_max = 2.0;
> = 1.0;
uniform float GreenCurve <
ui_type = "drag";
ui_min = 0.0; ui_max = 2.0;
> = 1.0;
uniform float BlueCurve <
ui_type = "drag";
ui_min = 0.0; ui_max = 2.0;
> = 1.0;
uniform float BaseCurve <
ui_type = "drag";
ui_min = 0.0; ui_max = 2.0;
> = 1.5;
uniform float BaseGamma <
ui_type = "drag";
ui_min = 0.7; ui_max = 2.0;
ui_tooltip = "Gamma Curve";
> = 1.0;
uniform float EffectGamma <
ui_type = "drag";
ui_min = 0.0; ui_max = 2.0;
> = 0.65;
uniform float EffectGammaR <
ui_type = "drag";
ui_min = 0.0; ui_max = 2.0;
> = 1.0;
uniform float EffectGammaG <
ui_type = "drag";
ui_min = 0.0; ui_max = 2.0;
> = 1.0;
uniform float EffectGammaB <
ui_type = "drag";
ui_min = 0.0; ui_max = 2.0;
> = 1.0;
uniform float3 LumCoeff <
> = float3(0.212656, 0.715158, 0.072186);
#include "ReShade.fxh"
float3 FilmPass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float3 B = tex2D(ReShade::BackBuffer, texcoord).rgb;
float3 G = B;
float3 H = 0.01;
B = saturate(B);
B = pow(B, Linearization);
B = lerp(H, B, Contrast);
float A = dot(B.rgb, LumCoeff);
float3 D = A;
B = pow(B, 1.0 / BaseGamma);
float a = RedCurve;
float b = GreenCurve;
float c = BlueCurve;
float d = BaseCurve;
float y = 1.0 / (1.0 + exp(a / 2.0));
float z = 1.0 / (1.0 + exp(b / 2.0));
float w = 1.0 / (1.0 + exp(c / 2.0));
float v = 1.0 / (1.0 + exp(d / 2.0));
float3 C = B;
D.r = (1.0 / (1.0 + exp(-a * (D.r - 0.5))) - y) / (1.0 - 2.0 * y);
D.g = (1.0 / (1.0 + exp(-b * (D.g - 0.5))) - z) / (1.0 - 2.0 * z);
D.b = (1.0 / (1.0 + exp(-c * (D.b - 0.5))) - w) / (1.0 - 2.0 * w);
D = pow(D, 1.0 / EffectGamma);
float3 Di = 1.0 - D;
D = lerp(D, Di, Bleach);
D.r = pow(abs(D.r), 1.0 / EffectGammaR);
D.g = pow(abs(D.g), 1.0 / EffectGammaG);
D.b = pow(abs(D.b), 1.0 / EffectGammaB);
if (D.r < 0.5)
C.r = (2.0 * D.r - 1.0) * (B.r - B.r * B.r) + B.r;
else
C.r = (2.0 * D.r - 1.0) * (sqrt(B.r) - B.r) + B.r;
if (D.g < 0.5)
C.g = (2.0 * D.g - 1.0) * (B.g - B.g * B.g) + B.g;
else
C.g = (2.0 * D.g - 1.0) * (sqrt(B.g) - B.g) + B.g;
if (D.b < 0.5)
C.b = (2.0 * D.b - 1.0) * (B.b - B.b * B.b) + B.b;
else
C.b = (2.0 * D.b - 1.0) * (sqrt(B.b) - B.b) + B.b;
float3 F = lerp(B, C, Strength);
F = (1.0 / (1.0 + exp(-d * (F - 0.5))) - v) / (1.0 - 2.0 * v);
float r2R = 1.0 - Saturation;
float g2R = 0.0 + Saturation;
float b2R = 0.0 + Saturation;
float r2G = 0.0 + Saturation;
float g2G = (1.0 - Fade) - Saturation;
float b2G = (0.0 + Fade) + Saturation;
float r2B = 0.0 + Saturation;
float g2B = (0.0 + Fade) + Saturation;
float b2B = (1.0 - Fade) - Saturation;
float3 iF = F;
F.r = (iF.r * r2R + iF.g * g2R + iF.b * b2R);
F.g = (iF.r * r2G + iF.g * g2G + iF.b * b2G);
F.b = (iF.r * r2B + iF.g * g2B + iF.b * b2B);
float N = dot(F.rgb, LumCoeff);
float3 Cn = F;
if (N < 0.5)
Cn = (2.0 * N - 1.0) * (F - F * F) + F;
else
Cn = (2.0 * N - 1.0) * (sqrt(F) - F) + F;
Cn = pow(max(Cn,0), 1.0 / Linearization);
float3 Fn = lerp(B, Cn, Strength);
return Fn;
}
technique FilmicPass
{
pass
{
VertexShader = PostProcessVS;
PixelShader = FilmPass;
}
}