Skip to content

Commit 63750d1

Browse files
Fixed LayeredLit test scene for UV3 case (data was corrupted by Vertex Tool Pro...)
1 parent 5a4d8fc commit 63750d1

File tree

12 files changed

+3045
-3077
lines changed

12 files changed

+3045
-3077
lines changed

Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/Editor/LayeredLitUI.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ public enum LayerUVBaseMapping
1717
Triplanar,
1818
}
1919

20-
public enum LayerUVDetailMapping
21-
{
22-
UV0,
23-
UV1,
24-
UV3
25-
}
26-
2720
private class StylesLayer
2821
{
2922
public readonly GUIContent[] layerLabels =
@@ -77,8 +70,10 @@ internal struct SerializeableGUIDs
7770
MaterialProperty layerEmissiveColorMap = null;
7871
MaterialProperty layerEmissiveIntensity = null;
7972

80-
private void FindLayerProperties(MaterialProperty[] props)
73+
override protected void FindMaterialProperties(MaterialProperty[] props)
8174
{
75+
FindMaterialOptionProperties(props);
76+
8277
layerMaskMap = FindProperty(kLayerMaskMap, props);
8378
layerMaskVertexColor = FindProperty(kLayerMaskVertexColor, props);
8479
layerCount = FindProperty(kLayerCount, props);
@@ -451,8 +446,11 @@ bool DoLayersGUI(AssetImporter materialImporter)
451446
return layerChanged;
452447
}
453448

454-
protected override void SetupKeywordsForInputMaps(Material material)
449+
protected override void SetupMaterialKeywords(Material material)
455450
{
451+
SetupCommonOptionsKeywords(material);
452+
SetupLayersKeywords(material);
453+
456454
// Find first non null layer
457455
int i = 0;
458456
while (i < numLayer && (m_MaterialLayers[i] == null)) ++i;
@@ -468,9 +466,26 @@ protected override void SetupKeywordsForInputMaps(Material material)
468466

469467
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));
470468
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR", material.GetFloat(kLayerMaskVertexColor) != 0.0f);
469+
470+
// We have to check for each layer if the UV3 is needed.
471+
SetKeyword(material, "_REQUIRE_UV3", false);
472+
for (int layer = 0; layer < numLayer; ++layer)
473+
{
474+
string uvBase = string.Format("{0}{1}", kUVBase, layer);
475+
string uvDetail = string.Format("{0}{1}", kUVDetail, layer);
476+
477+
if (
478+
((UVDetailMapping)material.GetFloat(uvDetail) == UVDetailMapping.UV3) ||
479+
((LayerUVBaseMapping)material.GetFloat(uvBase) == LayerUVBaseMapping.UV3)
480+
)
481+
{
482+
SetKeyword(material, "_REQUIRE_UV3", true);
483+
break;
484+
}
485+
}
471486
}
472487

473-
void SetupMaterialForLayers(Material material)
488+
void SetupLayersKeywords(Material material)
474489
{
475490
if (numLayer == 4)
476491
{
@@ -497,7 +512,7 @@ void SetupMaterialForLayers(Material material)
497512
string layerUVBaseParam = string.Format("{0}{1}", kUVBase, i);
498513
LayerUVBaseMapping layerUVBaseMapping = (LayerUVBaseMapping)material.GetFloat(layerUVBaseParam);
499514
string layerUVDetailParam = string.Format("{0}{1}", kUVDetail, i);
500-
LayerUVDetailMapping layerUVDetailMapping = (LayerUVDetailMapping)material.GetFloat(layerUVDetailParam);
515+
UVDetailMapping layerUVDetailMapping = (UVDetailMapping)material.GetFloat(layerUVDetailParam);
501516
string currentLayerMappingTriplanar = string.Format("{0}{1}", kLayerMappingTriplanar, i);
502517

503518
float X, Y, Z, W;
@@ -516,18 +531,18 @@ void SetupMaterialForLayers(Material material)
516531
}
517532
else
518533
{
519-
X = (layerUVDetailMapping == LayerUVDetailMapping.UV0) ? 1.0f : 0.0f;
520-
Y = (layerUVDetailMapping == LayerUVDetailMapping.UV1) ? 1.0f : 0.0f;
521-
Z = (layerUVDetailMapping == LayerUVDetailMapping.UV3) ? 1.0f : 0.0f;
534+
X = (layerUVDetailMapping == UVDetailMapping.UV0) ? 1.0f : 0.0f;
535+
Y = (layerUVDetailMapping == UVDetailMapping.UV1) ? 1.0f : 0.0f;
536+
Z = (layerUVDetailMapping == UVDetailMapping.UV3) ? 1.0f : 0.0f;
522537
}
523538
layerUVDetailsMappingMask[i].colorValue = new Color(X, Y, Z, 0.0f); // W Reuse planar mode from base
524539
}
525540
}
526541

