1
+
1
2
#include "shared/cBuffers.fxh"
2
3
#include "shared/cGraphics.fxh"
4
+ #include "shared/cCamera.fxh"
3
5
#include "shared/cTonemap.fxh"
4
6
5
7
/*
6
8
[Shader Options]
7
9
*/
8
10
11
+ uniform float _Frametime < source = "frametime" ; >;
12
+
9
13
uniform float _Threshold <
10
- ui_category = "Bloom " ;
14
+ ui_category = "Input Settings " ;
11
15
ui_label = "Threshold" ;
12
16
ui_type = "slider" ;
13
17
ui_min = 0.0 ;
14
18
ui_max = 1.0 ;
15
19
> = 0.8 ;
16
20
17
21
uniform float _Smooth <
18
- ui_category = "Bloom " ;
22
+ ui_category = "Input Settings " ;
19
23
ui_label = "Smoothing" ;
20
24
ui_type = "slider" ;
21
25
ui_min = 0.0 ;
22
26
ui_max = 1.0 ;
23
27
> = 0.5 ;
24
28
25
29
uniform float _Saturation <
26
- ui_category = "Bloom " ;
30
+ ui_category = "Input Settings " ;
27
31
ui_label = "Saturation" ;
28
32
ui_type = "slider" ;
29
33
ui_min = 0.0 ;
30
34
ui_max = 10.0 ;
31
35
> = 1.0 ;
32
36
33
37
uniform float3 _ColorShift <
34
- ui_category = "Bloom " ;
38
+ ui_category = "Input Settings " ;
35
39
ui_label = "Color Shift (RGB)" ;
36
40
ui_type = "color" ;
37
41
ui_min = 0.0 ;
38
42
ui_max = 1.0 ;
39
43
> = 1.0 ;
40
44
41
45
uniform float _Intensity <
42
- ui_category = "Bloom " ;
46
+ ui_category = "Input Settings " ;
43
47
ui_label = "Intensity" ;
44
48
ui_type = "slider" ;
45
49
ui_min = 0.0 ;
46
50
ui_max = 10.0 ;
47
- > = 5.0 ;
51
+ > = 1.0 ;
52
+
48
53
49
54
/*
50
55
[Textures & Samplers]
51
56
*/
52
57
58
+ #if USE_AUTOEXPOSURE
59
+ CREATE_TEXTURE (ExposureTex, int2 (1 , 1 ), R16F, 0 )
60
+ CREATE_SAMPLER (SampleExposureTex, ExposureTex, LINEAR, CLAMP )
61
+ #endif
62
+
53
63
CREATE_SAMPLER (SampleTempTex0, TempTex0_RGB10A2, LINEAR, CLAMP )
54
64
CREATE_SAMPLER (SampleTempTex1, TempTex1_RGBA16F, LINEAR, CLAMP )
55
65
CREATE_SAMPLER (SampleTempTex2, TempTex2_RGBA16F, LINEAR, CLAMP )
@@ -60,6 +70,7 @@ CREATE_SAMPLER(SampleTempTex6, TempTex6_RGBA16F, LINEAR, CLAMP)
60
70
CREATE_SAMPLER (SampleTempTex7, TempTex7_RGBA16F, LINEAR, CLAMP )
61
71
CREATE_SAMPLER (SampleTempTex8, TempTex8_RGBA16F, LINEAR, CLAMP )
62
72
73
+
63
74
/*
64
75
[Pixel Shaders]
65
76
---
@@ -82,8 +93,15 @@ float4 PS_Prefilter(VS2PS_Quad Input) : SV_TARGET0
82
93
{
83
94
const float Knee = mad (_Threshold, _Smooth, 1e-5 );
84
95
const float3 Curve = float3 (_Threshold - Knee, Knee * 2.0 , 0.25 / Knee);
96
+
85
97
float4 Color = tex2D (CShade_SampleColorTex, Input.Tex0);
86
98
99
+ #if USE_AUTOEXPOSURE
100
+ // Apply auto-exposure here
101
+ float Luma = tex2D (SampleExposureTex, Input.Tex0).r;
102
+ Color = ApplyAutoExposure (Color.rgb, Luma);
103
+ #endif
104
+
87
105
// Under-threshold
88
106
float Brightness = Med3 (Color.r, Color.g, Color.b);
89
107
float Response_Curve = clamp (Brightness - Curve.x, 0.0 , Curve.y);
@@ -220,9 +238,14 @@ CREATE_PS_DOWNSCALE(PS_Downscale6, SampleTempTex5, false)
220
238
CREATE_PS_DOWNSCALE (PS_Downscale7, SampleTempTex6, false )
221
239
CREATE_PS_DOWNSCALE (PS_Downscale8, SampleTempTex7, false )
222
240
223
- float4 GetPixelUpscale (VS2PS_Quad Input, sampler2D SampleSource)
241
+ float4 PS_GetExposure (VS2PS_Quad Input) : SV_TARGET0
224
242
{
243
+ float4 Color = tex2D (SampleTempTex8, Input.Tex0);
244
+ return CreateExposureTex (Color.rgb, _Frametime);
245
+ }
225
246
247
+ float4 GetPixelUpscale (VS2PS_Quad Input, sampler2D SampleSource)
248
+ {
226
249
// A0 B0 C0
227
250
// A1 B1 C1
228
251
// A2 B2 C2
@@ -265,16 +288,6 @@ CREATE_PS_UPSCALE(PS_Upscale3, SampleTempTex4)
265
288
CREATE_PS_UPSCALE (PS_Upscale2, SampleTempTex3)
266
289
CREATE_PS_UPSCALE (PS_Upscale1, SampleTempTex2)
267
290
268
- float3 ToneMapACESFilmic (float3 x)
269
- {
270
- float a = 2.51 ;
271
- float b = 0.03 ;
272
- float c = 2.43 ;
273
- float d = 0.59 ;
274
- float e = 0.14 ;
275
- return saturate ((x * (a * x + b)) / (x * (c * x + d) + e));
276
- }
277
-
278
291
float4 PS_Composite (VS2PS_Quad Input) : SV_TARGET0
279
292
{
280
293
float3 BaseColor = tex2D (CShade_SampleColorTex, Input.Tex0).rgb;
@@ -311,6 +324,22 @@ technique CShade_Bloom
311
324
CREATE_PASS (VS_Quad, PS_Downscale7, TempTex7_RGBA16F, FALSE )
312
325
CREATE_PASS (VS_Quad, PS_Downscale8, TempTex8_RGBA16F, FALSE )
313
326
327
+ #if USE_AUTOEXPOSURE
328
+ pass CreateExposureTex
329
+ {
330
+ ClearRenderTargets = FALSE ;
331
+ BlendEnable = TRUE ;
332
+ BlendOp = ADD ;
333
+ SrcBlend = SRCALPHA;
334
+ DestBlend = INVSRCALPHA;
335
+
336
+ VertexShader = VS_Quad;
337
+ PixelShader = PS_GetExposure;
338
+
339
+ RenderTarget0 = ExposureTex;
340
+ }
341
+ #endif
342
+
314
343
CREATE_PASS (VS_Quad, PS_Upscale7, TempTex7_RGBA16F, TRUE )
315
344
CREATE_PASS (VS_Quad, PS_Upscale6, TempTex6_RGBA16F, TRUE )
316
345
CREATE_PASS (VS_Quad, PS_Upscale5, TempTex5_RGBA16F, TRUE )
0 commit comments