Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 5e4d4eb

Browse files
committed
Optimized auto exposure (up to 4x)
At the cost of precision - the difference is minimal though and keeps the effect cost under 0.1ms at 1080p
1 parent 9a4d7fe commit 5e4d4eb

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

PostProcessing/Runtime/Utils/LogHistogram.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public void Generate(PostProcessRenderContext context)
3737
cmd.SetComputeTextureParam(compute, kernel, "_Source", context.source);
3838
cmd.SetComputeVectorParam(compute, "_ScaleOffsetRes", scaleOffsetRes);
3939
cmd.DispatchCompute(compute, kernel,
40-
Mathf.CeilToInt(scaleOffsetRes.z / m_ThreadX),
41-
Mathf.CeilToInt(scaleOffsetRes.w / m_ThreadY),
40+
Mathf.CeilToInt(scaleOffsetRes.z / 2f / m_ThreadX),
41+
Mathf.CeilToInt(scaleOffsetRes.w / 2f / m_ThreadY),
4242
1
4343
);
4444

PostProcessing/Shaders/Builtins/ExposureHistogram.compute

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
RWStructuredBuffer<uint> _HistogramBuffer;
99
Texture2D<float4> _Source;
10+
SamplerState sampler_LinearClamp;
1011

1112
CBUFFER_START(Params)
1213
float4 _ScaleOffsetRes; // x: scale, y: offset, z: width, w: height
@@ -29,25 +30,27 @@ void KEyeHistogram(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupThre
2930
if (localThreadId < HISTOGRAM_BINS)
3031
gs_histogram[localThreadId] = 0u;
3132

33+
float2 ipos = float2(dispatchThreadId) * 2.0;
34+
3235
GroupMemoryBarrierWithGroupSync();
3336

3437
// Gather local group histogram
35-
if (dispatchThreadId.x < (uint)_ScaleOffsetRes.z && dispatchThreadId.y < (uint)_ScaleOffsetRes.w)
38+
if (ipos.x < _ScaleOffsetRes.z && ipos.y < _ScaleOffsetRes.w)
3639
{
3740
uint weight = 1u;
41+
float2 sspos = ipos / _ScaleOffsetRes.zw;
3842

3943
// Vignette weighting to put more focus on what's in the center of the screen
4044
#if USE_VIGNETTE_WEIGHTING
4145
{
42-
float2 uv01 = float2(dispatchThreadId) / float2(_ScaleOffsetRes.z, _ScaleOffsetRes.w);
43-
float2 d = abs(uv01 - (0.5).xx);
46+
float2 d = abs(sspos - (0.5).xx);
4447
float vfactor = saturate(1.0 - dot(d, d));
4548
vfactor *= vfactor;
4649
weight = (uint)(64.0 * vfactor);
4750
}
4851
#endif
4952

50-
float3 color = _Source[dispatchThreadId].xyz;
53+
float3 color = _Source.SampleLevel(sampler_LinearClamp, sspos, 0.0).xyz; // Bilinear downsample 2x
5154
float luminance = Luminance(color);
5255
float logLuminance = GetHistogramBinFromLuminance(luminance, _ScaleOffsetRes.xy);
5356
uint idx = (uint)(logLuminance * (HISTOGRAM_BINS - 1u));

0 commit comments

Comments
 (0)