From e4c171df1bccf3f710ebe47992ba8f920485b5c8 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Fri, 27 Nov 2020 13:41:33 +0100 Subject: [PATCH 01/15] Removed some GCAlloc when creating probes --- .../Runtime/RenderPipeline/Camera/HDCamera.cs | 33 ++++++++++--------- .../RenderPipeline/HDRenderPipeline.cs | 13 ++++++-- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index ef8a1751bd5..e8b2c294007 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -881,25 +881,26 @@ internal void UpdateCurrentSky(SkyManager skyManager) visualSky.skySettings = SkyManager.GetSkySetting(volumeStack); - // Now, see if we have a lighting override - // Update needs to happen before testing if the component is active other internal data structure are not properly updated yet. - VolumeManager.instance.Update(skyManager.lightingOverrideVolumeStack, volumeAnchor, skyManager.lightingOverrideLayerMask); - if (VolumeManager.instance.IsComponentActiveInMask(skyManager.lightingOverrideLayerMask)) + lightingSky = visualSky; + + if (skyManager.lightingOverrideLayerMask != 0) { - SkySettings newSkyOverride = SkyManager.GetSkySetting(skyManager.lightingOverrideVolumeStack); - if (m_LightingOverrideSky.skySettings != null && newSkyOverride == null) + // Now, see if we have a lighting override + // Update needs to happen before testing if the component is active other internal data structure are not properly updated yet. + VolumeManager.instance.Update(skyManager.lightingOverrideVolumeStack, volumeAnchor, skyManager.lightingOverrideLayerMask); + if (VolumeManager.instance.IsComponentActiveInMask(skyManager.lightingOverrideLayerMask)) { - // When we switch from override to no override, we need to make sure that the visual sky will actually be properly re-rendered. - // Resetting the visual sky hash will ensure that. - visualSky.skyParametersHash = -1; - } + SkySettings newSkyOverride = SkyManager.GetSkySetting(skyManager.lightingOverrideVolumeStack); + if (m_LightingOverrideSky.skySettings != null && newSkyOverride == null) + { + // When we switch from override to no override, we need to make sure that the visual sky will actually be properly re-rendered. + // Resetting the visual sky hash will ensure that. + visualSky.skyParametersHash = -1; + } - m_LightingOverrideSky.skySettings = newSkyOverride; - lightingSky = m_LightingOverrideSky; - } - else - { - lightingSky = visualSky; + m_LightingOverrideSky.skySettings = newSkyOverride; + lightingSky = m_LightingOverrideSky; + } } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 2071dee77b2..87a53382793 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1595,7 +1595,6 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c m_Time = Time.time; // Does NOT take the 'animateMaterials' setting into account. m_LastTime = Mathf.Min(m_Time, m_LastTime); // Guard against broken Unity behavior. Should not be necessary. - m_ProbeCameraCache.ClearCamerasUnusedFor(2, m_FrameCount); HDCamera.CleanUnused(); } @@ -1616,6 +1615,9 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c ); } +#if UNITY_EDITOR + UnityEditor.EditorMaterialUtility.disableApplyMaterialPropertyDrawers = true; +#endif // This syntax is awful and hostile to debugging, please don't use it... using (ListPool.Get(out List renderRequests)) @@ -1966,10 +1968,11 @@ ref List renderDatas for (int j = 0; j < cameraSettings.Count; ++j) { var camera = m_ProbeCameraCache.GetOrCreate((viewerTransform, visibleProbe, j), m_FrameCount, CameraType.Reflection); - var additionalCameraData = camera.GetComponent(); - if (additionalCameraData == null) + if (!camera.TryGetComponent(out var additionalCameraData)) + { additionalCameraData = camera.gameObject.AddComponent(); + } additionalCameraData.hasPersistentHistory = true; // We need to set a targetTexture with the right otherwise when setting pixelRect, it will be rescaled internally to the size of the screen @@ -2296,6 +2299,10 @@ ref _cullingResults } } +#if UNITY_EDITOR + UnityEditor.EditorMaterialUtility.disableApplyMaterialPropertyDrawers = false; +#endif + if (m_EnableRenderGraph) m_RenderGraph.EndFrame(); m_XRSystem.ReleaseFrame(); From 76f58c02e23909f80056df3eb7588cbf019397b2 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Fri, 27 Nov 2020 13:42:52 +0100 Subject: [PATCH 02/15] Stop updating volume system for Lighting Override when not necessary. Disabled ApplyMaterialPropertyDrawers when rendering HDRP to avoid unwanted perf spikes --- .../Lighting/ProbeVolume/ProbeVolumeLighting.cs | 3 +-- .../Runtime/Material/GGXConvolution/IBLFilterGGX.cs | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs index ad25be4d9da..73f6587c385 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs @@ -958,8 +958,7 @@ ProbeVolumeDebugOverlayParameters PrepareProbeVolumeOverlayParameters(LightingDe #if UNITY_EDITOR if (UnityEditor.Selection.activeGameObject != null) { - var selectedProbeVolume = UnityEditor.Selection.activeGameObject.GetComponent(); - if (selectedProbeVolume != null) + if (UnityEditor.Selection.activeGameObject.TryGetComponent(out var selectedProbeVolume)) { // User currently has a probe volume selected. // Compute a scaleBias term so that atlas view automatically zooms into selected probe volume. diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/GGXConvolution/IBLFilterGGX.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/GGXConvolution/IBLFilterGGX.cs index fa26f0b849d..ce427a95f45 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/GGXConvolution/IBLFilterGGX.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/GGXConvolution/IBLFilterGGX.cs @@ -27,6 +27,8 @@ class IBLFilterGGX : IBLFilterBSDF const int k_DefaultPlanarResolution = 512; // Intermediate variables Vector4 currentScreenSize = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); + MaterialPropertyBlock m_MaterialPropertyBlock = new MaterialPropertyBlock(); + public IBLFilterGGX(RenderPipelineResources renderPipelineResources, MipGenerator mipGenerator) { @@ -138,23 +140,22 @@ void FilterCubemapCommon(CommandBuffer cmd, m_convolveMaterial.SetTexture("_GgxIblSamples", m_GgxIblSampleData); - var props = new MaterialPropertyBlock(); - props.SetTexture("_MainTex", source); - props.SetFloat("_InvOmegaP", invOmegaP); + m_MaterialPropertyBlock.SetTexture("_MainTex", source); + m_MaterialPropertyBlock.SetFloat("_InvOmegaP", invOmegaP); for (int mip = 1; mip < (int)EnvConstants.ConvolutionMipCount; ++mip) { - props.SetFloat("_Level", mip); + m_MaterialPropertyBlock.SetFloat("_Level", mip); for (int face = 0; face < 6; ++face) { var faceSize = new Vector4(source.width >> mip, source.height >> mip, 1.0f / (source.width >> mip), 1.0f / (source.height >> mip)); var transform = HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(0.5f * Mathf.PI, Vector2.zero, faceSize, worldToViewMatrices[face], true); - props.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, transform); + m_MaterialPropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, transform); CoreUtils.SetRenderTarget(cmd, target, ClearFlag.None, mip, (CubemapFace)face); - CoreUtils.DrawFullScreen(cmd, m_convolveMaterial, props); + CoreUtils.DrawFullScreen(cmd, m_convolveMaterial, m_MaterialPropertyBlock); } } } From d15aa3eb8085beadda09fcdb572f539171fe1dba Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 16 Dec 2020 16:06:44 +0100 Subject: [PATCH 03/15] Removed C++ change dependency --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index baccf830e74..07c462c9635 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1269,10 +1269,6 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c var dynResHandler = DynamicResolutionHandler.instance; dynResHandler.Update(m_Asset.currentPlatformRenderPipelineSettings.dynamicResolutionSettings); -#if UNITY_EDITOR - UnityEditor.EditorMaterialUtility.disableApplyMaterialPropertyDrawers = true; -#endif - // This syntax is awful and hostile to debugging, please don't use it... using (ListPool.Get(out List renderRequests)) using (ListPool.Get(out List rootRenderRequestIndices)) From 2fe900cb938a205d38c75dfd22d465143e57b29a Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 16 Dec 2020 17:24:10 +0100 Subject: [PATCH 04/15] Used new API to disable terrain data deletion for reflection cameras. --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 07c462c9635..0a43bb6617d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1269,6 +1269,8 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c var dynResHandler = DynamicResolutionHandler.instance; dynResHandler.Update(m_Asset.currentPlatformRenderPipelineSettings.dynamicResolutionSettings); + var activeTerrains = Terrain.activeTerrains; + // This syntax is awful and hostile to debugging, please don't use it... using (ListPool.Get(out List renderRequests)) using (ListPool.Get(out List rootRenderRequestIndices)) @@ -1619,6 +1621,9 @@ ref List renderDatas { var camera = m_ProbeCameraCache.GetOrCreate((viewerTransform, visibleProbe, j), m_FrameCount, CameraType.Reflection); + foreach (var terrain in activeTerrains) + terrain.SetFreeUnusedRenderingResources(camera.GetInstanceID(), false); + if (!camera.TryGetComponent(out var additionalCameraData)) { additionalCameraData = camera.gameObject.AddComponent(); From 77bae015b386a74926f0a26ad206757557e6b829 Mon Sep 17 00:00:00 2001 From: JulienIgnace-Unity Date: Fri, 8 Jan 2021 14:01:58 +0100 Subject: [PATCH 05/15] Fixed Render Graph immediate mode. (#3033) Co-authored-by: Sebastien Lagarde --- .../Runtime/RenderGraph/RenderGraph.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs index 6537bc9e51c..405830387e9 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs @@ -556,6 +556,8 @@ public void Begin(in RenderGraphParameters parameters) m_ImmediateModeResourceList[i].Clear(); } + + m_Resources.BeginExecute(m_CurrentFrameIndex); } } From 47bd6c2505b11a66ea4d61c5469b59e70bf8b256 Mon Sep 17 00:00:00 2001 From: FrancescoC-unity <43168857+FrancescoC-unity@users.noreply.github.com> Date: Fri, 8 Jan 2021 17:17:50 +0100 Subject: [PATCH 06/15] Fix issue with shadow mask and area lights (#3019) * Not checking NdotL since it's not really valid for area lights (We have multiple valid light directions, not one) * Changelog Co-authored-by: sebastienlagarde --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + .../Runtime/Lighting/LightEvaluation.hlsl | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 9c3469d1869..7e80b910a8b 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed Clearcoat on Stacklit or Lit breaks when URP is imported into the project (case 1297806) - Fixed timing issues with accumulation motion blur - Fixed an issue with the frame count management for the volumetric fog (case 1299251). +- Fixed issue with shadow mask and area lights. ### Changed - Removed the material pass probe volumes evaluation mode. diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl index abf522a0c67..ec987391400 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl @@ -481,12 +481,11 @@ SHADOW_TYPE EvaluateShadow_RectArea( LightLoopContext lightLoopContext, Position #ifndef LIGHT_EVALUATION_NO_SHADOWS float shadow = 1.0; float shadowMask = 1.0; - float NdotL = dot(N, L); // Disable contact shadow and shadow mask when facing away from light (i.e transmission) #ifdef SHADOWS_SHADOWMASK // shadowMaskSelector.x is -1 if there is no shadow mask // Note that we override shadow value (in case we don't have any dynamic shadow) - shadow = shadowMask = (light.shadowMaskSelector.x >= 0.0 && NdotL > 0.0) ? dot(BUILTIN_DATA_SHADOW_MASK, light.shadowMaskSelector) : 1.0; + shadow = shadowMask = (light.shadowMaskSelector.x >= 0.0) ? dot(BUILTIN_DATA_SHADOW_MASK, light.shadowMaskSelector) : 1.0; #endif // When screen space shadows are not supported, this value is stripped out as it is a constant. From 88daab37539355565f0044f0c0de8396a6c414af Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Fri, 8 Jan 2021 17:19:06 +0100 Subject: [PATCH 07/15] Fix issue with capture callback (now includes post processing results) (#3035) Co-authored-by: sebastienlagarde --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + .../Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 7e80b910a8b..e62081ef490 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed timing issues with accumulation motion blur - Fixed an issue with the frame count management for the volumetric fog (case 1299251). - Fixed issue with shadow mask and area lights. +- Fixed an issue with the capture callback (now includes post processing results). ### Changed - Removed the material pass probe volumes evaluation mode. diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs index 9da56017ace..af80c886cfd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs @@ -276,7 +276,7 @@ void ExecuteWithRenderGraph(RenderRequest renderRequest, // Because of this, we need another blit here to the final render target at the right viewport. if (!HDUtils.PostProcessIsFinalPass(hdCamera) || aovRequest.isValid) { - hdCamera.ExecuteCaptureActions(m_RenderGraph, colorBuffer); + hdCamera.ExecuteCaptureActions(m_RenderGraph, postProcessDest); postProcessDest = RenderDebug(m_RenderGraph, hdCamera, From 4313b48fbaf96d47ba538818ad85e68a50ed31c9 Mon Sep 17 00:00:00 2001 From: Antoine Lelievre Date: Fri, 8 Jan 2021 17:40:00 +0100 Subject: [PATCH 08/15] [HDRP] Fix decal draw order for ShaderGraph decal materials (#3018) * Fixed ShaderGraph decal draw order * Updated changelog Co-authored-by: sebastienlagarde --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + .../Runtime/Material/Decal/DecalSystem.cs | 4 ++-- .../Runtime/RenderPipeline/HDStringConstants.cs | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index e62081ef490..3435e744030 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed an issue with the frame count management for the volumetric fog (case 1299251). - Fixed issue with shadow mask and area lights. - Fixed an issue with the capture callback (now includes post processing results). +- Fixed decal draw order for ShaderGraph decal materials. ### Changed - Removed the material pass probe volumes evaluation mode. diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs index b0f4f0bac20..24d3274eb66 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs @@ -859,9 +859,9 @@ public int DrawOrder { get { - if (m_IsHDRenderPipelineDecal) + if (this.m_Material.HasProperty(HDShaderIDs._DrawOrder)) { - return this.m_Material.GetInt("_DrawOrder"); + return this.m_Material.GetInt(HDShaderIDs._DrawOrder); } else { diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs index d1efce9c524..b72c059cd7a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -243,6 +243,7 @@ static class HDShaderIDs public static readonly int _DecalNormalBufferStencilRef = Shader.PropertyToID("_DecalNormalBufferStencilRef"); public static readonly int _DecalPrepassTexture = Shader.PropertyToID("_DecalPrepassTexture"); public static readonly int _DecalPrepassTextureMS = Shader.PropertyToID("_DecalPrepassTextureMS"); + public static readonly int _DrawOrder = Shader.PropertyToID("_DrawOrder"); public static readonly int _WorldSpaceCameraPos = Shader.PropertyToID("_WorldSpaceCameraPos"); From a9c4c2784c17b614d824c9167030078b42ce6513 Mon Sep 17 00:00:00 2001 From: JulienIgnace-Unity Date: Mon, 11 Jan 2021 10:40:26 +0100 Subject: [PATCH 09/15] Fixed various Look Dev issues after exiting Playmode (#2956) * Fixed access to invalid Contexts references after exiting playmode. * Fixed comparison gizmo after playmode. * Fixes from PR feedback --- .../Editor/LookDev/CameraController.cs | 22 ++++++++++++----- .../LookDev/ComparisonGizmoController.cs | 8 +++++-- .../Editor/LookDev/Compositor.cs | 16 +++++++++---- .../Editor/LookDev/DisplayWindow.cs | 24 ++++++++++++------- .../Editor/LookDev/LookDev.cs | 17 ++++++++++--- .../Editor/LookDev/Stage.cs | 8 +++---- 6 files changed, 65 insertions(+), 30 deletions(-) diff --git a/com.unity.render-pipelines.core/Editor/LookDev/CameraController.cs b/com.unity.render-pipelines.core/Editor/LookDev/CameraController.cs index 26b67c5f1a6..a2271c88f3c 100644 --- a/com.unity.render-pipelines.core/Editor/LookDev/CameraController.cs +++ b/com.unity.render-pipelines.core/Editor/LookDev/CameraController.cs @@ -129,13 +129,17 @@ virtual protected bool isDragging } } - public CameraController(CameraState cameraState, DisplayWindow window, Action focused) + public CameraController(DisplayWindow window, Action focused) { - m_CameraState = cameraState; m_Window = window; m_Focused = focused; } + public void UpdateCameraState(Context context, ViewIndex index) + { + m_CameraState = context.GetViewContent(index).camera; + } + private void ResetCameraControl() { isDragging = false; @@ -458,16 +462,22 @@ class SwitchableCameraController : CameraController bool switchedDrag = false; bool switchedWheel = false; - public SwitchableCameraController(CameraState cameraStateFirstView, CameraState cameraStateSecondView, DisplayWindow window, Action focused) - : base(cameraStateFirstView, window, null) + public SwitchableCameraController(DisplayWindow window, Action focused) + : base(window, null) { - m_FirstView = cameraStateFirstView; - m_SecondView = cameraStateSecondView; m_CurrentViewIndex = ViewIndex.First; m_Focused = () => focused?.Invoke(m_CurrentViewIndex); } + public void UpdateCameraState(Context context) + { + m_FirstView = context.GetViewContent(ViewIndex.First).camera; + m_SecondView = context.GetViewContent(ViewIndex.Second).camera; + + m_CameraState = m_CurrentViewIndex == ViewIndex.First ? m_FirstView : m_SecondView; + } + void SwitchTo(ViewIndex index) { CameraState stateToSwitch; diff --git a/com.unity.render-pipelines.core/Editor/LookDev/ComparisonGizmoController.cs b/com.unity.render-pipelines.core/Editor/LookDev/ComparisonGizmoController.cs index 645fea46e53..9955fd6e923 100644 --- a/com.unity.render-pipelines.core/Editor/LookDev/ComparisonGizmoController.cs +++ b/com.unity.render-pipelines.core/Editor/LookDev/ComparisonGizmoController.cs @@ -49,12 +49,16 @@ bool isDragging } } - public ComparisonGizmoController(ComparisonGizmoState state, SwitchableCameraController switcher) + public ComparisonGizmoController(SwitchableCameraController switcher) { - m_State = state; m_Switcher = switcher; } + public void UpdateGizmoState(ComparisonGizmoState state) + { + m_State = state; + } + protected override void RegisterCallbacksOnTarget() { target.RegisterCallback(OnMouseDown); diff --git a/com.unity.render-pipelines.core/Editor/LookDev/Compositor.cs b/com.unity.render-pipelines.core/Editor/LookDev/Compositor.cs index bc2ce086b00..15698d250e4 100644 --- a/com.unity.render-pipelines.core/Editor/LookDev/Compositor.cs +++ b/com.unity.render-pipelines.core/Editor/LookDev/Compositor.cs @@ -150,17 +150,15 @@ public bool pixelPerfect public Compositer( IViewDisplayer displayer, - Context contexts, IDataProvider dataProvider, StageCache stages) { m_Displayer = displayer; - m_Contexts = contexts; m_RenderDataCache = new RenderingData[2] { - new RenderingData() { stage = stages[ViewIndex.First], updater = contexts.GetViewContent(ViewIndex.First).camera }, - new RenderingData() { stage = stages[ViewIndex.Second], updater = contexts.GetViewContent(ViewIndex.Second).camera } + new RenderingData() { stage = stages[ViewIndex.First] }, + new RenderingData() { stage = stages[ViewIndex.Second] } }; m_Displayer.OnRenderDocAcquisitionTriggered += RenderDocAcquisitionRequested; @@ -197,6 +195,12 @@ public void Dispose() public void Render() { + // This can happen when entering/leaving playmode. + if (LookDev.dataProvider == null) + return; + + m_Contexts = LookDev.currentContext; + //TODO: make integration EditorWindow agnostic! if (UnityEditorInternal.RenderDoc.IsLoaded() && UnityEditorInternal.RenderDoc.IsSupported() && m_RenderDocAcquisitionRequested) UnityEditorInternal.RenderDoc.BeginCaptureRenderDoc(m_Displayer as EditorWindow); @@ -236,11 +240,13 @@ void AcquireDataForView(ViewIndex index, Rect viewport) m_RenderTextures.UpdateSize(renderingData.viewPort, index, m_Renderer.pixelPerfect, renderingData.stage.camera); - int debugMode = m_Contexts.GetViewContent(index).debug.viewMode; + int debugMode = view.debug.viewMode; if (debugMode != -1) LookDev.dataProvider.UpdateDebugMode(debugMode); renderingData.output = m_RenderTextures[index, ShadowCompositionPass.MainView]; + renderingData.updater = view.camera; + m_Renderer.BeginRendering(renderingData, LookDev.dataProvider); m_Renderer.Acquire(renderingData); diff --git a/com.unity.render-pipelines.core/Editor/LookDev/DisplayWindow.cs b/com.unity.render-pipelines.core/Editor/LookDev/DisplayWindow.cs index 3f482e01847..ee8c36705a2 100644 --- a/com.unity.render-pipelines.core/Editor/LookDev/DisplayWindow.cs +++ b/com.unity.render-pipelines.core/Editor/LookDev/DisplayWindow.cs @@ -217,6 +217,10 @@ event Action IViewDisplayer.OnUpdateRequested StyleSheet styleSheet = null; StyleSheet styleSheetLight = null; + SwitchableCameraController m_FirstOrCompositeManipulator; + CameraController m_SecondManipulator; + ComparisonGizmoController m_GizmoManipulator; + void ReloadStyleSheets() { if (styleSheet == null || styleSheet.Equals(null)) @@ -395,9 +399,7 @@ void CreateViews() m_Views[(int)ViewIndex.Second] = new Image() { name = Style.k_SecondViewName, image = Texture2D.blackTexture }; m_ViewContainer.Add(m_Views[(int)ViewIndex.Second]); - var firstOrCompositeManipulator = new SwitchableCameraController( - LookDev.currentContext.GetViewContent(ViewIndex.First).camera, - LookDev.currentContext.GetViewContent(ViewIndex.Second).camera, + m_FirstOrCompositeManipulator = new SwitchableCameraController( this, index => { @@ -406,8 +408,7 @@ void CreateViews() if (sidePanel == SidePanel.Environment && environment != null && LookDev.currentContext.environmentLibrary != null) m_EnvironmentList.selectedIndex = LookDev.currentContext.environmentLibrary.IndexOf(environment); }); - var secondManipulator = new CameraController( - LookDev.currentContext.GetViewContent(ViewIndex.Second).camera, + m_SecondManipulator = new CameraController( this, () => { @@ -416,10 +417,10 @@ void CreateViews() if (sidePanel == SidePanel.Environment && environment != null && LookDev.currentContext.environmentLibrary != null) m_EnvironmentList.selectedIndex = LookDev.currentContext.environmentLibrary.IndexOf(environment); }); - var gizmoManipulator = new ComparisonGizmoController(LookDev.currentContext.layout.gizmoState, firstOrCompositeManipulator); - m_Views[(int)ViewIndex.First].AddManipulator(gizmoManipulator); //must take event first to switch the firstOrCompositeManipulator - m_Views[(int)ViewIndex.First].AddManipulator(firstOrCompositeManipulator); - m_Views[(int)ViewIndex.Second].AddManipulator(secondManipulator); + m_GizmoManipulator = new ComparisonGizmoController(m_FirstOrCompositeManipulator); + m_Views[(int)ViewIndex.First].AddManipulator(m_GizmoManipulator); //must take event first to switch the firstOrCompositeManipulator + m_Views[(int)ViewIndex.First].AddManipulator(m_FirstOrCompositeManipulator); + m_Views[(int)ViewIndex.Second].AddManipulator(m_SecondManipulator); m_NoObject1 = new Label(Style.k_DragAndDropObject); m_NoObject1.style.flexGrow = 1; @@ -667,6 +668,11 @@ void Update() Debug.LogError("LookDev is not supported: No SRP detected."); LookDev.Close(); } + + // All those states coming from the Contexts can become invalid after a domain reload so we need to update them. + m_FirstOrCompositeManipulator.UpdateCameraState(LookDev.currentContext); + m_SecondManipulator.UpdateCameraState(LookDev.currentContext, ViewIndex.Second); + m_GizmoManipulator.UpdateGizmoState(LookDev.currentContext.layout.gizmoState); } void OnGUI() diff --git a/com.unity.render-pipelines.core/Editor/LookDev/LookDev.cs b/com.unity.render-pipelines.core/Editor/LookDev/LookDev.cs index 0e7fb8c8285..756dacb06b9 100644 --- a/com.unity.render-pipelines.core/Editor/LookDev/LookDev.cs +++ b/com.unity.render-pipelines.core/Editor/LookDev/LookDev.cs @@ -28,7 +28,18 @@ internal static IDataProvider dataProvider internal static Context currentContext { //Lazy init: load it when needed instead in static even if you do not support lookdev - get => s_CurrentContext ?? (s_CurrentContext = LoadConfigInternal() ?? defaultContext); + get + { + if (s_CurrentContext == null || s_CurrentContext.Equals(null)) + { + s_CurrentContext = LoadConfigInternal(); + if (s_CurrentContext == null) + s_CurrentContext = defaultContext; + + ReloadStage(false); + } + return s_CurrentContext; + } private set => s_CurrentContext = value; } @@ -161,9 +172,9 @@ static void WaitingSRPReloadForConfiguringRenderer(int maxAttempt, bool reloadWi static void ConfigureRenderer(bool reloadWithTemporaryID) { s_Stages?.Dispose(); //clean previous occurrence on reloading - s_Stages = new StageCache(dataProvider, currentContext); + s_Stages = new StageCache(dataProvider); s_Compositor?.Dispose(); //clean previous occurrence on reloading - s_Compositor = new Compositer(s_ViewDisplayer, currentContext, dataProvider, s_Stages); + s_Compositor = new Compositer(s_ViewDisplayer, dataProvider, s_Stages); } static void LinkViewDisplayer() diff --git a/com.unity.render-pipelines.core/Editor/LookDev/Stage.cs b/com.unity.render-pipelines.core/Editor/LookDev/Stage.cs index 08551be06b2..d67d18bb966 100644 --- a/com.unity.render-pipelines.core/Editor/LookDev/Stage.cs +++ b/com.unity.render-pipelines.core/Editor/LookDev/Stage.cs @@ -284,7 +284,6 @@ class StageCache : IDisposable const string secondStageName = "LookDevSecondView"; Stage[] m_Stages; - Context m_Contexts; IDataProvider m_CurrentDataProvider; public Stage this[ViewIndex index] @@ -292,9 +291,8 @@ public Stage this[ViewIndex index] public bool initialized { get; private set; } - public StageCache(IDataProvider dataProvider, Context contexts) + public StageCache(IDataProvider dataProvider) { - m_Contexts = contexts; m_Stages = new Stage[2] { InitStage(ViewIndex.First, dataProvider), @@ -333,7 +331,7 @@ public void UpdateSceneObjects(ViewIndex index) Stage stage = this[index]; stage.Clear(); - var viewContent = m_Contexts.GetViewContent(index); + var viewContent = LookDev.currentContext.GetViewContent(index); if (viewContent == null) { viewContent.viewedInstanceInPreview = null; @@ -347,7 +345,7 @@ public void UpdateSceneObjects(ViewIndex index) public void UpdateSceneLighting(ViewIndex index, IDataProvider provider) { Stage stage = this[index]; - Environment environment = m_Contexts.GetViewContent(index).environment; + Environment environment = LookDev.currentContext.GetViewContent(index).environment; provider.UpdateSky(stage.camera, environment == null ? default : environment.sky, stage.runtimeInterface); From a22cfa418a09a2f0d8d175f63d61f4c64d3e80f7 Mon Sep 17 00:00:00 2001 From: slunity <37302815+slunity@users.noreply.github.com> Date: Tue, 12 Jan 2021 03:34:01 -0500 Subject: [PATCH 10/15] StackLit: Fix SG surface option property block to only display energy conserving specular color option for the specular input parametrization (similar to case 1257050) (#3060) --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + .../ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 0f666e7b367..1a1f0927c38 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed issue with shadow mask and area lights. - Fixed an issue with the capture callback (now includes post processing results). - Fixed decal draw order for ShaderGraph decal materials. +- Fixed StackLit ShaderGraph surface option property block to only display energy conserving specular color option for the specular parametrization (case 1257050) ### Changed - Removed the material pass probe volumes evaluation mode. diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs index 54def1e40d3..e4b45b590db 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs @@ -33,7 +33,10 @@ protected override void CreatePropertyGUI() // StackLit specific properties: AddProperty("Base Color Parametrization", () => stackLitData.baseParametrization, (newValue) => stackLitData.baseParametrization = newValue); - AddProperty("Energy Conserving Specular", () => stackLitData.energyConservingSpecular, (newValue) => stackLitData.energyConservingSpecular = newValue, 1); + if (stackLitData.baseParametrization == StackLit.BaseParametrization.SpecularColor) + { + AddProperty("Energy Conserving Specular", () => stackLitData.energyConservingSpecular, (newValue) => stackLitData.energyConservingSpecular = newValue, 1); + } // Material type enables: context.AddLabel("Material Core Features", 0); From a3c36a58f5b08018e61bbaa5332d52d0c4e06ab5 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Tue, 12 Jan 2021 10:28:49 +0100 Subject: [PATCH 11/15] Fixed missing BeginCameraRendering call for custom render mode of a Camera (#3063) --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + .../Runtime/RenderPipeline/HDRenderPipeline.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 1a1f0927c38..0db4c3650cd 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed an issue with the capture callback (now includes post processing results). - Fixed decal draw order for ShaderGraph decal materials. - Fixed StackLit ShaderGraph surface option property block to only display energy conserving specular color option for the specular parametrization (case 1257050) +- Fixed missing BeginCameraRendering call for custom render mode of a Camera. ### Changed - Removed the material pass probe volumes evaluation mode. diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 25a7bf2b45a..43b02e89aeb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1389,6 +1389,7 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c { skipRequest = true; // Execute custom render + UnityEngine.Rendering.RenderPipeline.BeginCameraRendering(renderContext, camera); additionalCameraData.ExecuteCustomRender(renderContext, hdCamera); } From d932606ec71acf21934892d7930f3532efaf458b Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Tue, 12 Jan 2021 14:25:18 +0100 Subject: [PATCH 12/15] Fix wrong merge --- .../Runtime/RenderPipeline/Camera/HDCamera.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index 5809a828396..93e690a7be8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -864,19 +864,26 @@ internal void UpdateCurrentSky(SkyManager skyManager) if (skyManager.lightingOverrideLayerMask != 0) { - SkySettings newSkyOverride = SkyManager.GetSkySetting(skyManager.lightingOverrideVolumeStack); - CloudSettings newCloudOverride = SkyManager.GetCloudSetting(skyManager.lightingOverrideVolumeStack); + // Now, see if we have a lighting override + // Update needs to happen before testing if the component is active other internal data structure are not properly updated yet. + VolumeManager.instance.Update(skyManager.lightingOverrideVolumeStack, volumeAnchor, skyManager.lightingOverrideLayerMask); - if ((m_LightingOverrideSky.skySettings != null && newSkyOverride == null) || - (m_LightingOverrideSky.cloudSettings != null && newCloudOverride == null)) + if (VolumeManager.instance.IsComponentActiveInMask(skyManager.lightingOverrideLayerMask)) { - // When we switch from override to no override, we need to make sure that the visual sky will actually be properly re-rendered. - // Resetting the visual sky hash will ensure that. - visualSky.skyParametersHash = -1; + SkySettings newSkyOverride = SkyManager.GetSkySetting(skyManager.lightingOverrideVolumeStack); + CloudSettings newCloudOverride = SkyManager.GetCloudSetting(skyManager.lightingOverrideVolumeStack); - m_LightingOverrideSky.skySettings = newSkyOverride; - m_LightingOverrideSky.cloudSettings = newCloudOverride; - lightingSky = m_LightingOverrideSky; + if ((m_LightingOverrideSky.skySettings != null && newSkyOverride == null) || + (m_LightingOverrideSky.cloudSettings != null && newCloudOverride == null)) + { + // When we switch from override to no override, we need to make sure that the visual sky will actually be properly re-rendered. + // Resetting the visual sky hash will ensure that. + visualSky.skyParametersHash = -1; + + m_LightingOverrideSky.skySettings = newSkyOverride; + m_LightingOverrideSky.cloudSettings = newCloudOverride; + lightingSky = m_LightingOverrideSky; + } } } } From 8d89719082f6bf6d3c3226dc173e7070c8045f8f Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Mon, 22 Mar 2021 10:42:10 +0100 Subject: [PATCH 13/15] Fixed C++ API change --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index fcde2841428..950e1586703 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1401,7 +1401,7 @@ ref List renderDatas var camera = m_ProbeCameraCache.GetOrCreate((viewerTransform, visibleProbe, j), Time.frameCount, CameraType.Reflection); foreach (var terrain in activeTerrains) - terrain.SetFreeUnusedRenderingResources(camera.GetInstanceID(), false); + terrain.SetKeepUnusedCameraRenderingResources(camera.GetInstanceID(), true); if (!camera.TryGetComponent(out var additionalCameraData)) { From 858b6616b4aa32f9e7fe1d85a47e8105e73e4ef1 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Fri, 26 Mar 2021 11:54:22 +0100 Subject: [PATCH 14/15] Use new no alloc API to retrieve active terrain list. --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 3597c664171..11065ce4c21 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -150,6 +150,7 @@ internal static HDRenderPipeline currentPipeline RenderStateBlock m_AlphaToMaskBlock; readonly List m_ActivePassVolumes = new List(6); + readonly List m_ActiveTerrains = new List(); // Detect when windows size is changing int m_MaxCameraWidth; @@ -1050,7 +1051,7 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c var dynResHandler = DynamicResolutionHandler.instance; dynResHandler.Update(m_Asset.currentPlatformRenderPipelineSettings.dynamicResolutionSettings); - var activeTerrains = Terrain.activeTerrains; + Terrain.FillActiveTerrainList(m_ActiveTerrains); // This syntax is awful and hostile to debugging, please don't use it... using (ListPool.Get(out List renderRequests)) @@ -1405,7 +1406,7 @@ ref List renderDatas { var camera = m_ProbeCameraCache.GetOrCreate((viewerTransform, visibleProbe, j), Time.frameCount, CameraType.Reflection); - foreach (var terrain in activeTerrains) + foreach (var terrain in m_ActiveTerrains) terrain.SetKeepUnusedCameraRenderingResources(camera.GetInstanceID(), true); if (!camera.TryGetComponent(out var additionalCameraData)) From 711d1700dcf83b48622eb145be1a7db585c0a46f Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Thu, 29 Apr 2021 10:53:05 +0200 Subject: [PATCH 15/15] Fixed API change --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index cbbb76a489f..712a9bc5cac 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1056,7 +1056,7 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c HDCamera.CleanUnused(); } - Terrain.FillActiveTerrainList(m_ActiveTerrains); + Terrain.GetActiveTerrains(m_ActiveTerrains); // This syntax is awful and hostile to debugging, please don't use it... using (ListPool.Get(out List renderRequests))