@@ -64,6 +64,15 @@ public static void PostCullBeginCameraRendering(RenderRequestBatcherContext cont
6464 s_Instance ? . batcher . PostCullBeginCameraRendering ( context ) ;
6565 }
6666
67+
68+ /// <summary>
69+ /// Utility function for updating probe data after global ambient probe is set up
70+ /// </summary>
71+ public static void OnSetupAmbientProbe ( )
72+ {
73+ s_Instance ? . batcher . OnSetupAmbientProbe ( ) ;
74+ }
75+
6776 /// <summary>
6877 /// Utility function to run an occlusion test in compute to update indirect draws.
6978 /// This function will dispatch compute shaders to run the given occlusion test and
@@ -445,8 +454,9 @@ private void Dispose()
445454
446455 private void OnSceneLoaded ( Scene scene , LoadSceneMode mode )
447456 {
457+ // Loaded scene might contain light probes that would affect existing objects. Hence we have to update all probes data.
448458 if ( mode == LoadSceneMode . Additive )
449- m_BatchersContext . UpdateAmbientProbeAndGpuBuffer ( RenderSettings . ambientProbe , true ) ;
459+ m_BatchersContext . UpdateAmbientProbeAndGpuBuffer ( forceUpdate : true ) ;
450460 }
451461
452462 private static void PostPostLateUpdateStatic ( )
@@ -540,22 +550,24 @@ private void OnEndCameraRendering(ScriptableRenderContext context, Camera camera
540550
541551 private void PostPostLateUpdate ( )
542552 {
553+ m_BatchersContext . UpdateAmbientProbeAndGpuBuffer ( forceUpdate : false ) ;
554+
543555 Profiler . BeginSample ( "GPUResidentDrawer.DispatchChanges" ) ;
544556 var lodGroupTransformData = m_Dispatcher . GetTransformChangesAndClear < LODGroup > ( TransformTrackingType . GlobalTRS , Allocator . TempJob ) ;
545557 var lodGroupData = m_Dispatcher . GetTypeChangesAndClear < LODGroup > ( Allocator . TempJob , noScriptingArray : true ) ;
546558 var meshDataSorted = m_Dispatcher . GetTypeChangesAndClear < Mesh > ( Allocator . TempJob , sortByInstanceID : true , noScriptingArray : true ) ;
547559 var materialData = m_Dispatcher . GetTypeChangesAndClear < Material > ( Allocator . TempJob , noScriptingArray : true ) ;
548560 Profiler . EndSample ( ) ;
549561
550- Profiler . BeginSample ( "GPUResindentDrawer .ProcessMaterials" ) ;
562+ Profiler . BeginSample ( "GPUResidentDrawer .ProcessMaterials" ) ;
551563 ProcessMaterials ( materialData . destroyedID ) ;
552564 Profiler . EndSample ( ) ;
553565
554- Profiler . BeginSample ( "GPUResindentDrawer .ProcessMeshes" ) ;
566+ Profiler . BeginSample ( "GPUResidentDrawer .ProcessMeshes" ) ;
555567 ProcessMeshes ( meshDataSorted . destroyedID ) ;
556568 Profiler . EndSample ( ) ;
557569
558- Profiler . BeginSample ( "GPUResindentDrawer .ProcessLODGroups" ) ;
570+ Profiler . BeginSample ( "GPUResidentDrawer .ProcessLODGroups" ) ;
559571 ProcessLODGroups ( lodGroupData . changedID , lodGroupData . destroyedID , lodGroupTransformData . transformedID ) ;
560572 Profiler . EndSample ( ) ;
561573
@@ -564,12 +576,11 @@ private void PostPostLateUpdate()
564576 meshDataSorted . Dispose ( ) ;
565577 materialData . Dispose ( ) ;
566578
567- Profiler . BeginSample ( "GPUResindentDrawer .ProcessDraws" ) ;
579+ Profiler . BeginSample ( "GPUResidentDrawer .ProcessDraws" ) ;
568580 m_MeshRendererDrawer . ProcessDraws ( ) ;
569581 // Add more drawers here ...
570582 Profiler . EndSample ( ) ;
571583
572- m_BatchersContext . UpdateAmbientProbeAndGpuBuffer ( RenderSettings . ambientProbe ) ;
573584 m_BatchersContext . UpdateInstanceMotions ( ) ;
574585
575586 m_Batcher . UpdateFrame ( ) ;
@@ -610,7 +621,7 @@ private void ProcessLODGroups(NativeArray<int> changedID, NativeArray<int> destr
610621
611622 internal void ProcessRenderers ( NativeArray < int > rendererGroupsID )
612623 {
613- Profiler . BeginSample ( "GPUResindentDrawer .ProcessMeshRenderers" ) ;
624+ Profiler . BeginSample ( "GPUResidentDrawer .ProcessMeshRenderers" ) ;
614625
615626 var changedInstances = new NativeArray < InstanceHandle > ( rendererGroupsID . Length , Allocator . TempJob , NativeArrayOptions . UninitializedMemory ) ;
616627 ScheduleQueryRendererGroupInstancesJob ( rendererGroupsID , changedInstances ) . Complete ( ) ;
@@ -624,7 +635,7 @@ internal void ProcessRenderers(NativeArray<int> rendererGroupsID)
624635
625636 internal void TransformInstances ( NativeArray < InstanceHandle > instances , NativeArray < Matrix4x4 > localToWorldMatrices )
626637 {
627- Profiler . BeginSample ( "GPUResindentDrawer .TransformInstances" ) ;
638+ Profiler . BeginSample ( "GPUResidentDrawer .TransformInstances" ) ;
628639
629640 m_BatchersContext . UpdateInstanceTransforms ( instances , localToWorldMatrices ) ;
630641
@@ -633,7 +644,7 @@ internal void TransformInstances(NativeArray<InstanceHandle> instances, NativeAr
633644
634645 internal void FreeInstances ( NativeArray < InstanceHandle > instances )
635646 {
636- Profiler . BeginSample ( "GPUResindentDrawer .FreeInstances" ) ;
647+ Profiler . BeginSample ( "GPUResidentDrawer .FreeInstances" ) ;
637648
638649 m_Batcher . DestroyInstances ( instances ) ;
639650 m_BatchersContext . FreeInstances ( instances ) ;
@@ -643,17 +654,9 @@ internal void FreeInstances(NativeArray<InstanceHandle> instances)
643654
644655 internal void FreeRendererGroupInstances ( NativeArray < int > rendererGroupIDs )
645656 {
646- if ( rendererGroupIDs . Length == 0 )
647- return ;
648-
649- Profiler . BeginSample ( "GPUResindentDrawer.FreeRendererGroupInstances" ) ;
650-
651- var instances = new NativeList < InstanceHandle > ( rendererGroupIDs . Length , Allocator . TempJob ) ;
652- ScheduleQueryRendererGroupInstancesJob ( rendererGroupIDs , instances ) . Complete ( ) ;
653- m_Batcher . DestroyInstances ( instances . AsArray ( ) ) ;
654- instances . Dispose ( ) ;
657+ Profiler . BeginSample ( "GPUResidentDrawer.FreeRendererGroupInstances" ) ;
655658
656- m_BatchersContext . FreeRendererGroupInstances ( rendererGroupIDs ) ;
659+ m_Batcher . FreeRendererGroupInstances ( rendererGroupIDs ) ;
657660
658661 Profiler . EndSample ( ) ;
659662 }
0 commit comments