-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathReinhard.fx
110 lines (88 loc) · 2.81 KB
/
Reinhard.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
// Reshade port of Reinhard tonemap
// Based on code from John Hable's and Tom Madams' blogs at http://filmicworlds.com/blog/filmic-tonemapping-operators/ and https://imdoingitwrong.wordpress.com/2010/08/19/why-reinhard-desaturates-my-blacks-3/ respectively
// by Jace Regenbrecht
uniform bool R_Lum <
ui_label = "Use luminance";
ui_tooltip = "Calculate tone based off each pixel's luminance value vs the RGB value.";
> = false;
uniform bool R_Simple <
ui_label = "Simple Equation";
ui_tooltip = "Use the simplistic Reinhard equation (doesn't support white point but is moderately cheaper computationally).";
> = false;
uniform float R_W <
ui_type = "drag";
ui_min = 0.00; ui_max = 20.00;
ui_label = "Linear White Point Value";
> = 5.0;
uniform float R_Exp <
ui_type = "drag";
ui_min = 1.00; ui_max = 20.00;
ui_label = "Exposure";
> = 1.0;
uniform float R_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 ReinhardSimple(float3 x)
{
return x/(1+x);
}
float3 ReinhardComplex(float3 x, float white)
{
return (x*(1+(x/pow(white, 2))))/(1+x);
}
float3 Reinhard_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( R_Gamma > 1.00 )
texColor = pow(texColor,R_Gamma);
texColor *= R_Exp; // Exposure Adjustment
float3 processColor;
float lum;
// Determine if we're operating on luminance or RGB
if(R_Lum)
{
lum = 0.2126f * texColor[0] + 0.7152 * texColor[1] + 0.0722 * texColor[2];
processColor = float3(lum, 0, 0);
}
else
processColor = texColor;
// Run the tonemapping equations
if(R_Simple)
processColor = ReinhardSimple(processColor);
else
processColor = ReinhardComplex(processColor, R_W);
// Do luminance adjustments
if(R_Lum)
{
float lumScale = processColor / lum;
processColor = texColor * lumScale;
}
// Do the post-tonemapping gamma correction
if( R_Gamma > 1.00 )
texColor = pow(processColor,1/R_Gamma);
else
texColor = processColor;
return texColor;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
technique Reinhard
{
pass
{
VertexShader = PostProcessVS;
PixelShader = Reinhard_Tonemap_Main;
}
}