@@ -975,7 +975,6 @@ class RenderSSRPassData
975975
976976 public bool transparentSSR ;
977977 public bool usePBRAlgo ;
978- public bool accumNeedClear ;
979978 public bool previousAccumNeedClear ;
980979 public bool validColorPyramid ;
981980
@@ -993,7 +992,6 @@ class RenderSSRPassData
993992 public TextureHandle stencilBuffer ;
994993 public TextureHandle hitPointsTexture ;
995994 public TextureHandle ssrAccum ;
996- public TextureHandle lightingTexture ;
997995 public TextureHandle ssrAccumPrev ;
998996 public TextureHandle clearCoatMask ;
999997
@@ -1027,7 +1025,7 @@ static void ClearColorBuffer2D(RenderSSRPassData data, CommandBuffer cmd, Textur
10271025 }
10281026 else
10291027 {
1030- cmd . SetComputeTextureParam ( data . clearBuffer2DCS , data . clearBuffer2DKernel , HDShaderIDs . _Buffer2D , data . ssrAccum ) ;
1028+ cmd . SetComputeTextureParam ( data . clearBuffer2DCS , data . clearBuffer2DKernel , HDShaderIDs . _Buffer2D , rt ) ;
10311029 cmd. SetComputeVectorParam ( data . clearBuffer2DCS , HDShaderIDs . _ClearValue , clearColor ) ;
10321030 cmd. SetComputeVectorParam ( data . clearBuffer2DCS , HDShaderIDs . _BufferSize , new Vector4 ( ( float ) data . width , ( float ) data . height , 0.0f , 0.0f ) ) ;
10331031 cmd. DispatchCompute ( data . clearBuffer2DCS , data . clearBuffer2DKernel , HDUtils . DivRoundUp ( data . width , 8 ) , HDUtils . DivRoundUp ( data . height , 8 ) , data . viewCount ) ;
@@ -1128,12 +1126,12 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
11281126 bool useAsync = hdCamera . frameSettings . SSRRunsAsync ( ) && ! transparent ;
11291127 builder . EnableAsyncCompute ( useAsync ) ;
11301128
1131- hdCamera . AllocateScreenSpaceAccumulationHistoryBuffer ( 1.0f ) ;
1132-
11331129 bool usePBRAlgo = ! transparent && settings . usedAlgorithm . value == ScreenSpaceReflectionAlgorithm . PBRAccumulation ;
11341130 var colorPyramid = renderGraph . ImportTexture ( colorPyramidRT ) ;
11351131 var volumeSettings = hdCamera . volumeStack . GetComponent < ScreenSpaceReflection > ( ) ;
11361132
1133+ hdCamera . AllocateScreenSpaceAccumulationHistoryBuffer ( 1.0f ) ;
1134+
11371135 UpdateSSRConstantBuffer ( hdCamera , volumeSettings , transparent , ref passData . cb ) ;
11381136
11391137 passData . hdCamera = hdCamera ;
@@ -1167,8 +1165,7 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
11671165 passData . height = hdCamera . actualHeight ;
11681166 passData . viewCount = hdCamera . viewCount ;
11691167 passData . offsetBufferData = hdCamera . depthBufferMipChainInfo . GetOffsetBufferData ( m_DepthPyramidMipLevelOffsetsBuffer ) ;
1170- passData . accumNeedClear = usePBRAlgo ;
1171- passData . previousAccumNeedClear = usePBRAlgo && ( hdCamera . currentSSRAlgorithm == ScreenSpaceReflectionAlgorithm . Approximation || hdCamera . isFirstFrame || hdCamera . resetPostProcessingHistory ) ;
1168+ passData . previousAccumNeedClear = usePBRAlgo && ( hdCamera . isFirstFrame || hdCamera . resetPostProcessingHistory ) ;
11721169 hdCamera . currentSSRAlgorithm = volumeSettings . usedAlgorithm . value ; // Store for next frame comparison
11731170 passData . validColorPyramid = hdCamera . colorPyramidHistoryValidFrames > 1 ;
11741171
@@ -1204,42 +1201,45 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
12041201 // In practice, these textures are sparse (mostly black). Therefore, clearing them is fast (due to CMASK),
12051202 // and much faster than fully overwriting them from within SSR shaders.
12061203 passData . hitPointsTexture = builder . CreateTransientTexture ( new TextureDesc ( Vector2 . one , true , true )
1207- { colorFormat = GraphicsFormat . R16G16_UNorm , clearBuffer = true , clearColor = Color . clear , enableRandomWrite = true , name = transparent ? "SSR_Hit_Point_Texture_Trans" : "SSR_Hit_Point_Texture" } ) ;
1204+ { colorFormat = GraphicsFormat . R16G16_UNorm , clearBuffer = ! useAsync , clearColor = Color . clear , enableRandomWrite = true , name = transparent ? "SSR_Hit_Point_Texture_Trans" : "SSR_Hit_Point_Texture" } ) ;
12081205
12091206 if ( usePBRAlgo )
12101207 {
12111208 passData . ssrAccum = builder . WriteTexture ( renderGraph . ImportTexture ( hdCamera . GetCurrentFrameRT ( ( int ) HDCameraFrameHistoryType . ScreenSpaceReflectionAccumulation ) ) ) ;
12121209 passData . ssrAccumPrev = builder . WriteTexture ( renderGraph . ImportTexture ( hdCamera . GetPreviousFrameRT ( ( int ) HDCameraFrameHistoryType . ScreenSpaceReflectionAccumulation ) ) ) ;
1213- passData . lightingTexture = builder . CreateTransientTexture ( new TextureDesc ( Vector2 . one , true , true )
1214- { colorFormat = GraphicsFormat . R16G16B16A16_SFloat , clearBuffer = true , clearColor = Color . clear , enableRandomWrite = true , name = "SSR_Lighting_Texture" } ) ;
12151210 }
12161211 else
12171212 {
1218- passData . lightingTexture = builder . WriteTexture ( renderGraph . CreateTexture ( new TextureDesc ( Vector2 . one , true , true )
1219- { colorFormat = GraphicsFormat . R16G16B16A16_SFloat , clearBuffer = true , clearColor = Color . clear , enableRandomWrite = true , name = "SSR_Lighting_Texture" } ) ) ;
1213+ passData . ssrAccum = builder . WriteTexture ( renderGraph . CreateTexture ( new TextureDesc ( Vector2 . one , true , true )
1214+ { colorFormat = GraphicsFormat . R16G16B16A16_SFloat , clearBuffer = ! useAsync , clearColor = Color . clear , enableRandomWrite = true , name = "SSR_Lighting_Texture" } ) ) ;
12201215 }
12211216
12221217 builder . SetRenderFunc (
12231218 ( RenderSSRPassData data , RenderGraphContext ctx ) =>
12241219 {
12251220 var cs = data . ssrCS ;
12261221
1227- if ( ! data . usePBRAlgo )
1228- ctx . cmd . EnableShaderKeyword ( "SSR_APPROX" ) ;
1229- else
1222+ CoreUtils . SetKeyword ( ctx . cmd , "SSR_APPROX" , ! data . usePBRAlgo ) ;
1223+ CoreUtils . SetKeyword ( ctx . cmd , "DEPTH_SOURCE_NOT_FROM_MIP_CHAIN" , data . transparentSSR ) ;
1224+
1225+ if ( data . usePBRAlgo )
12301226 {
1231- if ( data . accumNeedClear || data . debugDisplaySpeed )
1232- ClearColorBuffer2D ( data , ctx . cmd , data . ssrAccum , Color . clear , data . useAsync ) ;
1227+ ClearColorBuffer2D ( data , ctx . cmd , data . ssrAccum , Color . clear , data . useAsync ) ;
1228+
12331229 if ( data . previousAccumNeedClear || data . debugDisplaySpeed )
12341230 ClearColorBuffer2D ( data , ctx . cmd , data . ssrAccumPrev , Color . clear , data . useAsync ) ;
1235-
1236- ctx . cmd . DisableShaderKeyword ( "SSR_APPROX" ) ;
1231+ }
1232+ else if ( data . useAsync )
1233+ {
1234+ // If the pass is synchronous, clear is done when the accumulation texture is created
1235+ ClearColorBuffer2D ( data , ctx . cmd , data . ssrAccum , Color . clear , data . useAsync ) ;
12371236 }
12381237
1239- if ( data . transparentSSR )
1240- ctx . cmd . EnableShaderKeyword ( "DEPTH_SOURCE_NOT_FROM_MIP_CHAIN" ) ;
1241- else
1242- ctx . cmd . DisableShaderKeyword ( "DEPTH_SOURCE_NOT_FROM_MIP_CHAIN" ) ;
1238+ if ( data . useAsync )
1239+ {
1240+ // If the pass is synchronous, clear is done when the hit point texture is created
1241+ ClearColorBuffer2D ( data , ctx . cmd , data . hitPointsTexture , Color . clear , data . useAsync ) ;
1242+ }
12431243
12441244 using ( new ProfilingScope ( ctx . cmd , ProfilingSampler . Get ( HDProfileId . SsrTracing ) ) )
12451245 {
@@ -1276,7 +1276,7 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
12761276 ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _ColorPyramidTexture , data . colorPyramid ) ;
12771277 ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _NormalBufferTexture , data . normalBuffer ) ;
12781278 ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _SsrHitPointTexture , data . hitPointsTexture ) ;
1279- ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _SSRAccumTexture , data . usePBRAlgo ? data . ssrAccum : data . lightingTexture ) ;
1279+ ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _SSRAccumTexture , data . ssrAccum ) ;
12801280 ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _SsrClearCoatMaskTexture , data . clearCoatMask ) ;
12811281 ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _CameraMotionVectorsTexture , data . motionVectorsBuffer ) ;
12821282
@@ -1370,7 +1370,6 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
13701370 ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _ColorPyramidTexture , data . colorPyramid ) ;
13711371 ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _SsrHitPointTexture , data . hitPointsTexture ) ;
13721372 ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _SSRAccumTexture , data . ssrAccum ) ;
1373- ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _SsrLightingTextureRW , data . lightingTexture ) ;
13741373 ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _SsrAccumPrev , data . ssrAccumPrev ) ;
13751374 ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _SsrClearCoatMaskTexture , data . clearCoatMask ) ;
13761375 ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _CameraMotionVectorsTexture , data . motionVectorsBuffer ) ;
@@ -1388,17 +1387,13 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
13881387
13891388 if ( usePBRAlgo )
13901389 {
1391- result = passData . ssrAccum ;
1392-
13931390 PushFullScreenDebugTexture ( renderGraph , passData . ssrAccum , FullScreenDebugMode . ScreenSpaceReflectionsAccum ) ;
13941391 PushFullScreenDebugTexture ( renderGraph , passData . ssrAccumPrev , FullScreenDebugMode . ScreenSpaceReflectionsPrev ) ;
1395- PushFullScreenDebugTexture ( renderGraph , passData . ssrAccum , FullScreenDebugMode . ScreenSpaceReflectionSpeedRejection ) ;
1396- }
1397- else
1398- {
1399- result = passData . lightingTexture ;
1400- PushFullScreenDebugTexture ( renderGraph , result , FullScreenDebugMode . ScreenSpaceReflectionSpeedRejection ) ;
14011392 }
1393+
1394+ PushFullScreenDebugTexture ( renderGraph , passData . ssrAccum , FullScreenDebugMode . ScreenSpaceReflectionSpeedRejection ) ;
1395+
1396+ result = passData . ssrAccum ;
14021397 }
14031398
14041399 if ( ! hdCamera . colorPyramidHistoryIsValid )
0 commit comments