527542
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
528543
{
529-
FindOptionProperties(props);
530-
FindLayerProperties(props);
544+
FindCommonOptionProperties(props);
545+
FindMaterialProperties(props);
531546

532547
m_MaterialEditor = materialEditor;
533548

@@ -567,8 +582,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
567582

568583
foreach (var obj in m_MaterialEditor.targets)
569584
{
570-
SetupMaterial((Material)obj);
571-
SetupMaterialForLayers((Material)obj);
585+
SetupMaterialKeywords((Material)obj);
572586
}
573587

574588
SaveMaterialLayers(materialImporter);

Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/LayeredLit.shader

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,6 @@ Shader "HDRenderLoop/LayeredLit"
158158
[HideInInspector] _UVDetailsMappingMask1("_UVDetailsMappingMask1", Color) = (1, 0, 0, 0)
159159
[HideInInspector] _UVDetailsMappingMask2("_UVDetailsMappingMask2", Color) = (1, 0, 0, 0)
160160
[HideInInspector] _UVDetailsMappingMask3("_UVDetailsMappingMask3", Color) = (1, 0, 0, 0)
161-
162-
// Unused but to be able to share litUI.Sahder and layeredUI.Shader
163-
[HideInInspector] _UVBase("UV Set for base", Float) = 0
164-
[HideInInspector] _UVDetail("UV Set for base", Float) = 0
165-
[HideInInspector] _TexWorldScale("Tiling", Float) = 1.0
166-
[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0)
167-
[HideInInspector] _UVDetailsMappingMask("_UVDetailsMappingMask", Color) = (1, 0, 0, 0)
168161
}
169162

170163
HLSLINCLUDE

Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/BaseLitUI.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,16 @@ private void BlendModePopup()
145145
EditorGUI.showMixedValue = false;
146146
}
147147

148-
protected void FindOptionProperties(MaterialProperty[] props)
148+
protected void FindCommonOptionProperties(MaterialProperty[] props)
149149
{
150150
surfaceType = FindProperty(kSurfaceType, props);
151151
blendMode = FindProperty(kBlendMode, props);
152152
alphaCutoff = FindProperty(kAlphaCutoff, props);
153153
alphaCutoffEnable = FindProperty(kAlphaCutoffEnabled, props);
154154
doubleSidedMode = FindProperty(kDoubleSidedMode, props);
155-
FindInputOptionProperties(props);
156155
}
157156

158-
protected void SetupMaterial(Material material)
157+
protected void SetupCommonOptionsKeywords(Material material)
159158
{
160159
bool alphaTestEnable = material.GetFloat(kAlphaCutoffEnabled) == 1.0;
161160
SurfaceType surfaceType = (SurfaceType)material.GetFloat(kSurfaceType);
@@ -231,7 +230,7 @@ protected void SetupMaterial(Material material)
231230
}
232231

233232
SetKeyword(material, "_ALPHATEST_ON", alphaTestEnable);
234-
SetupInputMaterial(material);
233+
235234
SetupEmissionGIFlags(material);
236235
}
237236

@@ -263,14 +262,14 @@ public void ShaderPropertiesGUI(Material material)
263262
if (EditorGUI.EndChangeCheck())
264263
{
265264
foreach (var obj in m_MaterialEditor.targets)
266-
SetupMaterial((Material)obj);
265+
SetupMaterialKeywords((Material)obj);
267266
}
268267
}
269268

