@@ -257,6 +257,8 @@ void OnPreCull()
257257 // is switched off and the FOV or any other camera property changes.
258258 m_Camera . ResetProjectionMatrix ( ) ;
259259 m_Camera . nonJitteredProjectionMatrix = m_Camera . projectionMatrix ;
260+ if ( XR . XRSettings . isDeviceActive )
261+ m_Camera . ResetStereoProjectionMatrices ( ) ;
260262
261263 context . Reset ( ) ;
262264 context . camera = m_Camera ;
@@ -362,15 +364,142 @@ void OnPreCull()
362364 m_LegacyCmdBuffer . ReleaseTemporaryRT ( tempRt ) ;
363365 }
364366
367+ void OnPreRender ( )
368+ {
369+ // Unused in scriptable render pipelines
370+ // we only execute this for right eye
371+ if ( RuntimeUtilities . scriptableRenderPipelineActive ||
372+ ( m_Camera . stereoActiveEye != Camera . MonoOrStereoscopicEye . Right ) )
373+ return ;
374+
375+ var context = m_CurrentContext ;
376+ var sourceFormat = m_Camera . allowHDR ? RenderTextureFormat . DefaultHDR : RenderTextureFormat . Default ;
377+
378+ // Resets the projection matrix from previous frame in case TAA was enabled.
379+ // We also need to force reset the non-jittered projection matrix here as it's not done
380+ // when ResetProjectionMatrix() is called and will break transparent rendering if TAA
381+ // is switched off and the FOV or any other camera property changes.
382+ //m_Camera.ResetProjectionMatrix();
383+ //m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
384+
385+ context . Reset ( ) ;
386+ context . camera = m_Camera ;
387+ context . sourceFormat = sourceFormat ;
388+
389+ // TODO: I assume these are all executed for left eye before coming here
390+ m_LegacyCmdBufferBeforeReflections . Clear ( ) ;
391+ m_LegacyCmdBufferOpaque . Clear ( ) ;
392+ m_LegacyCmdBuffer . Clear ( ) ;
393+
394+ SetupContext ( context ) ;
395+
396+ // Lighting & opaque-only effects
397+ int opaqueOnlyEffects = 0 ;
398+ bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects ( context ) ;
399+ bool isAmbientOcclusionDeferred = ambientOcclusion . IsEnabledAndSupported ( context ) && ambientOcclusion . IsAmbientOnly ( context ) ;
400+ bool isAmbientOcclusionOpaque = ambientOcclusion . IsEnabledAndSupported ( context ) && ! ambientOcclusion . IsAmbientOnly ( context ) ;
401+ bool isFogActive = fog . IsEnabledAndSupported ( context ) ;
402+
403+ // Ambient-only AO is done in a separate command buffer, before reflections
404+ if ( isAmbientOcclusionDeferred )
405+ {
406+ context . command = m_LegacyCmdBufferBeforeReflections ;
407+ ambientOcclusion . RenderAmbientOnly ( context ) ;
408+ }
409+ else if ( isAmbientOcclusionOpaque )
410+ {
411+ opaqueOnlyEffects ++ ;
412+ }
413+
414+ opaqueOnlyEffects += isFogActive ? 1 : 0 ;
415+ opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0 ;
416+
417+ var cameraTarget = new RenderTargetIdentifier ( BuiltinRenderTextureType . CameraTarget ) ;
418+
419+ if ( opaqueOnlyEffects > 0 )
420+ {
421+ var cmd = m_LegacyCmdBufferOpaque ;
422+ context . command = cmd ;
423+
424+ // We need to use the internal Blit method to copy the camera target or it'll fail
425+ // on tiled GPU as it won't be able to resolve
426+ int tempTarget0 = m_TargetPool . Get ( ) ;
427+ cmd . GetTemporaryRT ( tempTarget0 , context . width , context . height , 24 , FilterMode . Bilinear , sourceFormat ) ;
428+ cmd . Blit ( cameraTarget , tempTarget0 ) ;
429+ context . source = tempTarget0 ;
430+
431+ int tempTarget1 = - 1 ;
432+
433+ if ( opaqueOnlyEffects > 1 )
434+ {
435+ tempTarget1 = m_TargetPool . Get ( ) ;
436+ cmd . GetTemporaryRT ( tempTarget1 , context . width , context . height , 24 , FilterMode . Bilinear , sourceFormat ) ;
437+ context . destination = tempTarget1 ;
438+ }
439+ else
440+ {
441+ context . destination = cameraTarget ;
442+ }
443+
444+ if ( isAmbientOcclusionOpaque )
445+ {
446+ ambientOcclusion . RenderAfterOpaque ( context ) ;
447+ opaqueOnlyEffects -- ;
448+ var prevSource = context . source ;
449+ context . source = context . destination ;
450+ context . destination = opaqueOnlyEffects == 1 ? cameraTarget : prevSource ;
451+ }
452+
453+ // TODO: Insert SSR here
454+
455+ if ( isFogActive )
456+ {
457+ fog . Render ( context ) ;
458+ opaqueOnlyEffects -- ;
459+ var prevSource = context . source ;
460+ context . source = context . destination ;
461+ context . destination = opaqueOnlyEffects == 1 ? cameraTarget : prevSource ;
462+ }
463+
464+ if ( hasCustomOpaqueOnlyEffects )
465+ {
466+ RenderOpaqueOnly ( context ) ;
467+ }
468+
469+ if ( opaqueOnlyEffects > 1 )
470+ cmd . ReleaseTemporaryRT ( tempTarget1 ) ;
471+
472+ cmd . ReleaseTemporaryRT ( tempTarget0 ) ;
473+ }
474+
475+ // Post-transparency stack
476+ // Same as before, first blit needs to use the builtin Blit command to properly handle
477+ // tiled GPUs
478+ int tempRt = m_TargetPool . Get ( ) ;
479+ m_LegacyCmdBuffer . GetTemporaryRT ( tempRt , context . width , context . height , 24 , FilterMode . Bilinear , sourceFormat ) ;
480+ m_LegacyCmdBuffer . Blit ( cameraTarget , tempRt , RuntimeUtilities . copyMaterial , stopNaNPropagation ? 3 : 2 ) ;
481+ m_NaNKilled = stopNaNPropagation ;
482+
483+ context . command = m_LegacyCmdBuffer ;
484+ context . source = tempRt ;
485+ context . destination = cameraTarget ;
486+ Render ( context ) ;
487+ m_LegacyCmdBuffer . ReleaseTemporaryRT ( tempRt ) ;
488+ }
489+
365490 void OnPostRender ( )
366- {
367- // Unused in scriptable render pipelines
368- if ( RuntimeUtilities . scriptableRenderPipelineActive )
369- return ;
370-
371- if ( m_CurrentContext . IsTemporalAntialiasingActive ( ) )
372- m_Camera . ResetProjectionMatrix ( ) ;
373- }
491+ {
492+ // Unused in scriptable render pipelines
493+ if ( RuntimeUtilities . scriptableRenderPipelineActive )
494+ return ;
495+
496+ if ( m_CurrentContext . IsTemporalAntialiasingActive ( ) )
497+ {
498+ m_Camera . ResetProjectionMatrix ( ) ;
499+ if ( XR . XRSettings . isDeviceActive )
500+ m_Camera . ResetStereoProjectionMatrices ( ) ;
501+ }
502+ }
374503
375504 PostProcessBundle GetBundle < T > ( )
376505 where T : PostProcessEffectSettings
@@ -544,10 +673,19 @@ public void Render(PostProcessRenderContext context)
544673 {
545674 if ( ! RuntimeUtilities . scriptableRenderPipelineActive )
546675 {
547- var camera = context . camera ;
548- camera . nonJitteredProjectionMatrix = camera . projectionMatrix ;
549- camera . projectionMatrix = temporalAntialiasing . GetJitteredProjectionMatrix ( camera ) ;
550- camera . useJitteredProjectionMatrixForTransparentRendering = false ;
676+ if ( XR . XRSettings . isDeviceActive )
677+ {
678+ // We only need to configure all of this once for stereo, during OnPreCull
679+ if ( context . camera . stereoActiveEye != Camera . MonoOrStereoscopicEye . Right )
680+ temporalAntialiasing . ConfiguredStereoJitteredProjectionMatrices ( context ) ;
681+ }
682+ else
683+ temporalAntialiasing . ConfiguredJitteredProjectionMatrix ( context ) ;
684+
685+ //var camera = context.camera;
686+ //camera.nonJitteredProjectionMatrix = camera.projectionMatrix;
687+ //camera.projectionMatrix = temporalAntialiasing.GetJitteredProjectionMatrix(camera);
688+ //camera.useJitteredProjectionMatrixForTransparentRendering = false;
551689 }
552690
553691 var taaTarget = m_TargetPool . Get ( ) ;
0 commit comments