Skip to content

Commit 4f1c053

Browse files
committed
Apply adjustable tonemapper for bloom and autoexposure
1 parent 9d3fe69 commit 4f1c053

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

shaders/cAutoExposure.fx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "shared/cMacros.fxh"
22
#include "shared/cGraphics.fxh"
3+
#include "shared/cTonemap.fxh"
34

45
/*
56
Automatic exposure shader using hardware blending
@@ -129,11 +130,11 @@ float3 PS_Exposure(VS2PS_Quad Input) : SV_TARGET0
129130
float3 Color1 = ExposedColor.rgb;
130131
float3 Color2 = lerp(Dot * 2.0, Color.rgb, Mask * 0.5);
131132

132-
return lerp(Color1, Color2, Mask).rgb;
133+
return lerp(ApplyTonemap(Color1), Color2, Mask).rgb;
133134
}
134135
else
135136
{
136-
return ExposedColor;
137+
return ApplyTonemap(ExposedColor);
137138
}
138139
}
139140

shaders/cBloom.fx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
11
#include "shared/cBuffers.fxh"
22
#include "shared/cGraphics.fxh"
3+
#include "shared/cTonemap.fxh"
34

45
/*
56
[Shader Options]
67
*/
78

89
uniform float _Threshold <
10+
ui_category = "Bloom";
911
ui_label = "Threshold";
1012
ui_type = "slider";
1113
ui_min = 0.0;
1214
ui_max = 1.0;
1315
> = 0.8;
1416

1517
uniform float _Smooth <
18+
ui_category = "Bloom";
1619
ui_label = "Smoothing";
1720
ui_type = "slider";
1821
ui_min = 0.0;
1922
ui_max = 1.0;
2023
> = 0.5;
2124

2225
uniform float _Saturation <
26+
ui_category = "Bloom";
2327
ui_label = "Saturation";
2428
ui_type = "slider";
2529
ui_min = 0.0;
2630
ui_max = 10.0;
2731
> = 1.0;
2832

2933
uniform float3 _ColorShift <
34+
ui_category = "Bloom";
3035
ui_label = "Color Shift (RGB)";
3136
ui_type = "color";
3237
ui_min = 0.0;
3338
ui_max = 1.0;
3439
> = 1.0;
3540

3641
uniform float _Intensity <
42+
ui_category = "Bloom";
3743
ui_label = "Intensity";
3844
ui_type = "slider";
3945
ui_min = 0.0;
@@ -275,7 +281,7 @@ float4 PS_Composite(VS2PS_Quad Input) : SV_TARGET0
275281
float3 BloomColor = tex2D(SampleTempTex1, Input.Tex0).rgb;
276282

277283
float4 Color = 1.0;
278-
Color.rgb = ToneMapACESFilmic(BaseColor + (BloomColor * _Intensity));
284+
Color.rgb = ApplyTonemap(BaseColor + (BloomColor * _Intensity));
279285
return Color;
280286
}
281287

shaders/shared/cTonemap.fxh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,27 @@
8080
return 0.5 * (D * SDR - sqrt(((D*D - 4.0*C*E) * SDR + 4.0*A*E-2.0*B*D) * SDR + B*B) - B) / (A - C * SDR);
8181
}
8282

83+
uniform int _OutputTonemapOperator <
84+
ui_category = "OUTPUT";
85+
ui_label = "Tonemap Operator";
86+
ui_tooltip = "Select a tonemap operator for the output";
87+
ui_type = "combo";
88+
ui_items = "Reinhard\0DirectX Graphics Sample\0ACES Filmic Approximation\0";
89+
> = 0;
90+
91+
float3 ApplyTonemap(float3 HDR)
92+
{
93+
switch (_OutputTonemapOperator)
94+
{
95+
case 0:
96+
return ApplyReinhardTonemap(HDR, 1.0);
97+
case 1:
98+
return ApplyNewToneMap(HDR);
99+
case 2:
100+
return ApplyToneMapACES(HDR);
101+
default:
102+
return HDR;
103+
}
104+
}
105+
83106
#endif

0 commit comments

Comments
 (0)