270269
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
271270
{
272-
FindOptionProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
273-
FindInputProperties(props);
271+
FindCommonOptionProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
272+
FindMaterialProperties(props);
274273

275274
m_MaterialEditor = materialEditor;
276275
Material material = materialEditor.target as Material;
@@ -324,11 +323,10 @@ protected virtual void SetupEmissionGIFlags(Material material)
324323
const string kDoubleSidedMode = "_DoubleSidedMode";
325324
protected static string[] reservedProperties = new string[] { kSurfaceType, kBlendMode, kAlphaCutoff, kAlphaCutoffEnabled, kDoubleSidedMode };
326325

327-
protected abstract void FindInputProperties(MaterialProperty[] props);
328-
protected abstract void ShaderInputGUI();
326+
protected abstract void FindMaterialProperties(MaterialProperty[] props);
327+
protected abstract void ShaderInputGUI();
329328
protected abstract void ShaderInputOptionsGUI();
330-
protected abstract void FindInputOptionProperties(MaterialProperty[] props);
331-
protected abstract void SetupInputMaterial(Material material);
329+
protected abstract void SetupMaterialKeywords(Material material);
332330
protected abstract bool ShouldEmissionBeEnabled(Material material);
333331
}
334332
} // namespace UnityEditor

Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/LitUI.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,21 @@ public enum EmissiveColorMode
123123
protected MaterialProperty emissiveIntensity = null;
124124
protected const string kEmissiveIntensity = "_EmissiveIntensity";
125125

126-
override protected void FindInputOptionProperties(MaterialProperty[] props)
126+
// These are options that are shared with the LayeredLit shader. Don't put anything that can't be shared here:
127+
// For instance, properties like BaseColor and such don't exist in the LayeredLit so don't put them here.
128+
protected void FindMaterialOptionProperties(MaterialProperty[] props)
127129
{
128130
smoothnessMapChannel = FindProperty(kSmoothnessTextureChannel, props);
129-
UVBase = FindProperty(kUVBase, props);
130-
TexWorldScale = FindProperty(kTexWorldScale, props);
131-
UVMappingMask = FindProperty(kUVMappingMask, props);
132131
normalMapSpace = FindProperty(kNormalMapSpace, props);
133132
heightMapMode = FindProperty(kHeightMapMode, props);
134133
detailMapMode = FindProperty(kDetailMapMode, props);
135-
UVDetail = FindProperty(kUVDetail, props);
136-
UVDetailsMappingMask = FindProperty(kUVDetailsMappingMask, props);
137134
emissiveColorMode = FindProperty(kEmissiveColorMode, props);
138135
}
139136

140-
override protected void FindInputProperties(MaterialProperty[] props)
137+
override protected void FindMaterialProperties(MaterialProperty[] props)
141138
{
139+
FindMaterialOptionProperties(props);
140+
142141
baseColor = FindProperty(kBaseColor, props);
143142
baseColorMap = FindProperty(kBaseColorMap, props);
144143
metallic = FindProperty(kMetallic, props);
@@ -153,6 +152,12 @@ override protected void FindInputProperties(MaterialProperty[] props)
153152
anisotropy = FindProperty(kAnisotropy, props);
154153
anisotropyMap = FindProperty(kAnisotropyMap, props);
155154

155+
UVBase = FindProperty(kUVBase, props);
156+
UVDetail = FindProperty(kUVDetail, props);
157+
TexWorldScale = FindProperty(kTexWorldScale, props);
158+
UVMappingMask = FindProperty(kUVMappingMask, props);
159+
UVDetailsMappingMask = FindProperty(kUVDetailsMappingMask, props);
160+
156161
detailMap = FindProperty(kDetailMap, props);
157162
detailMask = FindProperty(kDetailMask, props);
158163
detailAlbedoScale = FindProperty(kDetailAlbedoScale, props);
@@ -284,38 +289,37 @@ public override void AssignNewShaderToMaterial(Material material, Shader oldShad
284289
base.AssignNewShaderToMaterial(material, oldShader, newShader);
285290
}
286291

287-
protected virtual void SetupKeywordsForInputMaps(Material material)
288-
{
289-
SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap) || material.GetTexture(kDetailMap)); // With details map, we always use a normal map and Unity provide a default (0, 0, 1) normal map for ir
290-
SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap));
291-
SetKeyword(material, "_SPECULAROCCLUSIONMAP", material.GetTexture(kSpecularOcclusionMap));
292-
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));
293-
SetKeyword(material, "_HEIGHTMAP", material.GetTexture(kHeightMap));
294-
SetKeyword(material, "_TANGENTMAP", material.GetTexture(kTangentMap));
295-
SetKeyword(material, "_ANISOTROPYMAP", material.GetTexture(kAnisotropyMap));
296-
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap));
297-
}
298-
299292
protected override bool ShouldEmissionBeEnabled(Material mat)
300293
{
301294
float emissiveIntensity = mat.GetFloat(kEmissiveIntensity);
302295
var realtimeEmission = (mat.globalIlluminationFlags & MaterialGlobalIlluminationFlags.RealtimeEmissive) > 0;
303296
return emissiveIntensity > 0.0f || realtimeEmission;
304297
}
305298

