Skip to content

Commit 6c19563

Browse files
authored
[URP] Lit Shader Detail Fixes (#5432)
* Fixed lit detail correctly upgraded from standard shader. [1323725] * Added warning for lit shader detailed abledo, if texture is not linear. [1342011] * Updating changelog * Adding missing namespace * Updating changelog and extending comments
1 parent 3d04eb8 commit 6c19563

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

com.unity.render-pipelines.universal/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
- Removed experimental tile deferred code.
1414

1515
### Fixed
16+
- 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)
17+
- Fixed lit detail correctly upgraded from standard shader. [1323725](https://issuetracker.unity3d.com/issues/urp-detail-map-tiling-is-tied-to-base-texture-tiling)
1618
- URP asset can now use multi-edit. [case 1364966](https://issuetracker.unity3d.com/issues/urp-universalrenderpipelineasset-does-not-support-multi-edit)
1719

1820
## [12.0.0] - 2021-01-11

com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using UnityEngine.Rendering;
3+
using UnityEngine.Experimental.Rendering;
34

45
namespace UnityEditor.Rendering.Universal.ShaderGUI
56
{
@@ -20,6 +21,7 @@ public static class Styles
2021
"Designates a Normal Map to create the illusion of bumps and dents in the details of this Material's surface.");
2122

2223
public static readonly GUIContent detailAlbedoMapScaleInfo = EditorGUIUtility.TrTextContent("Setting the scaling factor to a value other than 1 results in a less performant shader variant.");
24+
public static readonly GUIContent detailAlbedoMapFormatError = EditorGUIUtility.TrTextContent("This texture is not in linear space.");
2325
}
2426

2527
public struct LitProperties
@@ -49,6 +51,11 @@ public static void DoDetailArea(LitProperties properties, MaterialEditor materia
4951
{
5052
EditorGUILayout.HelpBox(Styles.detailAlbedoMapScaleInfo.text, MessageType.Info, true);
5153
}
54+
var detailAlbedoTexture = properties.detailAlbedoMap.textureValue as Texture2D;
55+
if (detailAlbedoTexture != null && GraphicsFormatUtility.IsSRGBFormat(detailAlbedoTexture.graphicsFormat))
56+
{
57+
EditorGUILayout.HelpBox(Styles.detailAlbedoMapFormatError.text, MessageType.Warning, true);
58+
}
5259
materialEditor.TexturePropertySingleLine(Styles.detailNormalMapText, properties.detailNormalMap,
5360
properties.detailNormalMap.textureValue != null ? properties.detailNormalMapScale : null);
5461
materialEditor.TextureScaleOffsetProperty(properties.detailAlbedoMap);

com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ public static void UpdateStandardMaterialKeywords(Material material)
373373
CoreUtils.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap"));
374374
CoreUtils.SetKeyword(material, "_METALLICSPECGLOSSMAP", material.GetTexture("_MetallicGlossMap"));
375375
UpdateSurfaceTypeAndBlendMode(material);
376+
UpdateDetailScaleOffset(material);
376377
BaseShaderGUI.SetupMaterialBlendMode(material);
377378
}
378379

@@ -391,9 +392,24 @@ public static void UpdateStandardSpecularMaterialKeywords(Material material)
391392
CoreUtils.SetKeyword(material, "_METALLICSPECGLOSSMAP", material.GetTexture("_SpecGlossMap"));
392393
CoreUtils.SetKeyword(material, "_SPECULAR_SETUP", true);
393394
UpdateSurfaceTypeAndBlendMode(material);
395+
UpdateDetailScaleOffset(material);
394396
BaseShaderGUI.SetupMaterialBlendMode(material);
395397
}
396398

399+
static void UpdateDetailScaleOffset(Material material)
400+
{
401+
// In URP details tile/offset is multipied with base tile/offset, where in builtin is not
402+
// Basically we setup new tile/offset values that in shader they would result in same values as in builtin
403+
// This archieved with inverted calculation where scale=detailScale/baseScale and tile=detailOffset-baseOffset*scale
404+
var baseScale = material.GetTextureScale("_BaseMap");
405+
var baseOffset = material.GetTextureOffset("_BaseMap");
406+
var detailScale = material.GetTextureScale("_DetailAlbedoMap");
407+
var detailOffset = material.GetTextureOffset("_DetailAlbedoMap");
408+
var scale = new Vector2(baseScale.x == 0 ? 0 : detailScale.x / baseScale.x, baseScale.y == 0 ? 0 : detailScale.y / baseScale.y);
409+
material.SetTextureScale("_DetailAlbedoMap", scale);
410+
material.SetTextureOffset("_DetailAlbedoMap", new Vector2((detailOffset.x - baseOffset.x * scale.x), (detailOffset.y - baseOffset.y * scale.y)));
411+
}
412+
397413
// Converts from legacy RenderingMode to new SurfaceType and BlendMode
398414
static void UpdateSurfaceTypeAndBlendMode(Material material)
399415
{

0 commit comments

Comments
 (0)