@@ -727,6 +727,18 @@ public void UpdateEnvironment( HDCamera hdCamera,
727727 m_BuiltinParameters . frameIndex = frameIndex ;
728728 m_BuiltinParameters . skySettings = skyContext . skySettings ;
729729
730+ // When update is not requested and the context is already valid (ie: already computed at least once),
731+ // we need to early out in two cases:
732+ // - updateMode is "OnDemand" in which case we never update unless explicitly requested
733+ // - updateMode is "Realtime" in which case we only update if the time threshold for realtime update is passed.
734+ if ( IsCachedContextValid ( skyContext ) && ! updateRequired )
735+ {
736+ if ( skyContext . skySettings . updateMode . value == EnvironmentUpdateMode . OnDemand )
737+ return ;
738+ else if ( skyContext . skySettings . updateMode . value == EnvironmentUpdateMode . Realtime && skyContext . currentUpdateTime < skyContext . skySettings . updatePeriod . value )
739+ return ;
740+ }
741+
730742 int skyHash = ComputeSkyHash ( hdCamera , skyContext , sunLight , ambientMode , staticSky ) ;
731743 bool forceUpdate = updateRequired ;
732744
@@ -745,6 +757,7 @@ public void UpdateEnvironment( HDCamera hdCamera,
745757 {
746758 using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . UpdateSkyEnvironment ) ) )
747759 {
760+ // Debug.Log("Update Sky Lighting");
748761 RenderSkyToCubemap ( skyContext ) ;
749762
750763 if ( updateAmbientProbe )
@@ -823,7 +836,7 @@ public void UpdateEnvironment(HDCamera hdCamera, ScriptableRenderContext renderC
823836 if ( ( ambientMode == SkyAmbientMode . Static || forceStaticUpdate ) && hdCamera . camera . cameraType != CameraType . Preview )
824837 {
825838 m_StaticLightingSky . skySettings = staticLightingSky != null ? staticLightingSky . skySettings : null ;
826- UpdateEnvironment ( hdCamera , renderContext , m_StaticLightingSky , sunLight , m_StaticSkyUpdateRequired , true , true , SkyAmbientMode . Static , frameIndex , cmd ) ;
839+ UpdateEnvironment ( hdCamera , renderContext , m_StaticLightingSky , sunLight , m_StaticSkyUpdateRequired || m_UpdateRequired , true , true , SkyAmbientMode . Static , frameIndex , cmd ) ;
827840 m_StaticSkyUpdateRequired = false ;
828841 }
829842
0 commit comments