306-
override protected void SetupInputMaterial(Material material)
299+
override protected void SetupMaterialKeywords(Material material)
307300
{
301+
SetupCommonOptionsKeywords(material);
302+
308303
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
309304
// (MaterialProperty value might come from renderer material property block)
310305
SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", ((SmoothnessMapChannel)material.GetFloat(kSmoothnessTextureChannel)) == SmoothnessMapChannel.AlbedoAlpha);
311306
SetKeyword(material, "_MAPPING_TRIPLANAR", ((UVBaseMapping)material.GetFloat(kUVBase)) == UVBaseMapping.Triplanar);
312307
SetKeyword(material, "_NORMALMAP_TANGENT_SPACE", ((NormalMapSpace)material.GetFloat(kNormalMapSpace)) == NormalMapSpace.TangentSpace);
313308
SetKeyword(material, "_HEIGHTMAP_AS_DISPLACEMENT", ((HeightmapMode)material.GetFloat(kHeightMapMode)) == HeightmapMode.Displacement);
314309
SetKeyword(material, "_DETAIL_MAP_WITH_NORMAL", ((DetailMapMode)material.GetFloat(kDetailMapMode)) == DetailMapMode.DetailWithNormal);
315-
SetKeyword(material, "_REQUIRE_UV3", ((UVDetailMapping)material.GetFloat(kUVDetail)) == UVDetailMapping.UV3 && (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0);
316310
SetKeyword(material, "_EMISSIVE_COLOR", ((EmissiveColorMode)material.GetFloat(kEmissiveColorMode)) == EmissiveColorMode.UseEmissiveColor);
317-
318-
SetupKeywordsForInputMaps(material);
311+
312+
SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap) || material.GetTexture(kDetailMap)); // With details map, we always use a normal map and Unity provide a default (0, 0, 1) normal map for ir
313+
SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap));
314+
SetKeyword(material, "_SPECULAROCCLUSIONMAP", material.GetTexture(kSpecularOcclusionMap));
315+
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));
316+
SetKeyword(material, "_HEIGHTMAP", material.GetTexture(kHeightMap));
317+
SetKeyword(material, "_TANGENTMAP", material.GetTexture(kTangentMap));
318+
SetKeyword(material, "_ANISOTROPYMAP", material.GetTexture(kAnisotropyMap));
319+
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap));
320+
321+
SetKeyword(material, "_REQUIRE_UV3", ((UVDetailMapping)material.GetFloat(kUVDetail)) == UVDetailMapping.UV3 && (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0);
322+
319323
}
320324
}
321325
} // namespace UnityEditor

Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitSharePass.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ PackedVaryings VertDefault(Attributes input)
142142
output.texCoord2 = input.uv2;
143143
#endif
144144

145+
#ifdef _REQUIRE_UV3
146+
output.texCoord3 = input.uv3;
147+
#endif
148+
145149
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
146150

147151
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);

Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Editor/BaseUnlitUI.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,19 @@ protected static class Styles
6565

