-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUncharted2.fx
126 lines (101 loc) · 3.02 KB
/
Uncharted2.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
// Reshade port of Uncharted 2 tonemap
// Base code sourced from John Hable's blog at http://filmicworlds.com/blog/filmic-tonemapping-operators/
// by Jace Regenbrecht
uniform bool U2_Lum <
ui_label = "Use luminance";
ui_tooltip = "Calculate tone based off each pixel's luminance value vs the RGB value.";
> = false;
uniform float U2_A <
ui_type = "drag";
ui_min = 0.00; ui_max = 1.00;
ui_label = "Shoulder strength";
> = 0.22;
uniform float U2_B <
ui_type = "drag";
ui_min = 0.00; ui_max = 1.00;
ui_label = "Linear strength";
> = 0.30;
uniform float U2_C <
ui_type = "drag";
ui_min = 0.00; ui_max = 1.00;
ui_label = "Linear angle";
> = 0.10;
uniform float U2_D <
ui_type = "drag";
ui_min = 0.00; ui_max = 1.00;
ui_label = "Toe strength";
> = 0.20;
uniform float U2_E <
ui_type = "drag";
ui_min = 0.00; ui_max = 1.00;
ui_label = "Toe numerator";
> = 0.01;
uniform float U2_F <
ui_type = "drag";
ui_min = 0.00; ui_max = 1.00;
ui_label = "Toe denominator";
> = 0.22;
uniform float U2_W <
ui_type = "drag";
ui_min = 0.00; ui_max = 20.00;
ui_label = "Linear White Point Value";
> = 11.2;
uniform float U2_Exp <
ui_type = "drag";
ui_min = 1.00; ui_max = 20.00;
ui_label = "Exposure";
> = 1.0;
uniform float U2_Gamma <
ui_type = "drag";
ui_min = 1.00; ui_max = 3.00;
ui_label = "Gamma value";
ui_tooltip = "Most monitors/images use a value of 2.2. Setting this to 1 disables the inital color space conversion from gamma to linear.";
> = 2.2;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "ReShade.fxh"
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
float3 Uncharted2Tonemap(float3 x)
{
return ((x*(U2_A*x+U2_C*U2_B)+U2_D*U2_E)/(x*(U2_A*x+U2_B)+U2_D*U2_F))-U2_E/U2_F;
}
float3 Uncharted_Tonemap_Main(float4 pos : SV_Position, float2 texcoord : TexCoord ) : COLOR
{
float3 texColor = tex2D(ReShade::BackBuffer, texcoord ).rgb;
// Do inital de-gamma of the game image to ensure we're operating in the correct colour range.
if( U2_Gamma > 1.00 )
texColor = pow(texColor,U2_Gamma);
texColor *= U2_Exp; // Exposure Adjustment
float ExposureBias = 2.0f;
float3 curr;
// Do tonemapping on RGB or Luminance
if(!U2_Lum)
curr = Uncharted2Tonemap(ExposureBias*texColor);
else
{
float lum = 0.2126f * texColor[0] + 0.7152 * texColor[1] + 0.0722 * texColor[2];
float3 newLum = Uncharted2Tonemap(ExposureBias*lum);
float lumScale = newLum / lum;
curr = texColor*lumScale;
}
float3 whiteScale = 1.0f/Uncharted2Tonemap(U2_W);
float3 color = curr*whiteScale;
// Do the post-tonemapping gamma correction
if( U2_Gamma > 1.00 )
color = pow(color,1/U2_Gamma);
return color;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
technique Uncharted2
{
pass
{
VertexShader = PostProcessVS;
PixelShader = Uncharted_Tonemap_Main;
}
}