Skip to content

Commit

Permalink
Apply adjustable tonemapper for bloom and autoexposure
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Jun 28, 2024
1 parent 9d3fe69 commit 4f1c053
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 3 additions & 2 deletions shaders/cAutoExposure.fx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "shared/cMacros.fxh"
#include "shared/cGraphics.fxh"
#include "shared/cTonemap.fxh"

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

return lerp(Color1, Color2, Mask).rgb;
return lerp(ApplyTonemap(Color1), Color2, Mask).rgb;
}
else
{
return ExposedColor;
return ApplyTonemap(ExposedColor);
}
}

Expand Down
8 changes: 7 additions & 1 deletion shaders/cBloom.fx
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
#include "shared/cBuffers.fxh"
#include "shared/cGraphics.fxh"
#include "shared/cTonemap.fxh"

/*
[Shader Options]
*/

uniform float _Threshold <
ui_category = "Bloom";
ui_label = "Threshold";
ui_type = "slider";
ui_min = 0.0;
ui_max = 1.0;
> = 0.8;

uniform float _Smooth <
ui_category = "Bloom";
ui_label = "Smoothing";
ui_type = "slider";
ui_min = 0.0;
ui_max = 1.0;
> = 0.5;

uniform float _Saturation <
ui_category = "Bloom";
ui_label = "Saturation";
ui_type = "slider";
ui_min = 0.0;
ui_max = 10.0;
> = 1.0;

uniform float3 _ColorShift <
ui_category = "Bloom";
ui_label = "Color Shift (RGB)";
ui_type = "color";
ui_min = 0.0;
ui_max = 1.0;
> = 1.0;

uniform float _Intensity <
ui_category = "Bloom";
ui_label = "Intensity";
ui_type = "slider";
ui_min = 0.0;
Expand Down Expand Up @@ -275,7 +281,7 @@ float4 PS_Composite(VS2PS_Quad Input) : SV_TARGET0
float3 BloomColor = tex2D(SampleTempTex1, Input.Tex0).rgb;

float4 Color = 1.0;
Color.rgb = ToneMapACESFilmic(BaseColor + (BloomColor * _Intensity));
Color.rgb = ApplyTonemap(BaseColor + (BloomColor * _Intensity));
return Color;
}

Expand Down
23 changes: 23 additions & 0 deletions shaders/shared/cTonemap.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,27 @@
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);
}

uniform int _OutputTonemapOperator <
ui_category = "OUTPUT";
ui_label = "Tonemap Operator";
ui_tooltip = "Select a tonemap operator for the output";
ui_type = "combo";
ui_items = "Reinhard\0DirectX Graphics Sample\0ACES Filmic Approximation\0";
> = 0;

float3 ApplyTonemap(float3 HDR)
{
switch (_OutputTonemapOperator)
{
case 0:
return ApplyReinhardTonemap(HDR, 1.0);
case 1:
return ApplyNewToneMap(HDR);
case 2:
return ApplyToneMapACES(HDR);
default:
return HDR;
}
}

#endif

0 comments on commit 4f1c053

Please sign in to comment.