diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 12c7a69b7e5..dbabe38173b 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Removed experimental tile deferred code. ### 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) - URP asset can now use multi-edit. [case 1364966](https://issuetracker.unity3d.com/issues/urp-universalrenderpipelineasset-does-not-support-multi-edit) ## [12.0.0] - 2021-01-11 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..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 { @@ -20,6 +21,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 +51,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); diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs index 998111f9cf9..5121ecbb5fd 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,24 @@ 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 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"); + 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) {