From a7ef107656c41d5df42af82da4c497ef589a4f82 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 27 May 2020 14:52:49 +0200 Subject: [PATCH 1/2] Fixed an issue where editing the lookdev default profile would not reflect directly in the lookdev window. --- .../HDRenderPipeline.LookDev.cs | 93 +++++++++++++++---- 1 file changed, 75 insertions(+), 18 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LookDev.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LookDev.cs index b8cc17d3187..853e2e7af89 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LookDev.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LookDev.cs @@ -5,6 +5,8 @@ namespace UnityEngine.Rendering.HighDefinition { public partial class HDRenderPipeline : IDataProvider { + int m_LookDevVolumeProfileHash = -1; + struct LookDevDataForHDRP { public HDAdditionalCameraData additionalCameraData; @@ -14,6 +16,65 @@ struct LookDevDataForHDRP public Volume volume; } +#if UNITY_EDITOR + bool UpdateVolumeProfile(Volume volume, out VisualEnvironment visualEnvironment, out HDRISky sky) + { + HDRenderPipelineAsset hdrpAsset = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset; + if (hdrpAsset.defaultLookDevProfile == null) + hdrpAsset.defaultLookDevProfile = hdrpAsset.renderPipelineEditorResources.lookDev.defaultLookDevVolumeProfile; + + int newHashCode = hdrpAsset.defaultLookDevProfile.GetHashCode(); + if (newHashCode != m_LookDevVolumeProfileHash) + { + VolumeProfile oldProfile = volume.sharedProfile; + + m_LookDevVolumeProfileHash = newHashCode; + + VolumeProfile profile = ScriptableObject.Instantiate(hdrpAsset.defaultLookDevProfile); + volume.sharedProfile = profile; + + // Remove potentially existing components in the user profile. + if (profile.TryGet(out visualEnvironment)) + profile.Remove(); + + if (profile.TryGet(out sky)) + profile.Remove(); + + // If there was a profile before we needed to re-instantiate the new profile, we need to copy the data over for sky settings. + if (oldProfile != null) + { + if (oldProfile.TryGet(out HDRISky oldSky)) + { + sky = Object.Instantiate(oldSky); + profile.components.Add(sky); + } + if (oldProfile.TryGet(out VisualEnvironment oldVisualEnv)) + { + visualEnvironment = Object.Instantiate(oldVisualEnv); + profile.components.Add(visualEnvironment); + } + + CoreUtils.Destroy(oldProfile); + } + else + { + visualEnvironment = profile.Add(); + visualEnvironment.skyType.Override((int)SkyType.HDRI); + visualEnvironment.skyAmbientMode.Override(SkyAmbientMode.Dynamic); + sky = profile.Add(); + } + + return true; + } + else + { + visualEnvironment = null; + sky = null; + return false; + } + } +#endif + /// /// This hook allows HDRP to init the scene when creating the view /// @@ -51,24 +112,11 @@ void IDataProvider.FirstInitScene(StageRuntimeInterface SRI) volume.priority = float.MaxValue; volume.enabled = false; -#if UNITY_EDITOR - HDRenderPipelineAsset hdrpAsset = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset; - if (hdrpAsset.defaultLookDevProfile == null) - hdrpAsset.defaultLookDevProfile = hdrpAsset.renderPipelineEditorResources.lookDev.defaultLookDevVolumeProfile; - VolumeProfile profile = ScriptableObject.Instantiate(hdrpAsset.defaultLookDevProfile); - volume.sharedProfile = profile; - - VisualEnvironment visualEnvironment; - if (profile.TryGet(out visualEnvironment)) - profile.Remove(); - visualEnvironment = profile.Add(); - visualEnvironment.skyType.Override((int)SkyType.HDRI); - visualEnvironment.skyAmbientMode.Override(SkyAmbientMode.Dynamic); - HDRISky sky; - if (profile.TryGet(out sky)) - profile.Remove(); - sky = profile.Add(); +#if UNITY_EDITOR + // Make sure we invalidate the current volume when first loading a scene. + m_LookDevVolumeProfileHash = -1; + UpdateVolumeProfile(volume, out var visualEnvironment, out var sky); SRI.SRPData = new LookDevDataForHDRP() { @@ -79,7 +127,7 @@ void IDataProvider.FirstInitScene(StageRuntimeInterface SRI) volume = volume }; #else - //remove unasigned warnings when building + //remove unassigned warnings when building SRI.SRPData = new LookDevDataForHDRP() { additionalCameraData = null, @@ -122,6 +170,15 @@ void IDataProvider.UpdateSky(Camera camera, Sky sky, StageRuntimeInterface SRI) void IDataProvider.OnBeginRendering(StageRuntimeInterface SRI) { LookDevDataForHDRP data = (LookDevDataForHDRP)SRI.SRPData; +#if UNITY_EDITOR + // The default volume can change in the HDRP asset so if it does we need to re-instantiate it. + if (UpdateVolumeProfile(data.volume, out var visualEnv, out var sky)) + { + data.sky = sky; + data.visualEnvironment = visualEnv; + SRI.SRPData = data; + } +#endif data.volume.enabled = true; } From 06d7189c7f1c30b34994ca3422a4896f429b1d33 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 27 May 2020 14:53:40 +0200 Subject: [PATCH 2/2] Update changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 38f3533bed3..05e2fe7f7e8 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -623,6 +623,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix erroneous central depth sampling in TAA. - Fixed light layers not correctly disabled when the lightlayers is set to Nothing and Lightlayers isn't enabled in HDRP Asset - Fixed a wrong condition in CameraSwitcher, potentially causing out of bound exceptions. +- Fixed an issue where editing the Look Dev default profile would not reflect directly in the Look Dev window. ### Changed - Improve MIP selection for decals on Transparents