7
7
8
8
RWStructuredBuffer<uint> _HistogramBuffer;
9
9
Texture2D<float4> _Source;
10
+ SamplerState sampler_LinearClamp;
10
11
11
12
CBUFFER_START(Params)
12
13
float4 _ScaleOffsetRes; // x: scale, y: offset, z: width, w: height
@@ -29,25 +30,27 @@ void KEyeHistogram(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupThre
29
30
if (localThreadId < HISTOGRAM_BINS)
30
31
gs_histogram[localThreadId] = 0u;
31
32
33
+ float2 ipos = float2(dispatchThreadId) * 2.0;
34
+
32
35
GroupMemoryBarrierWithGroupSync();
33
36
34
37
// 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)
36
39
{
37
40
uint weight = 1u;
41
+ float2 sspos = ipos / _ScaleOffsetRes.zw;
38
42
39
43
// Vignette weighting to put more focus on what's in the center of the screen
40
44
#if USE_VIGNETTE_WEIGHTING
41
45
{
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);
44
47
float vfactor = saturate(1.0 - dot(d, d));
45
48
vfactor *= vfactor;
46
49
weight = (uint)(64.0 * vfactor);
47
50
}
48
51
#endif
49
52
50
- float3 color = _Source[dispatchThreadId]. xyz;
53
+ float3 color = _Source.SampleLevel(sampler_LinearClamp, sspos, 0.0). xyz; // Bilinear downsample 2x
51
54
float luminance = Luminance(color);
52
55
float logLuminance = GetHistogramBinFromLuminance(luminance, _ScaleOffsetRes.xy);
53
56
uint idx = (uint)(logLuminance * (HISTOGRAM_BINS - 1u));
0 commit comments