6666
protected MaterialEditor m_MaterialEditor;
6767

68-
public void FindOptionProperties(MaterialProperty[] props)
68+
public void FindCommonOptionProperties(MaterialProperty[] props)
6969
{
7070
surfaceType = FindProperty(kSurfaceType, props);
7171
blendMode = FindProperty(kBlendMode, props);
7272
alphaCutoff = FindProperty(kAlphaCutoff, props);
7373
alphaCutoffEnable = FindProperty(kAlphaCutoffEnabled, props);
7474
doubleSidedMode = FindProperty(kDoubleSidedMode, props);
75-
FindInputOptionProperties(props);
7675
}
7776

7877
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
7978
{
80-
FindOptionProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
81-
FindInputProperties(props);
79+
FindCommonOptionProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
80+
FindMaterialProperties(props);
8281

8382
m_MaterialEditor = materialEditor;
8483
Material material = materialEditor.target as Material;
@@ -124,7 +123,7 @@ public void ShaderPropertiesGUI(Material material)
124123
if (EditorGUI.EndChangeCheck())
125124
{
126125
foreach (var obj in m_MaterialEditor.targets)
127-
SetupMaterial((Material)obj);
126+
SetupMaterialKeywords((Material)obj);
128127
}
129128
}
130129

@@ -166,9 +165,9 @@ void BlendModePopup()
166165
EditorGUI.showMixedValue = false;
167166
}
168167

169-
protected void SetupMaterial(Material material)
170-
{
171-
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
168+
protected void SetupCommonOptionsKeywords(Material material)
169+
{
170+
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
172171
// (MaterialProperty value might come from renderer material property block)
173172

174173
bool alphaTestEnable = material.GetFloat(kAlphaCutoffEnabled) == 1.0;
@@ -229,7 +228,6 @@ protected void SetupMaterial(Material material)
229228
}
230229

231230
SetKeyword(material, "_ALPHATEST_ON", alphaTestEnable);
232-
SetupInputMaterial(material);
233231

234232
// Setup lightmap emissive flags
235233
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
@@ -242,7 +240,7 @@ protected void SetupMaterial(Material material)
242240

243241
material.globalIlluminationFlags = flags;
244242
}
245-
}
243+
}
246244

247245
bool HasValidEmissiveKeyword(Material material)
248246
{
@@ -268,12 +266,11 @@ protected void SetKeyword(Material m, string keyword, bool state)
268266
m.DisableKeyword(keyword);
269267
}
270268

271-
protected abstract void FindInputProperties(MaterialProperty[] props);
269+
protected abstract void FindMaterialProperties(MaterialProperty[] props);
272270
protected abstract void ShaderInputGUI();
273271
protected abstract void ShaderInputOptionsGUI();
274-
protected abstract void FindInputOptionProperties(MaterialProperty[] props);
275-
protected abstract void SetupInputMaterial(Material material);
272+
protected abstract void SetupMaterialKeywords(Material material);
276273
protected abstract bool ShouldEmissionBeEnabled(Material material);
277274
}
278275

279-
}
276+
}

Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Editor/UnlitUI.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class UnlitGUI : BaseUnlitGUI
1515
protected const string kEmissiveColorMap = "_EmissiveColorMap";
1616
protected const string kEmissiveIntensity = "_EmissiveIntensity";
1717

18-
override protected void FindInputProperties(MaterialProperty[] props)
18+
override protected void FindMaterialProperties(MaterialProperty[] props)
1919
{
2020
color = FindProperty("_Color", props);
2121
colorMap = FindProperty("_ColorMap", props);
@@ -43,12 +43,9 @@ override protected void ShaderInputOptionsGUI()
4343
{
4444
}
4545

46-
protected override void FindInputOptionProperties(MaterialProperty[] props)
47-
{
48-
}
49-
50-
protected override void SetupInputMaterial(Material material)
46+
protected override void SetupMaterialKeywords(Material material)
5147
{
48+
SetupCommonOptionsKeywords(material);
5249
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));
5350
}
5451

0 commit comments

Comments
 (0)