77
88RWStructuredBuffer<uint> _HistogramBuffer;
99Texture2D<float4> _Source;
10+ SamplerState sampler_LinearClamp;
1011
1112CBUFFER_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