From 77bae015b386a74926f0a26ad206757557e6b829 Mon Sep 17 00:00:00 2001 From: JulienIgnace-Unity Date: Fri, 8 Jan 2021 14:01:58 +0100 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] [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 5/7] 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 c6bd7886e1c85f0199e2e1203aea9ba218172a90 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Mon, 11 Jan 2021 19:47:58 +0100 Subject: [PATCH 6/7] Fix undo redo on layered lit editor --- .../CHANGELOG.md | 1 + .../Material/LayeredLit/LayeredLitGUI.cs | 54 ++++++++++++------- .../Material/UIBlocks/LayerListUIBlock.cs | 38 +++++-------- 3 files changed, 48 insertions(+), 45 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 0f666e7b367..dbee509dd06 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 undo-redo on layered lit editor. ### Changed - Removed the material pass probe volumes evaluation mode. diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/LayeredLit/LayeredLitGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/LayeredLit/LayeredLitGUI.cs index d9083dba157..fbc15551b18 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/LayeredLit/LayeredLitGUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/LayeredLit/LayeredLitGUI.cs @@ -13,6 +13,7 @@ namespace UnityEditor.Rendering.HighDefinition internal struct SerializeableGUIDs { public string[] GUIDArray; + public bool[] withUV; } /// @@ -254,37 +255,27 @@ public static void SynchronizeAllLayers(Material material) AssetImporter materialImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(material.GetInstanceID())); Material[] layers = null; + bool[] withUV = null; // Material importer can be null when the selected material doesn't exists as asset (Material saved inside the scene) if (materialImporter != null) - InitializeMaterialLayers(material, ref layers); + InitializeMaterialLayers(material, ref layers, ref withUV); // We could have no userData in the assets, so test if we have load something - if (layers != null) + if (layers != null && withUV != null) { for (int i = 0; i < layerCount; ++i) { - SynchronizeLayerProperties(material, layers, i, true); + SynchronizeLayerProperties(material, i, layers[i], withUV[i]); } } } - public static void SynchronizeAllLayersProperties(Material material, Material[] materialLayers, bool excludeUVMappingProperties) - { - int numLayer = material.GetLayerCount(); - - for (int i = 0; i < numLayer; ++i) - { - SynchronizeLayerProperties(material, materialLayers, i, excludeUVMappingProperties); - } - } - // This function will look for all referenced lit material, and assign value from Lit to layered lit layers. // This is based on the naming of the variables, i.E BaseColor will match BaseColor0, if a properties shouldn't be override // put the name in the exclusionList below - public static void SynchronizeLayerProperties(Material material, Material[] layers, int layerIndex, bool excludeUVMappingProperties) + public static void SynchronizeLayerProperties(Material material, int layerIndex, Material layerMaterial, bool includeUVMappingProperties) { - Material layerMaterial = layers[layerIndex]; string[] exclusionList = { kTexWorldScale, kUVBase, kUVMappingMask, kUVDetail, kUVDetailsMappingMask }; if (layerMaterial != null) @@ -296,7 +287,7 @@ public static void SynchronizeLayerProperties(Material material, Material[] laye string propertyName = ShaderUtil.GetPropertyName(layerShader, i); string layerPropertyName = propertyName + layerIndex; - if (!exclusionList.Contains(propertyName) || !excludeUVMappingProperties) + if (includeUVMappingProperties || !exclusionList.Contains(propertyName)) { if (material.HasProperty(layerPropertyName)) { @@ -322,7 +313,7 @@ public static void SynchronizeLayerProperties(Material material, Material[] laye case ShaderUtil.ShaderPropertyType.TexEnv: { material.SetTexture(layerPropertyName, layerMaterial.GetTexture(propertyName)); - if (!excludeUVMappingProperties) + if (includeUVMappingProperties) { material.SetTextureOffset(layerPropertyName, layerMaterial.GetTextureOffset(propertyName)); material.SetTextureScale(layerPropertyName, layerMaterial.GetTextureScale(propertyName)); @@ -338,10 +329,14 @@ public static void SynchronizeLayerProperties(Material material, Material[] laye // We use the user data to save a string that represent the referenced lit material // so we can keep reference during serialization - public static void InitializeMaterialLayers(Material material, ref Material[] layers) + public static void InitializeMaterialLayers(Material material, ref Material[] layers, ref bool[] withUV) { AssetImporter materialImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(material.GetInstanceID())); + InitializeMaterialLayers(materialImporter, ref layers, ref withUV); + } + public static void InitializeMaterialLayers(AssetImporter materialImporter, ref Material[] layers, ref bool[] withUV) + { if (materialImporter.userData != string.Empty) { SerializeableGUIDs layersGUID = JsonUtility.FromJson(materialImporter.userData); @@ -353,19 +348,40 @@ public static void InitializeMaterialLayers(Material material, ref Material[] la layers[i] = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(layersGUID.GUIDArray[i]), typeof(Material)) as Material; } } + if (layersGUID.withUV.Length > 0) + { + withUV = new bool[layersGUID.withUV.Length]; + for (int i = 0; i < layersGUID.withUV.Length; ++i) + withUV[i] = layersGUID.withUV[i]; + } + } + else + { + if (layers != null) + { + for (int i = 0; i < layers.Length; ++i) + layers[i] = null; + } + if (withUV != null) + { + for (int i = 0; i < withUV.Length; ++i) + withUV[i] = true; + } } } - public static void SaveMaterialLayers(Material material, Material[] materialLayers) + public static void SaveMaterialLayers(Material material, Material[] materialLayers, bool[] withUV) { AssetImporter materialImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(material.GetInstanceID())); SerializeableGUIDs layersGUID; layersGUID.GUIDArray = new string[materialLayers.Length]; + layersGUID.withUV = new bool[withUV.Length]; for (int i = 0; i < materialLayers.Length; ++i) { if (materialLayers[i] != null) layersGUID.GUIDArray[i] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(materialLayers[i].GetInstanceID())); + layersGUID.withUV[i] = withUV[i]; } materialImporter.userData = JsonUtility.ToJson(layersGUID); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LayerListUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LayerListUIBlock.cs index 01529ff8e52..ff91945e624 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LayerListUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LayerListUIBlock.cs @@ -35,7 +35,7 @@ internal class Styles MaterialProperty layerCount = null; ExpandableBit m_ExpandableBit; - bool[] m_WithUV; + bool[] m_WithUV = new bool[kMaxLayerCount]; Material[] m_MaterialLayers = new Material[kMaxLayerCount]; AssetImporter m_MaterialImporter; @@ -69,7 +69,6 @@ void UpdateEditorExpended(int layerNumber) public LayerListUIBlock(ExpandableBit expandableBit) { m_ExpandableBit = expandableBit; - m_WithUV = new bool[] { true, true, true, true }; } /// @@ -86,25 +85,7 @@ public override void LoadMaterialProperties() // Material importer can be null when the selected material doesn't exists as asset (Material saved inside the scene) if (m_MaterialImporter != null) - InitializeMaterialLayers(m_MaterialImporter, ref m_MaterialLayers); - } - - // We use the user data to save a string that represent the referenced lit material - // so we can keep reference during serialization - static void InitializeMaterialLayers(AssetImporter materialImporter, ref Material[] layers) - { - if (materialImporter.userData != string.Empty) - { - SerializeableGUIDs layersGUID = JsonUtility.FromJson(materialImporter.userData); - if (layersGUID.GUIDArray.Length > 0) - { - layers = new Material[layersGUID.GUIDArray.Length]; - for (int i = 0; i < layersGUID.GUIDArray.Length; ++i) - { - layers[i] = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(layersGUID.GUIDArray[i]), typeof(Material)) as Material; - } - } - } + LayeredLitGUI.InitializeMaterialLayers(m_MaterialImporter, ref m_MaterialLayers, ref m_WithUV); } /// @@ -153,19 +134,18 @@ void DrawLayerListGUI() { using (new EditorGUILayout.HorizontalScope()) { - EditorGUI.BeginChangeCheck(); - Rect lineRect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight); Rect colorRect = new Rect(lineRect.x + 17f, lineRect.y + 7f, colorWidth, colorWidth); Rect materialRect = new Rect(lineRect.x + padding + colorRect.width, lineRect.y, lineRect.width - UVWidth - padding - 3 - resetButtonWidth + endOffset, lineRect.height); Rect uvRect = new Rect(lineRect.x + lineRect.width - resetButtonWidth - padding - UVWidth - endOffset, lineRect.y, UVWidth, lineRect.height); Rect resetRect = new Rect(lineRect.x + lineRect.width - resetButtonWidth - endOffset, lineRect.y, resetButtonWidth, lineRect.height); + EditorGUI.BeginChangeCheck(); m_MaterialLayers[layerIndex] = EditorGUI.ObjectField(materialRect, Styles.layerLabels[layerIndex], m_MaterialLayers[layerIndex], typeof(Material), allowSceneObjects: true) as Material; if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(new UnityEngine.Object[] { material, m_MaterialImporter }, "Change layer material"); - LayeredLitGUI.SynchronizeLayerProperties(material, m_MaterialLayers, layerIndex, true); + LayeredLitGUI.SynchronizeLayerProperties(material, layerIndex, m_MaterialLayers[layerIndex], m_WithUV[layerIndex]); layersChanged = true; // Update external reference. @@ -178,12 +158,18 @@ void DrawLayerListGUI() EditorGUI.DrawRect(colorRect, kLayerColors[layerIndex]); + EditorGUI.BeginChangeCheck(); m_WithUV[layerIndex] = EditorGUI.Toggle(uvRect, m_WithUV[layerIndex]); + if (EditorGUI.EndChangeCheck()) + { + Undo.RecordObjects(new UnityEngine.Object[] { material, m_MaterialImporter }, "Change layer material"); + layersChanged = true; + } if (GUI.Button(resetRect, GUIContent.none)) { Undo.RecordObjects(new UnityEngine.Object[] { material, m_MaterialImporter }, "Reset layer material"); - LayeredLitGUI.SynchronizeLayerProperties(material, m_MaterialLayers, layerIndex, !m_WithUV[layerIndex]); + LayeredLitGUI.SynchronizeLayerProperties(material, layerIndex, m_MaterialLayers[layerIndex], m_WithUV[layerIndex]); layersChanged = true; } @@ -212,7 +198,7 @@ void DrawLayerListGUI() // SaveAssetsProcessor the referenced material in the users data if (m_MaterialImporter != null) - LayeredLitGUI.SaveMaterialLayers(material, m_MaterialLayers); + LayeredLitGUI.SaveMaterialLayers(material, m_MaterialLayers, m_WithUV); // We should always do this call at the end materialEditor.serializedObject.ApplyModifiedProperties(); From d20830e1228e32952c83c8ae319c0e29fe9f6e58 Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Thu, 14 Jan 2021 14:38:41 +0100 Subject: [PATCH 7/7] Update CHANGELOG.md --- 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 14f9d78aef5..53dd173b264 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed after post process custom pass scale issue when dynamic resolution is enabled (case 1299194). - Fixed an issue with light intensity prefab override application not visible in the inspector (case 1299563). - Fixed Undo/Redo instability of light temperature. +- Fixed undo-redo on layered lit editor. ### Changed - Change the source value for the ray tracing frame index iterator from m_FrameCount to the camera frame count (case 1301356).