@@ -248,9 +248,6 @@ void OnPreCull()
248248 if ( RuntimeUtilities . scriptableRenderPipelineActive )
249249 return ;
250250
251- var context = m_CurrentContext ;
252- var sourceFormat = m_Camera . allowHDR ? RenderTextureFormat . DefaultHDR : RenderTextureFormat . Default ;
253-
254251 // Resets the projection matrix from previous frame in case TAA was enabled.
255252 // We also need to force reset the non-jittered projection matrix here as it's not done
256253 // when ResetProjectionMatrix() is called and will break transparent rendering if TAA
@@ -260,108 +257,7 @@ void OnPreCull()
260257 if ( XR . XRSettings . isDeviceActive )
261258 m_Camera . ResetStereoProjectionMatrices ( ) ;
262259
263- context . Reset ( ) ;
264- context . camera = m_Camera ;
265- context . sourceFormat = sourceFormat ;
266-
267- m_LegacyCmdBufferBeforeReflections . Clear ( ) ;
268- m_LegacyCmdBufferOpaque . Clear ( ) ;
269- m_LegacyCmdBuffer . Clear ( ) ;
270-
271- SetupContext ( context ) ;
272-
273- // Lighting & opaque-only effects
274- int opaqueOnlyEffects = 0 ;
275- bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects ( context ) ;
276- bool isAmbientOcclusionDeferred = ambientOcclusion . IsEnabledAndSupported ( context ) && ambientOcclusion . IsAmbientOnly ( context ) ;
277- bool isAmbientOcclusionOpaque = ambientOcclusion . IsEnabledAndSupported ( context ) && ! ambientOcclusion . IsAmbientOnly ( context ) ;
278- bool isFogActive = fog . IsEnabledAndSupported ( context ) ;
279-
280- // Ambient-only AO is done in a separate command buffer, before reflections
281- if ( isAmbientOcclusionDeferred )
282- {
283- context . command = m_LegacyCmdBufferBeforeReflections ;
284- ambientOcclusion . RenderAmbientOnly ( context ) ;
285- }
286- else if ( isAmbientOcclusionOpaque )
287- {
288- opaqueOnlyEffects ++ ;
289- }
290-
291- opaqueOnlyEffects += isFogActive ? 1 : 0 ;
292- opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0 ;
293-
294- var cameraTarget = new RenderTargetIdentifier ( BuiltinRenderTextureType . CameraTarget ) ;
295-
296- if ( opaqueOnlyEffects > 0 )
297- {
298- var cmd = m_LegacyCmdBufferOpaque ;
299- context . command = cmd ;
300-
301- // We need to use the internal Blit method to copy the camera target or it'll fail
302- // on tiled GPU as it won't be able to resolve
303- int tempTarget0 = m_TargetPool . Get ( ) ;
304- cmd . GetTemporaryRT ( tempTarget0 , context . width , context . height , 24 , FilterMode . Bilinear , sourceFormat ) ;
305- cmd . Blit ( cameraTarget , tempTarget0 ) ;
306- context . source = tempTarget0 ;
307-
308- int tempTarget1 = - 1 ;
309-
310- if ( opaqueOnlyEffects > 1 )
311- {
312- tempTarget1 = m_TargetPool . Get ( ) ;
313- cmd . GetTemporaryRT ( tempTarget1 , context . width , context . height , 24 , FilterMode . Bilinear , sourceFormat ) ;
314- context . destination = tempTarget1 ;
315- }
316- else
317- {
318- context . destination = cameraTarget ;
319- }
320-
321- if ( isAmbientOcclusionOpaque )
322- {
323- ambientOcclusion . RenderAfterOpaque ( context ) ;
324- opaqueOnlyEffects -- ;
325- var prevSource = context . source ;
326- context . source = context . destination ;
327- context . destination = opaqueOnlyEffects == 1 ? cameraTarget : prevSource ;
328- }
329-
330- // TODO: Insert SSR here
331-
332- if ( isFogActive )
333- {
334- fog . Render ( context ) ;
335- opaqueOnlyEffects -- ;
336- var prevSource = context . source ;
337- context . source = context . destination ;
338- context . destination = opaqueOnlyEffects == 1 ? cameraTarget : prevSource ;
339- }
340-
341- if ( hasCustomOpaqueOnlyEffects )
342- {
343- RenderOpaqueOnly ( context ) ;
344- }
345-
346- if ( opaqueOnlyEffects > 1 )
347- cmd . ReleaseTemporaryRT ( tempTarget1 ) ;
348-
349- cmd . ReleaseTemporaryRT ( tempTarget0 ) ;
350- }
351-
352- // Post-transparency stack
353- // Same as before, first blit needs to use the builtin Blit command to properly handle
354- // tiled GPUs
355- int tempRt = m_TargetPool . Get ( ) ;
356- m_LegacyCmdBuffer . GetTemporaryRT ( tempRt , context . width , context . height , 24 , FilterMode . Bilinear , sourceFormat ) ;
357- m_LegacyCmdBuffer . Blit ( cameraTarget , tempRt , RuntimeUtilities . copyMaterial , stopNaNPropagation ? 3 : 2 ) ;
358- m_NaNKilled = stopNaNPropagation ;
359-
360- context . command = m_LegacyCmdBuffer ;
361- context . source = tempRt ;
362- context . destination = cameraTarget ;
363- Render ( context ) ;
364- m_LegacyCmdBuffer . ReleaseTemporaryRT ( tempRt ) ;
260+ BuildCommandBuffers ( ) ;
365261 }
366262
367263 void OnPreRender ( )
@@ -372,9 +268,11 @@ void OnPreRender()
372268 ( m_Camera . stereoActiveEye != Camera . MonoOrStereoscopicEye . Right ) )
373269 return ;
374270
375- // Probably should re-factor everything below to share common code between OnPreCull
376- // and OnPreRender.
271+ BuildCommandBuffers ( ) ;
272+ }
377273
274+ void BuildCommandBuffers ( )
275+ {
378276 var context = m_CurrentContext ;
379277 var sourceFormat = m_Camera . allowHDR ? RenderTextureFormat . DefaultHDR : RenderTextureFormat . Default ;
380278
0 commit comments