@@ -975,7 +975,6 @@ class RenderSSRPassData
975
975
976
976
public bool transparentSSR ;
977
977
public bool usePBRAlgo ;
978
- public bool accumNeedClear ;
979
978
public bool previousAccumNeedClear ;
980
979
public bool validColorPyramid ;
981
980
@@ -993,7 +992,6 @@ class RenderSSRPassData
993
992
public TextureHandle stencilBuffer ;
994
993
public TextureHandle hitPointsTexture ;
995
994
public TextureHandle ssrAccum ;
996
- public TextureHandle lightingTexture ;
997
995
public TextureHandle ssrAccumPrev ;
998
996
public TextureHandle clearCoatMask ;
999
997
@@ -1027,7 +1025,7 @@ static void ClearColorBuffer2D(RenderSSRPassData data, CommandBuffer cmd, Textur
1027
1025
}
1028
1026
else
1029
1027
{
1030
- cmd . SetComputeTextureParam ( data . clearBuffer2DCS , data . clearBuffer2DKernel , HDShaderIDs . _Buffer2D , data . ssrAccum ) ;
1028
+ cmd . SetComputeTextureParam ( data . clearBuffer2DCS , data . clearBuffer2DKernel , HDShaderIDs . _Buffer2D , rt ) ;
1031
1029
cmd. SetComputeVectorParam ( data . clearBuffer2DCS , HDShaderIDs . _ClearValue , clearColor ) ;
1032
1030
cmd. SetComputeVectorParam ( data . clearBuffer2DCS , HDShaderIDs . _BufferSize , new Vector4 ( ( float ) data . width , ( float ) data . height , 0.0f , 0.0f ) ) ;
1033
1031
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,
1128
1126
bool useAsync = hdCamera . frameSettings . SSRRunsAsync ( ) && ! transparent ;
1129
1127
builder . EnableAsyncCompute ( useAsync ) ;
1130
1128
1131
- hdCamera . AllocateScreenSpaceAccumulationHistoryBuffer ( 1.0f ) ;
1132
-
1133
1129
bool usePBRAlgo = ! transparent && settings . usedAlgorithm . value == ScreenSpaceReflectionAlgorithm . PBRAccumulation ;
1134
1130
var colorPyramid = renderGraph . ImportTexture ( colorPyramidRT ) ;
1135
1131
var volumeSettings = hdCamera . volumeStack . GetComponent < ScreenSpaceReflection > ( ) ;
1136
1132
1133
+ hdCamera . AllocateScreenSpaceAccumulationHistoryBuffer ( 1.0f ) ;
1134
+
1137
1135
UpdateSSRConstantBuffer ( hdCamera , volumeSettings , transparent , ref passData . cb ) ;
1138
1136
1139
1137
passData . hdCamera = hdCamera ;
@@ -1167,8 +1165,7 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
1167
1165
passData . height = hdCamera . actualHeight ;
1168
1166
passData . viewCount = hdCamera . viewCount ;
1169
1167
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 ) ;
1172
1169
hdCamera . currentSSRAlgorithm = volumeSettings . usedAlgorithm . value ; // Store for next frame comparison
1173
1170
passData . validColorPyramid = hdCamera . colorPyramidHistoryValidFrames > 1 ;
1174
1171
@@ -1204,42 +1201,45 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
1204
1201
// In practice, these textures are sparse (mostly black). Therefore, clearing them is fast (due to CMASK),
1205
1202
// and much faster than fully overwriting them from within SSR shaders.
1206
1203
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" } ) ;
1208
1205
1209
1206
if ( usePBRAlgo )
1210
1207
{
1211
1208
passData . ssrAccum = builder . WriteTexture ( renderGraph . ImportTexture ( hdCamera . GetCurrentFrameRT ( ( int ) HDCameraFrameHistoryType . ScreenSpaceReflectionAccumulation ) ) ) ;
1212
1209
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" } ) ;
1215
1210
}
1216
1211
else
1217
1212
{
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" } ) ) ;
1220
1215
}
1221
1216
1222
1217
builder . SetRenderFunc (
1223
1218
( RenderSSRPassData data , RenderGraphContext ctx ) =>
1224
1219
{
1225
1220
var cs = data . ssrCS ;
1226
1221
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 )
1230
1226
{
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
+
1233
1229
if ( data . previousAccumNeedClear || data . debugDisplaySpeed )
1234
1230
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 ) ;
1237
1236
}
1238
1237
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
+ }
1243
1243
1244
1244
using ( new ProfilingScope ( ctx . cmd , ProfilingSampler . Get ( HDProfileId . SsrTracing ) ) )
1245
1245
{
@@ -1276,7 +1276,7 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
1276
1276
ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _ColorPyramidTexture , data . colorPyramid ) ;
1277
1277
ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _NormalBufferTexture , data . normalBuffer ) ;
1278
1278
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 ) ;
1280
1280
ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _SsrClearCoatMaskTexture , data . clearCoatMask ) ;
1281
1281
ctx . cmd . SetComputeTextureParam ( cs , data . reprojectionKernel , HDShaderIDs . _CameraMotionVectorsTexture , data . motionVectorsBuffer ) ;
1282
1282
@@ -1370,7 +1370,6 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
1370
1370
ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _ColorPyramidTexture , data . colorPyramid ) ;
1371
1371
ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _SsrHitPointTexture , data . hitPointsTexture ) ;
1372
1372
ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _SSRAccumTexture , data . ssrAccum ) ;
1373
- ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _SsrLightingTextureRW , data . lightingTexture ) ;
1374
1373
ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _SsrAccumPrev , data . ssrAccumPrev ) ;
1375
1374
ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _SsrClearCoatMaskTexture , data . clearCoatMask ) ;
1376
1375
ctx . cmd . SetComputeTextureParam ( cs , pass , HDShaderIDs . _CameraMotionVectorsTexture , data . motionVectorsBuffer ) ;
@@ -1388,17 +1387,13 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
1388
1387
1389
1388
if ( usePBRAlgo )
1390
1389
{
1391
- result = passData . ssrAccum ;
1392
-
1393
1390
PushFullScreenDebugTexture ( renderGraph , passData . ssrAccum , FullScreenDebugMode . ScreenSpaceReflectionsAccum ) ;
1394
1391
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 ) ;
1401
1392
}
1393
+
1394
+ PushFullScreenDebugTexture ( renderGraph , passData . ssrAccum , FullScreenDebugMode . ScreenSpaceReflectionSpeedRejection ) ;
1395
+
1396
+ result = passData . ssrAccum ;
1402
1397
}
1403
1398
1404
1399
if ( ! hdCamera . colorPyramidHistoryIsValid )
0 commit comments