@@ -5,6 +5,10 @@ namespace UnityEngine.Rendering.HighDefinition
55{
66 public partial class HDRenderPipeline : IDataProvider
77 {
8+ #if UNITY_EDITOR
9+ int m_LookDevVolumeProfileHash = - 1 ;
10+ #endif
11+
812 struct LookDevDataForHDRP
913 {
1014 public HDAdditionalCameraData additionalCameraData ;
@@ -14,6 +18,65 @@ struct LookDevDataForHDRP
1418 public Volume volume ;
1519 }
1620
21+ #if UNITY_EDITOR
22+ bool UpdateVolumeProfile ( Volume volume , out VisualEnvironment visualEnvironment , out HDRISky sky )
23+ {
24+ HDRenderPipelineAsset hdrpAsset = GraphicsSettings . renderPipelineAsset as HDRenderPipelineAsset ;
25+ if ( hdrpAsset . defaultLookDevProfile == null )
26+ hdrpAsset . defaultLookDevProfile = hdrpAsset . renderPipelineEditorResources . lookDev . defaultLookDevVolumeProfile ;
27+
28+ int newHashCode = hdrpAsset . defaultLookDevProfile . GetHashCode ( ) ;
29+ if ( newHashCode != m_LookDevVolumeProfileHash )
30+ {
31+ VolumeProfile oldProfile = volume . sharedProfile ;
32+
33+ m_LookDevVolumeProfileHash = newHashCode ;
34+
35+ VolumeProfile profile = ScriptableObject . Instantiate ( hdrpAsset . defaultLookDevProfile ) ;
36+ volume . sharedProfile = profile ;
37+
38+ // Remove potentially existing components in the user profile.
39+ if ( profile . TryGet ( out visualEnvironment ) )
40+ profile . Remove < VisualEnvironment > ( ) ;
41+
42+ if ( profile . TryGet ( out sky ) )
43+ profile . Remove < HDRISky > ( ) ;
44+
45+ // If there was a profile before we needed to re-instantiate the new profile, we need to copy the data over for sky settings.
46+ if ( oldProfile != null )
47+ {
48+ if ( oldProfile . TryGet ( out HDRISky oldSky ) )
49+ {
50+ sky = Object . Instantiate ( oldSky ) ;
51+ profile . components . Add ( sky ) ;
52+ }
53+ if ( oldProfile . TryGet ( out VisualEnvironment oldVisualEnv ) )
54+ {
55+ visualEnvironment = Object . Instantiate ( oldVisualEnv ) ;
56+ profile . components . Add ( visualEnvironment ) ;
57+ }
58+
59+ CoreUtils . Destroy ( oldProfile ) ;
60+ }
61+ else
62+ {
63+ visualEnvironment = profile . Add < VisualEnvironment > ( ) ;
64+ visualEnvironment . skyType . Override ( ( int ) SkyType . HDRI ) ;
65+ visualEnvironment . skyAmbientMode . Override ( SkyAmbientMode . Dynamic ) ;
66+ sky = profile . Add < HDRISky > ( ) ;
67+ }
68+
69+ return true ;
70+ }
71+ else
72+ {
73+ visualEnvironment = null ;
74+ sky = null ;
75+ return false ;
76+ }
77+ }
78+ #endif
79+
1780 /// <summary>
1881 /// This hook allows HDRP to init the scene when creating the view
1982 /// </summary>
@@ -51,24 +114,11 @@ void IDataProvider.FirstInitScene(StageRuntimeInterface SRI)
51114 volume . priority = float . MaxValue ;
52115 volume . enabled = false ;
53116
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 ;
60117
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 ) ;
67-
68- HDRISky sky ;
69- if ( profile . TryGet ( out sky ) )
70- profile . Remove < HDRISky > ( ) ;
71- sky = profile . Add < HDRISky > ( ) ;
118+ #if UNITY_EDITOR
119+ // Make sure we invalidate the current volume when first loading a scene.
120+ m_LookDevVolumeProfileHash = - 1 ;
121+ UpdateVolumeProfile ( volume , out var visualEnvironment , out var sky ) ;
72122
73123 SRI . SRPData = new LookDevDataForHDRP ( )
74124 {
@@ -79,7 +129,7 @@ void IDataProvider.FirstInitScene(StageRuntimeInterface SRI)
79129 volume = volume
80130 } ;
81131#else
82- //remove unasigned warnings when building
132+ //remove unassigned warnings when building
83133 SRI . SRPData = new LookDevDataForHDRP ( )
84134 {
85135 additionalCameraData = null ,
@@ -122,6 +172,15 @@ void IDataProvider.UpdateSky(Camera camera, Sky sky, StageRuntimeInterface SRI)
122172 void IDataProvider . OnBeginRendering ( StageRuntimeInterface SRI )
123173 {
124174 LookDevDataForHDRP data = ( LookDevDataForHDRP ) SRI . SRPData ;
175+ #if UNITY_EDITOR
176+ // The default volume can change in the HDRP asset so if it does we need to re-instantiate it.
177+ if ( UpdateVolumeProfile ( data . volume , out var visualEnv , out var sky ) )
178+ {
179+ data . sky = sky ;
180+ data . visualEnvironment = visualEnv ;
181+ SRI . SRPData = data ;
182+ }
183+ #endif
125184 data . volume . enabled = true ;
126185 }
127186
0 commit comments