@@ -80,6 +80,7 @@ public FreeCamPanel(UIBase owner) : base(owner)
8080 public static Toggle followRotationToggle ;
8181 static bool disabledCinemachine ;
8282 static bool disabledOrthographic ;
83+ static bool disabledOcclusionCulling ;
8384 static List < string > stringComponentsToDisable = new ( ) ;
8485
8586 private class DisableTarget
@@ -319,6 +320,7 @@ static void SetupFreeCamera()
319320 // so we will try to move the real camera as well.
320321 MaybeToggleCinemachine ( false ) ;
321322 MaybeToggleOrthographic ( false ) ;
323+ MaybeToggleOcclusionCulling ( false ) ;
322324 ToggleCustomComponents ( false ) ;
323325
324326 cameraMatrixOverrider = new GameObject ( "CUE Camera" ) . AddComponent < Camera > ( ) ;
@@ -392,6 +394,7 @@ internal static void EndFreecam()
392394 case FreeCameraType . ForcedMatrix :
393395 MaybeToggleCinemachine ( true ) ;
394396 MaybeToggleOrthographic ( true ) ;
397+ MaybeToggleOcclusionCulling ( true ) ;
395398 ToggleCustomComponents ( true ) ;
396399 MethodInfo resetCullingMatrixMethod = typeof ( Camera ) . GetMethod ( "ResetCullingMatrix" , new Type [ ] { } ) ;
397400 resetCullingMatrixMethod . Invoke ( ourCamera , null ) ;
@@ -528,6 +531,22 @@ static void MaybeToggleOrthographic(bool enable){
528531 }
529532 }
530533
534+ static void MaybeToggleOcclusionCulling ( bool enable ) {
535+ if ( ourCamera ) {
536+ if ( enable ) {
537+ if ( disabledOcclusionCulling ) {
538+ ourCamera . useOcclusionCulling = true ;
539+ disabledOcclusionCulling = false ;
540+ }
541+ } else {
542+ if ( ourCamera . useOcclusionCulling ) {
543+ disabledOcclusionCulling = true ;
544+ ourCamera . useOcclusionCulling = false ;
545+ }
546+ }
547+ }
548+ }
549+
531550 static void SetCameraPositionInput ( Vector3 pos )
532551 {
533552 if ( ! ourCamera || lastSetCameraPosition == pos )
@@ -1077,7 +1096,7 @@ static void ToggleCustomComponents(bool enable)
10771096 }
10781097 }
10791098
1080- static Behaviour GetComponentByName ( GameObject obj , string componentsName )
1099+ public static Behaviour GetComponentByName ( GameObject obj , string componentsName )
10811100 {
10821101 if ( obj )
10831102 {
@@ -1216,6 +1235,7 @@ public FreeCamBehaviour(IntPtr ptr) : base(ptr) { }
12161235 private Vector3 cachedPosition ;
12171236 private Quaternion cachedRotation ;
12181237 private CamPaths cachedCamPathsPanel ;
1238+ private bool ? hasHDRPComponent = null ;
12191239
12201240 internal void Update ( )
12211241 {
@@ -1714,11 +1734,20 @@ private void OnAfterEvent(object arg1, Camera[] arg2)
17141734 // HDRP matrix override ignores us moving the camera unfortunately, so we try to copy over the position of the camera matrix overrider.
17151735 protected void UpdateRealCamera ( ) {
17161736 if ( FreeCamPanel . cameraMatrixOverrider != null ) {
1717- cachedPosition = FreeCamPanel . ourCamera . transform . position ;
1718- FreeCamPanel . ourCamera . transform . position = FreeCamPanel . cameraMatrixOverrider . transform . position ;
1719- // We also try to update the rotation in case there are game shaders that use the real camera rotation
1720- cachedRotation = FreeCamPanel . ourCamera . transform . rotation ;
1721- FreeCamPanel . ourCamera . transform . rotation = FreeCamPanel . cameraMatrixOverrider . transform . rotation ;
1737+ if ( ! hasHDRPComponent . HasValue )
1738+ {
1739+ var hdrpComponent = FreeCamPanel . GetComponentByName ( FreeCamPanel . ourCamera . gameObject , "UnityEngine.Rendering.HighDefinition.HDAdditionalCameraData" ) ;
1740+ hasHDRPComponent = hdrpComponent != null ;
1741+ }
1742+
1743+ if ( hasHDRPComponent == true )
1744+ {
1745+ cachedPosition = FreeCamPanel . ourCamera . transform . position ;
1746+ FreeCamPanel . ourCamera . transform . position = FreeCamPanel . cameraMatrixOverrider . transform . position ;
1747+ // We also try to update the rotation in case there are game shaders that use the real camera rotation
1748+ cachedRotation = FreeCamPanel . ourCamera . transform . rotation ;
1749+ FreeCamPanel . ourCamera . transform . rotation = FreeCamPanel . cameraMatrixOverrider . transform . rotation ;
1750+ }
17221751 }
17231752 }
17241753
0 commit comments