From ad11245a78d1a34e4243cf3703d44ed830c6fd3d Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 25 Aug 2021 13:41:27 +0300 Subject: [PATCH 1/5] Fixed lit detail correctly upgraded from standard shader. [1323725] --- .../UniversalRenderPipelineMaterialUpgrader.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs index 998111f9cf9..396a88648c3 100644 --- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs +++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs @@ -373,6 +373,7 @@ public static void UpdateStandardMaterialKeywords(Material material) CoreUtils.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap")); CoreUtils.SetKeyword(material, "_METALLICSPECGLOSSMAP", material.GetTexture("_MetallicGlossMap")); UpdateSurfaceTypeAndBlendMode(material); + UpdateDetailScaleOffset(material); BaseShaderGUI.SetupMaterialBlendMode(material); } @@ -391,9 +392,22 @@ public static void UpdateStandardSpecularMaterialKeywords(Material material) CoreUtils.SetKeyword(material, "_METALLICSPECGLOSSMAP", material.GetTexture("_SpecGlossMap")); CoreUtils.SetKeyword(material, "_SPECULAR_SETUP", true); UpdateSurfaceTypeAndBlendMode(material); + UpdateDetailScaleOffset(material); BaseShaderGUI.SetupMaterialBlendMode(material); } + static void UpdateDetailScaleOffset(Material material) + { + // In URP details tile/offset is tied to base map tile offset + var baseScale = material.GetTextureScale("_BaseMap"); + var baseOffset = material.GetTextureOffset("_BaseMap"); + var detailScale = material.GetTextureScale("_DetailAlbedoMap"); + var detailOffset = material.GetTextureOffset("_DetailAlbedoMap"); + var scale = new Vector2(baseScale.x == 0 ? 0 : detailScale.x / baseScale.x, baseScale.y == 0 ? 0 : detailScale.y / baseScale.y); + material.SetTextureScale("_DetailAlbedoMap", scale); + material.SetTextureOffset("_DetailAlbedoMap", new Vector2((detailOffset.x - baseOffset.x * scale.x), (detailOffset.y - baseOffset.y * scale.y))); + } + // Converts from legacy RenderingMode to new SurfaceType and BlendMode static void UpdateSurfaceTypeAndBlendMode(Material material) { From bdec5978ec5dee88944087b2dc1a1f2dd1ca14c1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 25 Aug 2021 15:02:49 +0300 Subject: [PATCH 2/5] Added warning for lit shader detailed abledo, if texture is not linear. [1342011] --- .../Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs b/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs index 5582eea33bd..ebf8c324242 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs @@ -20,6 +20,7 @@ public static class Styles "Designates a Normal Map to create the illusion of bumps and dents in the details of this Material's surface."); public static readonly GUIContent detailAlbedoMapScaleInfo = EditorGUIUtility.TrTextContent("Setting the scaling factor to a value other than 1 results in a less performant shader variant."); + public static readonly GUIContent detailAlbedoMapFormatError = EditorGUIUtility.TrTextContent("This texture is not in linear space."); } public struct LitProperties @@ -49,6 +50,11 @@ public static void DoDetailArea(LitProperties properties, MaterialEditor materia { EditorGUILayout.HelpBox(Styles.detailAlbedoMapScaleInfo.text, MessageType.Info, true); } + var detailAlbedoTexture = properties.detailAlbedoMap.textureValue as Texture2D; + if (detailAlbedoTexture != null && GraphicsFormatUtility.IsSRGBFormat(detailAlbedoTexture.graphicsFormat)) + { + EditorGUILayout.HelpBox(Styles.detailAlbedoMapFormatError.text, MessageType.Warning, true); + } materialEditor.TexturePropertySingleLine(Styles.detailNormalMapText, properties.detailNormalMap, properties.detailNormalMap.textureValue != null ? properties.detailNormalMapScale : null); materialEditor.TextureScaleOffsetProperty(properties.detailAlbedoMap); From 95c39836dc866121565940b82f499938a79abd33 Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 25 Aug 2021 15:04:22 +0300 Subject: [PATCH 3/5] Updating changelog --- com.unity.render-pipelines.universal/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index c47278f8f54..95ba07f0174 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -168,6 +168,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Support undo of URP Global Settings asset assignation (case 1342987). - Removed unsupported fields from Presets of Light and Camera [case 1335979]. - Fixed an issue where Unlit and ParticlesUnlit shaders did not have HDR color selection for albedo [case 1283767](https://issuetracker.unity3d.com/issues/built-in-unlit-particle-shader-has-hdr-color-selection-for-albedo-urp-unlit-particles-do-not) +- Added warning for lit shader detailed abledo, if texture is not linear. [1342011](https://issuetracker.unity3d.com/issues/detail-maps-packed-differently-in-built-in-vs-urp) +- Fixed lit detail correctly upgraded from standard shader. [1323725](https://issuetracker.unity3d.com/issues/urp-detail-map-tiling-is-tied-to-base-texture-tiling) ### Changed - Change Asset/Create/Shader/Universal Render Pipeline/Lit Shader Graph to Asset/Create/Shader Graph/URP/Lit Shader Graph From 989685f024f93b05d1d72754fe9ba11809231103 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Aug 2021 11:56:44 +0300 Subject: [PATCH 4/5] Adding missing namespace --- .../Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs b/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs index ebf8c324242..3c441836550 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEngine.Rendering; +using UnityEngine.Experimental.Rendering; namespace UnityEditor.Rendering.Universal.ShaderGUI { From 5b796c94a1857c4405d4fa6caa4803c96e58ae4a Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 7 Sep 2021 12:02:32 +0300 Subject: [PATCH 5/5] Updating changelog and extending comments --- com.unity.render-pipelines.universal/CHANGELOG.md | 7 ++++--- .../Editor/UniversalRenderPipelineMaterialUpgrader.cs | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 9d61b0044a4..6d4cc5361a0 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - URP global setting for stripping post processing shader variants. - URP global setting for stripping off shader variants. +### Fixed +- Added warning for lit shader detailed abledo, if texture is not linear. [1342011](https://issuetracker.unity3d.com/issues/detail-maps-packed-differently-in-built-in-vs-urp) +- Fixed lit detail correctly upgraded from standard shader. [1323725](https://issuetracker.unity3d.com/issues/urp-detail-map-tiling-is-tied-to-base-texture-tiling) + ## [12.0.0] - 2021-01-11 ### Added - Added support for default sprite mask shaders for the 2D Renderer in URP. @@ -176,9 +180,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix sporadic NaN when using normal maps with XYZ-encoding [case 1351020](https://issuetracker.unity3d.com/issues/android-urp-vulkan-nan-pixels-and-bloom-post-processing-generates-visual-artifacts) - Support undo of URP Global Settings asset assignation (case 1342987). - Removed unsupported fields from Presets of Light and Camera [case 1335979]. -- Fixed an issue where Unlit and ParticlesUnlit shaders did not have HDR color selection for albedo [case 1283767](https://issuetracker.unity3d.com/issues/built-in-unlit-particle-shader-has-hdr-color-selection-for-albedo-urp-unlit-particles-do-not) -- Added warning for lit shader detailed abledo, if texture is not linear. [1342011](https://issuetracker.unity3d.com/issues/detail-maps-packed-differently-in-built-in-vs-urp) -- Fixed lit detail correctly upgraded from standard shader. [1323725](https://issuetracker.unity3d.com/issues/urp-detail-map-tiling-is-tied-to-base-texture-tiling) - Fixed graphical artefact when terrain height map is used with rendering layer mask for lighting. ### Changed diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs index 396a88648c3..5121ecbb5fd 100644 --- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs +++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs @@ -398,7 +398,9 @@ public static void UpdateStandardSpecularMaterialKeywords(Material material) static void UpdateDetailScaleOffset(Material material) { - // In URP details tile/offset is tied to base map tile offset + // In URP details tile/offset is multipied with base tile/offset, where in builtin is not + // Basically we setup new tile/offset values that in shader they would result in same values as in builtin + // This archieved with inverted calculation where scale=detailScale/baseScale and tile=detailOffset-baseOffset*scale var baseScale = material.GetTextureScale("_BaseMap"); var baseOffset = material.GetTextureOffset("_BaseMap"); var detailScale = material.GetTextureScale("_DetailAlbedoMap");