From 025a2b791e8c0b0e9f438d1ecf09b90773115b69 Mon Sep 17 00:00:00 2001 From: Chris Chu Date: Mon, 13 Sep 2021 05:17:57 +0800 Subject: [PATCH 1/6] Backport of https://github.com/Unity-Technologies/Graphics/commit/0d1d0f89318c244137f1c555168112be8b7ad6c3 --- .../CHANGELOG.md | 1 + .../2D/Shadows/ShadowCasterGroup2DManager.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 4c7aa1660a4..111dd3e3942 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed a case where camera dimension can be zero. [case 1321168](https://issuetracker.unity3d.com/issues/urp-attempting-to-get-camera-relative-temporary-rendertexture-is-thrown-when-tweening-the-viewport-rect-values-of-a-camera) - VFX: Fixed soft particles when HDR or Opaque texture isn't enabled - VFX: Fixed OpenGL soft particles fallback when depth texture isn't available +- Fixed an issue where ShadowCaster2Ds were sometimes being rendered twice in the editor while in playmode. ## [10.6.0] - 2021-04-29 diff --git a/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs b/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs index e90acc09857..c2b68fa94ea 100644 --- a/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs +++ b/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs @@ -2,8 +2,15 @@ using System.Collections.Generic; using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + namespace UnityEngine.Experimental.Rendering.Universal { +#if UNITY_EDITOR + [InitializeOnLoadAttribute] +#endif internal class ShadowCasterGroup2DManager { static List s_ShadowCasterGroups = null; @@ -11,6 +18,20 @@ internal class ShadowCasterGroup2DManager public static List shadowCasterGroups { get { return s_ShadowCasterGroups; } } +#if UNITY_EDITOR + static ShadowCasterGroup2DManager() + { + EditorApplication.playModeStateChanged += OnPlayModeStateChanged; + } + + private static void OnPlayModeStateChanged(PlayModeStateChange state) + { + if (state == PlayModeStateChange.ExitingEditMode || state == PlayModeStateChange.ExitingPlayMode) + s_ShadowCasterGroups.Clear(); + } + +#endif + public static void AddShadowCasterGroupToList(ShadowCasterGroup2D shadowCaster, List list) { int positionToInsert = 0; From 100de6eeb5fc8d14b94997f4e1e52cb2b5c0c2e3 Mon Sep 17 00:00:00 2001 From: Chris Chu Date: Mon, 13 Sep 2021 15:19:42 +0800 Subject: [PATCH 2/6] Added null check --- .../2D/Shadows/ShadowCasterGroup2DManager.cs | 2 +- .../Runtime/Materials/Lit.mat | 16 +++++++++++++++- .../Runtime/Materials/ParticlesUnlit.mat | 5 +++-- .../Runtime/Materials/SimpleLit.mat | 16 ++++++++++++++-- .../Runtime/Materials/TerrainLit.mat | 2 +- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs b/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs index c2b68fa94ea..72fa3657837 100644 --- a/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs +++ b/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs @@ -26,7 +26,7 @@ static ShadowCasterGroup2DManager() private static void OnPlayModeStateChanged(PlayModeStateChange state) { - if (state == PlayModeStateChange.ExitingEditMode || state == PlayModeStateChange.ExitingPlayMode) + if (s_ShadowCasterGroups != null && (state == PlayModeStateChange.ExitingEditMode || state == PlayModeStateChange.ExitingPlayMode)) s_ShadowCasterGroups.Clear(); } diff --git a/com.unity.render-pipelines.universal/Runtime/Materials/Lit.mat b/com.unity.render-pipelines.universal/Runtime/Materials/Lit.mat index 2d651471682..ee75030f91f 100644 --- a/com.unity.render-pipelines.universal/Runtime/Materials/Lit.mat +++ b/com.unity.render-pipelines.universal/Runtime/Materials/Lit.mat @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} m_Name: m_EditorClassIdentifier: - version: 4 + version: 5 --- !u!21 &2100000 Material: serializedVersion: 6 @@ -89,6 +89,18 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} m_Ints: [] m_Floats: - _AlphaClip: 0 @@ -96,8 +108,10 @@ Material: - _BumpScale: 1 - _ClearCoat: 0 - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 - _Cull: 2 - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 - _DetailNormalMapScale: 1 - _DstBlend: 0 - _EnvironmentReflections: 1 diff --git a/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat b/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat index 67b127d30c1..4a8fa9bf079 100644 --- a/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat +++ b/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} m_Name: m_EditorClassIdentifier: - version: 4 + version: 5 --- !u!21 &2100000 Material: serializedVersion: 6 @@ -26,12 +26,13 @@ Material: m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: 3050 + m_CustomRenderQueue: 3000 stringTagMap: RenderType: Transparent disabledShaderPasses: - ALWAYS - SHADOWCASTER + - DepthOnly m_SavedProperties: serializedVersion: 3 m_TexEnvs: diff --git a/com.unity.render-pipelines.universal/Runtime/Materials/SimpleLit.mat b/com.unity.render-pipelines.universal/Runtime/Materials/SimpleLit.mat index 7ae209e6ad4..2acc4b70dd8 100644 --- a/com.unity.render-pipelines.universal/Runtime/Materials/SimpleLit.mat +++ b/com.unity.render-pipelines.universal/Runtime/Materials/SimpleLit.mat @@ -60,6 +60,18 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} m_Ints: [] m_Floats: - _AlphaClip: 0 @@ -90,7 +102,7 @@ Material: - _ZWrite: 1 m_Colors: - _BaseColor: {r: 0.5, g: 0.5, b: 0.5, a: 0.5} - - _Color: {r: 0.5, g: 0.5, b: 0.5, a: 1} + - _Color: {r: 0.5, g: 0.5, b: 0.5, a: 0.5} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _SpecColor: {r: 0.5, g: 0.5, b: 0.5, a: 0.5} m_BuildTextureStacks: [] @@ -106,4 +118,4 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} m_Name: m_EditorClassIdentifier: - version: 4 + version: 5 diff --git a/com.unity.render-pipelines.universal/Runtime/Materials/TerrainLit.mat b/com.unity.render-pipelines.universal/Runtime/Materials/TerrainLit.mat index 07682e115a0..b16235f562b 100644 --- a/com.unity.render-pipelines.universal/Runtime/Materials/TerrainLit.mat +++ b/com.unity.render-pipelines.universal/Runtime/Materials/TerrainLit.mat @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} m_Name: m_EditorClassIdentifier: - version: 4 + version: 5 --- !u!21 &2100000 Material: serializedVersion: 6 From a45a19439fa14018739bc7a70aae5c10241ddfa6 Mon Sep 17 00:00:00 2001 From: Chris Chu Date: Thu, 27 Jan 2022 14:59:31 +0800 Subject: [PATCH 3/6] Restored CustomRenderQueue --- .../Runtime/Materials/ParticlesUnlit.mat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat b/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat index 4a8fa9bf079..ad8898ca58b 100644 --- a/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat +++ b/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat @@ -26,7 +26,7 @@ Material: m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: 3000 + m_CustomRenderQueue: 3050 stringTagMap: RenderType: Transparent disabledShaderPasses: From d44ae3466343c2856dfe83ca65bc36af77e4877f Mon Sep 17 00:00:00 2001 From: Chris Chu Date: Thu, 27 Jan 2022 18:02:56 +0800 Subject: [PATCH 4/6] Revert "Restored CustomRenderQueue" This reverts commit a45a19439fa14018739bc7a70aae5c10241ddfa6. --- .../Runtime/Materials/ParticlesUnlit.mat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat b/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat index ad8898ca58b..4a8fa9bf079 100644 --- a/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat +++ b/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat @@ -26,7 +26,7 @@ Material: m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: 3050 + m_CustomRenderQueue: 3000 stringTagMap: RenderType: Transparent disabledShaderPasses: From 8f8b4996d2e110b38715601a79feeeef075dbdfe Mon Sep 17 00:00:00 2001 From: Chris Chu Date: Thu, 27 Jan 2022 18:03:57 +0800 Subject: [PATCH 5/6] Reverted upgraded materials --- .../Runtime/Materials/Lit.mat | 16 +--------------- .../Runtime/Materials/ParticlesUnlit.mat | 5 ++--- .../Runtime/Materials/SimpleLit.mat | 16 ++-------------- .../Runtime/Materials/TerrainLit.mat | 2 +- 4 files changed, 6 insertions(+), 33 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/Materials/Lit.mat b/com.unity.render-pipelines.universal/Runtime/Materials/Lit.mat index ee75030f91f..2d651471682 100644 --- a/com.unity.render-pipelines.universal/Runtime/Materials/Lit.mat +++ b/com.unity.render-pipelines.universal/Runtime/Materials/Lit.mat @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} m_Name: m_EditorClassIdentifier: - version: 5 + version: 4 --- !u!21 &2100000 Material: serializedVersion: 6 @@ -89,18 +89,6 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - - unity_Lightmaps: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - unity_LightmapsInd: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - unity_ShadowMasks: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} m_Ints: [] m_Floats: - _AlphaClip: 0 @@ -108,10 +96,8 @@ Material: - _BumpScale: 1 - _ClearCoat: 0 - _ClearCoatMask: 0 - - _ClearCoatSmoothness: 0 - _Cull: 2 - _Cutoff: 0.5 - - _DetailAlbedoMapScale: 1 - _DetailNormalMapScale: 1 - _DstBlend: 0 - _EnvironmentReflections: 1 diff --git a/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat b/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat index 4a8fa9bf079..67b127d30c1 100644 --- a/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat +++ b/com.unity.render-pipelines.universal/Runtime/Materials/ParticlesUnlit.mat @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} m_Name: m_EditorClassIdentifier: - version: 5 + version: 4 --- !u!21 &2100000 Material: serializedVersion: 6 @@ -26,13 +26,12 @@ Material: m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: 3000 + m_CustomRenderQueue: 3050 stringTagMap: RenderType: Transparent disabledShaderPasses: - ALWAYS - SHADOWCASTER - - DepthOnly m_SavedProperties: serializedVersion: 3 m_TexEnvs: diff --git a/com.unity.render-pipelines.universal/Runtime/Materials/SimpleLit.mat b/com.unity.render-pipelines.universal/Runtime/Materials/SimpleLit.mat index 2acc4b70dd8..7ae209e6ad4 100644 --- a/com.unity.render-pipelines.universal/Runtime/Materials/SimpleLit.mat +++ b/com.unity.render-pipelines.universal/Runtime/Materials/SimpleLit.mat @@ -60,18 +60,6 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - - unity_Lightmaps: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - unity_LightmapsInd: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - unity_ShadowMasks: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} m_Ints: [] m_Floats: - _AlphaClip: 0 @@ -102,7 +90,7 @@ Material: - _ZWrite: 1 m_Colors: - _BaseColor: {r: 0.5, g: 0.5, b: 0.5, a: 0.5} - - _Color: {r: 0.5, g: 0.5, b: 0.5, a: 0.5} + - _Color: {r: 0.5, g: 0.5, b: 0.5, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _SpecColor: {r: 0.5, g: 0.5, b: 0.5, a: 0.5} m_BuildTextureStacks: [] @@ -118,4 +106,4 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} m_Name: m_EditorClassIdentifier: - version: 5 + version: 4 diff --git a/com.unity.render-pipelines.universal/Runtime/Materials/TerrainLit.mat b/com.unity.render-pipelines.universal/Runtime/Materials/TerrainLit.mat index b16235f562b..07682e115a0 100644 --- a/com.unity.render-pipelines.universal/Runtime/Materials/TerrainLit.mat +++ b/com.unity.render-pipelines.universal/Runtime/Materials/TerrainLit.mat @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} m_Name: m_EditorClassIdentifier: - version: 5 + version: 4 --- !u!21 &2100000 Material: serializedVersion: 6 From eb4c6cd0ec47e437d2cf88bce5d84c60498badf1 Mon Sep 17 00:00:00 2001 From: Chris Chu Date: Thu, 27 Jan 2022 21:40:05 +0800 Subject: [PATCH 6/6] Fix for changelog --- com.unity.render-pipelines.universal/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index e84223d6aa6..8c3015c7d38 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [10.10.0] +## [Unreleased] ### Fixed - Fixed an issue where ShadowCaster2Ds were sometimes being rendered twice in the editor while in playmode.