@@ -5,6 +5,8 @@ namespace UnityEngine.Rendering.HighDefinition
55{
66 public partial class HDRenderPipeline : IDataProvider
77 {
8+ int m_LookDevVolumeProfileHash = - 1 ;
9+
810 struct LookDevDataForHDRP
911 {
1012 public HDAdditionalCameraData additionalCameraData ;
@@ -14,6 +16,65 @@ struct LookDevDataForHDRP
1416 public Volume volume ;
1517 }
1618
19+ #if UNITY_EDITOR
20+ bool UpdateVolumeProfile ( Volume volume , out VisualEnvironment visualEnvironment , out HDRISky sky )
21+ {
22+ HDRenderPipelineAsset hdrpAsset = GraphicsSettings . renderPipelineAsset as HDRenderPipelineAsset ;
23+ if ( hdrpAsset . defaultLookDevProfile == null )
24+ hdrpAsset . defaultLookDevProfile = hdrpAsset . renderPipelineEditorResources . lookDev . defaultLookDevVolumeProfile ;
25+
26+ int newHashCode = hdrpAsset . defaultLookDevProfile . GetHashCode ( ) ;
27+ if ( newHashCode != m_LookDevVolumeProfileHash )
28+ {
29+ VolumeProfile oldProfile = volume . sharedProfile ;
30+
31+ m_LookDevVolumeProfileHash = newHashCode ;
32+
33+ VolumeProfile profile = ScriptableObject . Instantiate ( hdrpAsset . defaultLookDevProfile ) ;
34+ volume . sharedProfile = profile ;
35+
36+ // Remove potentially existing components in the user profile.
37+ if ( profile . TryGet ( out visualEnvironment ) )
38+ profile . Remove < VisualEnvironment > ( ) ;
39+
40+ if ( profile . TryGet ( out sky ) )
41+ profile . Remove < HDRISky > ( ) ;
42+
43+ // If there was a profile before we needed to re-instantiate the new profile, we need to copy the data over for sky settings.
44+ if ( oldProfile != null )
45+ {
46+ if ( oldProfile . TryGet ( out HDRISky oldSky ) )
47+ {
48+ sky = Object . Instantiate ( oldSky ) ;
49+ profile . components . Add ( sky ) ;
50+ }
51+ if ( oldProfile . TryGet ( out VisualEnvironment oldVisualEnv ) )
52+ {
53+ visualEnvironment = Object . Instantiate ( oldVisualEnv ) ;
54+ profile . components . Add ( visualEnvironment ) ;
55+ }
56+
57+ CoreUtils . Destroy ( oldProfile ) ;
58+ }
59+ else
60+ {
61+ visualEnvironment = profile . Add < VisualEnvironment > ( ) ;
62+ visualEnvironment . skyType . Override ( ( int ) SkyType . HDRI ) ;
63+ visualEnvironment . skyAmbientMode . Override ( SkyAmbientMode . Dynamic ) ;
64+ sky = profile . Add < HDRISky > ( ) ;
65+ }
66+
67+ return true ;
68+ }
69+ else
70+ {
71+ visualEnvironment = null ;
72+ sky = null ;
73+ return false ;
74+ }
75+ }
76+ #endif
77+
1778 /// <summary>
1879 /// This hook allows HDRP to init the scene when creating the view
1980 /// </summary>
@@ -51,24 +112,11 @@ void IDataProvider.FirstInitScene(StageRuntimeInterface SRI)
51112 volume . priority = float . MaxValue ;
52113 volume . enabled = false ;
53114
54- #if UNITY_EDITOR
55- HDRenderPipelineAsset hdrpAsset = GraphicsSettings . renderPipelineAsset as HDRenderPipelineAsset ;
56- if ( hdrpAsset . defaultLookDevProfile == null )
57- hdrpAsset . defaultLookDevProfile = hdrpAsset . renderPipelineEditorResources . lookDev . defaultLookDevVolumeProfile ;
58- VolumeProfile profile = ScriptableObject . Instantiate ( hdrpAsset . defaultLookDevProfile ) ;
59- volume . sharedProfile = profile ;
60-
61- VisualEnvironment visualEnvironment ;
62- if ( profile . TryGet ( out visualEnvironment ) )
63- profile . Remove < VisualEnvironment > ( ) ;
64- visualEnvironment = profile . Add < VisualEnvironment > ( ) ;
65- visualEnvironment . skyType . Override ( ( int ) SkyType . HDRI ) ;
66- visualEnvironment . skyAmbientMode . Override ( SkyAmbientMode . Dynamic ) ;
67115
68- HDRISky sky ;
69- if ( profile . TryGet ( out sky ) )
70- profile . Remove < HDRISky > ( ) ;
71- sky = profile . Add < HDRISky > ( ) ;
116+ #if UNITY_EDITOR
117+ // Make sure we invalidate the current volume when first loading a scene.
118+ m_LookDevVolumeProfileHash = - 1 ;
119+ UpdateVolumeProfile ( volume , out var visualEnvironment , out var sky ) ;
72120
73121 SRI . SRPData = new LookDevDataForHDRP ( )
74122 {
@@ -79,7 +127,7 @@ void IDataProvider.FirstInitScene(StageRuntimeInterface SRI)
79127 volume = volume
80128 } ;
81129#else
82- //remove unasigned warnings when building
130+ //remove unassigned warnings when building
83131 SRI . SRPData = new LookDevDataForHDRP ( )
84132 {
85133 additionalCameraData = null ,
@@ -122,6 +170,15 @@ void IDataProvider.UpdateSky(Camera camera, Sky sky, StageRuntimeInterface SRI)
122170 void IDataProvider . OnBeginRendering ( StageRuntimeInterface SRI )
123171 {
124172 LookDevDataForHDRP data = ( LookDevDataForHDRP ) SRI . SRPData ;
173+ #if UNITY_EDITOR
174+ // The default volume can change in the HDRP asset so if it does we need to re-instantiate it.
175+ if ( UpdateVolumeProfile ( data . volume , out var visualEnv , out var sky ) )
176+ {
177+ data . sky = sky ;
178+ data . visualEnvironment = visualEnv ;
179+ SRI . SRPData = data ;
180+ }
181+ #endif
125182 data . volume . enabled = true ;
126183 }
127184
0 commit comments