@@ -16,24 +16,12 @@ public void Generate(PostProcessRenderContext context)
1616 {
1717 if ( data == null )
1818 data = new ComputeBuffer ( k_Bins , sizeof ( uint ) ) ;
19-
19+
20+ var scaleOffsetRes = GetHistogramScaleOffsetRes ( context ) ;
2021 var compute = context . resources . computeShaders . exposureHistogram ;
2122 var cmd = context . command ;
2223 cmd . BeginSample ( "LogHistogram" ) ;
2324
24- // Downscale the framebuffer, we don't need an absolute precision to compute the average
25- // luminance (and it'll make it a tiny bit more stable - bonus side-effect)
26- var scaleOffsetRes = GetHistogramScaleOffsetRes ( context ) ;
27-
28- cmd . GetTemporaryRT ( Uniforms . _AutoExposureCopyTex ,
29- ( int ) scaleOffsetRes . z ,
30- ( int ) scaleOffsetRes . w ,
31- 0 ,
32- FilterMode . Bilinear ,
33- context . sourceFormat
34- ) ;
35- cmd . BlitFullscreenTriangle ( context . source , Uniforms . _AutoExposureCopyTex ) ;
36-
3725 // Clear the buffer on every frame as we use it to accumulate luminance values on each frame
3826 int kernel = compute . FindKernel ( "KEyeHistogramClear" ) ;
3927 cmd . SetComputeBufferParam ( compute , kernel , "_HistogramBuffer" , data ) ;
@@ -42,17 +30,14 @@ public void Generate(PostProcessRenderContext context)
4230 // Get a log histogram
4331 kernel = compute . FindKernel ( "KEyeHistogram" ) ;
4432 cmd . SetComputeBufferParam ( compute , kernel , "_HistogramBuffer" , data ) ;
45- cmd . SetComputeTextureParam ( compute , kernel , "_Source" , Uniforms . _AutoExposureCopyTex ) ;
33+ cmd . SetComputeTextureParam ( compute , kernel , "_Source" , context . source ) ;
4634 cmd . SetComputeVectorParam ( compute , "_ScaleOffsetRes" , scaleOffsetRes ) ;
4735 cmd . DispatchCompute ( compute , kernel ,
4836 Mathf . CeilToInt ( scaleOffsetRes . z / ( float ) k_ThreadX ) ,
4937 Mathf . CeilToInt ( scaleOffsetRes . w / ( float ) k_ThreadY ) ,
5038 1
5139 ) ;
5240
53- // Cleanup
54- cmd . ReleaseTemporaryRT ( Uniforms . _AutoExposureCopyTex ) ;
55-
5641 cmd . EndSample ( "LogHistogram" ) ;
5742 }
5843
@@ -61,7 +46,7 @@ public Vector4 GetHistogramScaleOffsetRes(PostProcessRenderContext context)
6146 float diff = rangeMax - rangeMin ;
6247 float scale = 1f / diff ;
6348 float offset = - rangeMin * scale ;
64- return new Vector4 ( scale , offset , Mathf . Floor ( context . width / 2f ) , Mathf . Floor ( context . height / 2f ) ) ;
49+ return new Vector4 ( scale , offset , context . width , context . height ) ;
6550 }
6651
6752 public void Release ( )
0 commit comments