-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenbadaptation.fx
130 lines (105 loc) · 2.52 KB
/
enbadaptation.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
/*
Magic ENB
*/
#include "enb_include/Common.hlsl"
//========//
//Uniforms//
//========//
/*
x: AdaptationMin.
y: AdaptationMax.
z: AdaptationSensitivity.
w: AdaptationTime multiplied by time elapsed.
*/
float4 AdaptationParameters;
float uSensitivity <
string UIName = "Sensitivity";
string UIWidget = "spinner";
float UIMin = 0.0;
float UIMax = 100.0;
> = 1.0;
float uCenterBias <
string UIName = "Center Bias";
string UIWidget = "spinner";
float UIMin = 0.0;
float UIMax = 10.0;
> = 0.0;
bool uOnlyClampInExterior <
string UIName = "Only Clamp in Exteriors";
> = true;
//========//
//Textures//
//========//
Texture2D TextureCurrent;
Texture2D TexturePrevious;
//=========//
//Functions//
//=========//
float2 get_pixel_size(float width) {
float rcp_width = 1.0 / width;
return float2(rcp_width, rcp_width * ScreenSize.z);
}
//=======//
//Shaders//
//=======//
float4 PS_Downsample(
float4 position : SV_POSITION,
float2 uv : TEXCOORD
) : SV_TARGET {
const float2 ps = get_pixel_size(256.0);
float3 color = 0.0;
[unroll]
for (int x = -8; x <= 8; ++x) {
[unroll]
for (int y = -8; y <= 8; ++y) {
color += TextureCurrent.Sample(sLinear, uv + ps * float2(x, y)).rgb;
}
}
color /= 16 * 16;
color *= uSensitivity;
float luma = get_luma_linear(color);
luma *= saturate(lerp(1.0, 1.0 - distance(uv, 0.5), uCenterBias));
return float4(luma.xxx, 1.0);
}
float4 PS_Adaptation(
float4 position : SV_POSITION,
float2 uv : TEXCOORD
) : SV_TARGET {
const float2 ps = get_pixel_size(16.0);
float luma = 0.0;
float luma_max = 0.0;
[unroll]
for (int x = -8; x <= 8; ++x) {
[unroll]
for (int y = -8; y <= 8; ++y) {
float pixel = TextureCurrent.Sample(sLinear, uv + ps * float2(x, y)).x;
luma += pixel;
luma_max = max(luma_max, pixel);
}
}
luma /= 16 * 16;
// Sensitivity
luma = lerp(luma, luma_max, AdaptationParameters.z);
// Time
float last = TexturePrevious.Sample(sPoint, uv).x;
luma = lerp(last, luma, AdaptationParameters.w);
// Min/Max
if (!uOnlyClampInExterior || EInteriorFactor == 0)
luma = clamp(luma, AdaptationParameters.x, AdaptationParameters.y);
return float4(luma.xxx, 1.0);
}
//==========//
//Techniques//
//==========//
technique11 Downsample {
pass {
SetVertexShader(CompileShader(vs_5_0, VS_PostProcess()));
SetPixelShader(CompileShader(ps_5_0, PS_Downsample()));
}
}
technique11 Draw {
pass {
SetVertexShader(CompileShader(vs_5_0, VS_PostProcess()));
SetPixelShader(CompileShader(ps_5_0, PS_Adaptation()));
}
}