Skip to content

Commit c6ef8f2

Browse files
committed
Update cAutoExposure.fx
1 parent fbbbcd1 commit c6ef8f2

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

shaders/cAutoExposure.fx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,9 @@ CREATE_SAMPLER(SampleLumaTex, LumaTex, LINEAR, CLAMP)
6767
/*
6868
[Pixel Shaders]
6969
---
70-
TODO: Add average, spot, and center-weighted metering with adjustable radius and slope
71-
---
72-
AutoExposure(): https://knarkowicz.wordpress.com/2016/01/09/automatic-exposure/
70+
AutoExposure(): https://john-chapman.github.io/2017/08/23/dynamic-local-exposure.html
7371
*/
7472

75-
float3 GetAutoExposure(float3 Color, float Average)
76-
{
77-
// NOTE: KeyValue is an exposure compensation curve
78-
float KeyValue = 1.03 - (2.0 / (log10(Average + 1.0) + 2.0));
79-
float ExposureValue = log2(KeyValue / Average) + _ManualBias;
80-
return Color * exp2(ExposureValue);
81-
}
82-
8373
float2 Expand(float2 X)
8474
{
8575
return (X * 2.0) - 1.0;
@@ -108,14 +98,22 @@ float4 PS_Blit(VS2PS_Quad Input) : SV_TARGET0
10898
// OutputColor0.rgb = Output the highest brightness out of red/green/blue component
10999
// OutputColor0.a = Output the weight for temporal blending
110100
float Delay = 1e-3 * _Frametime;
111-
return float4(Color.rgb, saturate(Delay * _SmoothingSpeed));
101+
return float4(log(Color.rgb), saturate(Delay * _SmoothingSpeed));
102+
}
103+
104+
float3 GetAutoExposure(float3 Color, float2 Tex)
105+
{
106+
float LumaAverage = exp(tex2Dlod(SampleLumaTex, float4(Tex, 0.0, 99.0)).r);
107+
float Ev100 = log2(LumaAverage * 100.0 / 12.5);
108+
Ev100 -= _ManualBias; // optional manual bias
109+
float Exposure = 1.0 / (1.2 * exp2(Ev100));
110+
return Color * Exposure;
112111
}
113112

114113
float3 PS_Exposure(VS2PS_Quad Input) : SV_TARGET0
115114
{
116-
float AverageLuma = tex2Dlod(SampleLumaTex, float4(Input.Tex0, 0.0, 99.0)).r;
117115
float4 Color = tex2D(CShade_SampleColorTex, Input.Tex0);
118-
float3 ExposedColor = GetAutoExposure(Color.rgb, AverageLuma);
116+
float3 ExposedColor = GetAutoExposure(Color.rgb, Input.Tex0);
119117

120118
if (_Debug)
121119
{

0 commit comments

Comments
 (0)