@@ -67,19 +67,9 @@ CREATE_SAMPLER(SampleLumaTex, LumaTex, LINEAR, CLAMP)
67
67
/*
68
68
[Pixel Shaders]
69
69
---
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
73
71
*/
74
72
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
-
83
73
float2 Expand (float2 X)
84
74
{
85
75
return (X * 2.0 ) - 1.0 ;
@@ -108,14 +98,22 @@ float4 PS_Blit(VS2PS_Quad Input) : SV_TARGET0
108
98
// OutputColor0.rgb = Output the highest brightness out of red/green/blue component
109
99
// OutputColor0.a = Output the weight for temporal blending
110
100
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;
112
111
}
113
112
114
113
float3 PS_Exposure (VS2PS_Quad Input) : SV_TARGET0
115
114
{
116
- float AverageLuma = tex2Dlod (SampleLumaTex, float4 (Input.Tex0, 0.0 , 99.0 )).r;
117
115
float4 Color = tex2D (CShade_SampleColorTex, Input.Tex0);
118
- float3 ExposedColor = GetAutoExposure (Color.rgb, AverageLuma );
116
+ float3 ExposedColor = GetAutoExposure (Color.rgb, Input.Tex0 );
119
117
120
118
if (_Debug)
121
119
{
0 commit comments