Skip to content

Commit c8f7d58

Browse files
Fixed LayeredLit detail maps and improved the LayeredLitTest scene.
1 parent cdcc52c commit c8f7d58

File tree

107 files changed

+23452
-2273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+23452
-2273
lines changed

Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public ShadowSettings shadowSettings
128128
ShadowRenderPass m_ShadowPass;
129129

130130

131-
public const int k_MaxDirectionalLightsOnSCreen = 2;
131+
public const int k_MaxDirectionalLightsOnSCreen = 3;
132132
public const int k_MaxPunctualLightsOnSCreen = 512;
133133
public const int k_MaxAreaLightsOnSCreen = 128;
134134
public const int k_MaxEnvLightsOnSCreen = 64;

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

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using UnityEngine;
33
using UnityEngine.Rendering;
44

5+
using System.Linq;
6+
57
namespace UnityEditor
68
{
79
internal class LayeredLitGUI : LitGUI
@@ -66,22 +68,14 @@ internal struct SerializeableGUIDs
6668
MaterialProperty layerCount = null;
6769
const string kLayerCount = "_LayerCount";
6870
MaterialProperty[] layerTexWorldScale = new MaterialProperty[kMaxLayerCount];
69-
const string kLayerTexWorldScale = "_TexWorldScale";
7071
MaterialProperty[] layerUVBase = new MaterialProperty[kMaxLayerCount];
71-
const string kLayerUVBase = "_UVBase";
7272
MaterialProperty[] layerUVMappingMask = new MaterialProperty[kMaxLayerCount];
73-
const string kLayerUVMappingMask = "_UVMappingMask";
7473
MaterialProperty[] layerUVDetail = new MaterialProperty[kMaxLayerCount];
75-
const string kLayerUVDetail = "_UVDetail";
7674
MaterialProperty[] layerUVDetailsMappingMask = new MaterialProperty[kMaxLayerCount];
77-
const string kLayerUVDetailsMappingMask = "_UVDetailsMappingMask";
7875

7976
MaterialProperty layerEmissiveColor = null;
80-
const string kLayerEmissiveColor = "_EmissiveColor";
8177
MaterialProperty layerEmissiveColorMap = null;
82-
const string kLayerEmissiveColorMap = "_EmissiveColorMap";
8378
MaterialProperty layerEmissiveIntensity = null;
84-
const string kLayerEmissiveIntensity = "_EmissiveIntensity";
8579

8680
private void FindLayerProperties(MaterialProperty[] props)
8781
{
@@ -90,16 +84,16 @@ private void FindLayerProperties(MaterialProperty[] props)
9084
layerCount = FindProperty(kLayerCount, props);
9185
for (int i = 0; i < numLayer; ++i)
9286
{
93-
layerTexWorldScale[i] = FindProperty(string.Format("{0}{1}", kLayerTexWorldScale, i), props);
94-
layerUVBase[i] = FindProperty(string.Format("{0}{1}", kLayerUVBase, i), props);
95-
layerUVMappingMask[i] = FindProperty(string.Format("{0}{1}", kLayerUVMappingMask, i), props);
96-
layerUVDetail[i] = FindProperty(string.Format("{0}{1}", kLayerUVDetail, i), props);
97-
layerUVDetailsMappingMask[i] = FindProperty(string.Format("{0}{1}", kLayerUVDetailsMappingMask, i), props);
87+
layerTexWorldScale[i] = FindProperty(string.Format("{0}{1}", kTexWorldScale, i), props);
88+
layerUVBase[i] = FindProperty(string.Format("{0}{1}", kUVBase, i), props);
89+
layerUVMappingMask[i] = FindProperty(string.Format("{0}{1}", kUVMappingMask, i), props);
90+
layerUVDetail[i] = FindProperty(string.Format("{0}{1}", kUVDetail, i), props);
91+
layerUVDetailsMappingMask[i] = FindProperty(string.Format("{0}{1}", kUVDetailsMappingMask, i), props);
9892
}
9993

100-
layerEmissiveColor = FindProperty(kLayerEmissiveColor, props);
101-
layerEmissiveColorMap = FindProperty(kLayerEmissiveColorMap, props);
102-
layerEmissiveIntensity = FindProperty(kLayerEmissiveIntensity, props);
94+
layerEmissiveColor = FindProperty(kEmissiveColor, props);
95+
layerEmissiveColorMap = FindProperty(kEmissiveColorMap, props);
96+
layerEmissiveIntensity = FindProperty(kEmissiveIntensity, props);
10397
}
10498

10599
int numLayer
@@ -118,6 +112,8 @@ void SynchronizeAllLayersProperties()
118112

119113
void SynchronizeLayerProperties(int layerIndex)
120114
{
115+
string[] exclusionList = { kTexWorldScale, kUVBase, kUVMappingMask, kUVDetail, kUVDetailsMappingMask };
116+
121117
Material material = m_MaterialEditor.target as Material;
122118
Material layerMaterial = m_MaterialLayers[layerIndex];
123119

@@ -129,34 +125,38 @@ void SynchronizeLayerProperties(int layerIndex)
129125
{
130126
string propertyName = ShaderUtil.GetPropertyName(layerShader, i);
131127
string layerPropertyName = propertyName + layerIndex;
132-
if (material.HasProperty(layerPropertyName))
133-
{
134-
ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(layerShader, i);
135-
switch (type)
136-
{
137-
case ShaderUtil.ShaderPropertyType.Color:
138-
{
139-
material.SetColor(layerPropertyName, layerMaterial.GetColor(propertyName));
140-
break;
141-
}
142-
case ShaderUtil.ShaderPropertyType.Float:
143-
case ShaderUtil.ShaderPropertyType.Range:
144-
{
145-
material.SetFloat(layerPropertyName, layerMaterial.GetFloat(propertyName));
146-
break;
147-
}
148-
case ShaderUtil.ShaderPropertyType.Vector:
149-
{
150-
material.SetVector(layerPropertyName, layerMaterial.GetVector(propertyName));
151-
break;
152-
}
153-
case ShaderUtil.ShaderPropertyType.TexEnv:
154-
{
155-
material.SetTexture(layerPropertyName, layerMaterial.GetTexture(propertyName));
156-
break;
157-
}
158-
}
159-
}
128+
129+
if(!exclusionList.Contains(propertyName))
130+
{
131+
if (material.HasProperty(layerPropertyName))
132+
{
133+
ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(layerShader, i);
134+
switch (type)
135+
{
136+
case ShaderUtil.ShaderPropertyType.Color:
137+
{
138+
material.SetColor(layerPropertyName, layerMaterial.GetColor(propertyName));
139+
break;
140+
}
141+
case ShaderUtil.ShaderPropertyType.Float:
142+
case ShaderUtil.ShaderPropertyType.Range:
143+
{
144+
material.SetFloat(layerPropertyName, layerMaterial.GetFloat(propertyName));
145+
break;
146+
}
147+
case ShaderUtil.ShaderPropertyType.Vector:
148+
{
149+
material.SetVector(layerPropertyName, layerMaterial.GetVector(propertyName));
150+
break;
151+
}
152+
case ShaderUtil.ShaderPropertyType.TexEnv:
153+
{
154+
material.SetTexture(layerPropertyName, layerMaterial.GetTexture(propertyName));
155+
break;
156+
}
157+
}
158+
}
159+
}
160160
}
161161
}
162162
}
@@ -458,10 +458,11 @@ protected override void SetupKeywordsForInputMaps(Material material)
458458
SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap + i));
459459
SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap + i));
460460
SetKeyword(material, "_SPECULAROCCLUSIONMAP", material.GetTexture(kSpecularOcclusionMap + i));
461-
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap + i));
462461
SetKeyword(material, "_HEIGHTMAP", material.GetTexture(kHeightMap + i));
462+
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap + i));
463463
}
464464

465+
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));
465466
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR", material.GetFloat(kLayerMaskVertexColor) != 0.0f);
466467
}
467468

@@ -489,9 +490,9 @@ void SetupMaterialForLayers(Material material)
489490
{
490491
// We setup the masking map based on the enum for each layer.
491492
// using mapping mask allow to reduce the number of generated combination for a very small increase in ALU
492-
string layerUVBaseParam = string.Format("{0}{1}", kLayerUVBase, i);
493+
string layerUVBaseParam = string.Format("{0}{1}", kUVBase, i);
493494
LayerUVBaseMapping layerUVBaseMapping = (LayerUVBaseMapping)material.GetFloat(layerUVBaseParam);
494-
string layerUVDetailParam = string.Format("{0}{1}", kLayerUVDetail, i);
495+
string layerUVDetailParam = string.Format("{0}{1}", kUVDetail, i);
495496
LayerUVDetailMapping layerUVDetailMapping = (LayerUVDetailMapping)material.GetFloat(layerUVDetailParam);
496497
string currentLayerMappingTriplanar = string.Format("{0}{1}", kLayerMappingTriplanar, i);
497498

@@ -502,10 +503,7 @@ void SetupMaterialForLayers(Material material)
502503
W = (layerUVBaseMapping == LayerUVBaseMapping.Planar) ? 1.0f : 0.0f;
503504
layerUVMappingMask[i].colorValue = new Color(X, Y, Z, W);
504505

505-
if (layerUVBaseMapping == LayerUVBaseMapping.Triplanar)
506-
{
507-
SetKeyword(material, currentLayerMappingTriplanar, true);
508-
}
506+
SetKeyword(material, currentLayerMappingTriplanar, layerUVBaseMapping == LayerUVBaseMapping.Triplanar);
509507

510508
// If base is planar mode, detail is planar too
511509
if (W > 0.0f)

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ Shader "HDRenderLoop/LayeredLit"
130130

131131
[HideInInspector] _LayerCount("_LayerCount", Float) = 2.0
132132

133+
// WARNING
134+
// All the following properties that concern the UV mapping are the same as in the Lit shader.
135+
// This means that they will get overridden when synchronizing the various layers.
136+
// To avoid this, make sure that all properties here are in the exclusion list in LayeredLitUI.SynchronizeLayerProperties
133137
_TexWorldScale0("Scale to apply on world coordinate", Float) = 1.0
134138
_TexWorldScale1("Scale to apply on world coordinate", Float) = 1.0
135139
_TexWorldScale2("Scale to apply on world coordinate", Float) = 1.0
@@ -150,10 +154,10 @@ Shader "HDRenderLoop/LayeredLit"
150154
[Enum(UV0, 0, UV1, 1, UV3, 2)] _UVDetail2("UV Set for detail2", Float) = 0
151155
[Enum(UV0, 0, UV1, 1, UV3, 2)] _UVDetail3("UV Set for detail3", Float) = 0
152156

153-
[HideInInspector] _UVDetailsMappingMask0("_UVDetailsMappingMask0", Float) = 0
154-
[HideInInspector] _UVDetailsMappingMask1("_UVDetailsMappingMask1", Float) = 0
155-
[HideInInspector] _UVDetailsMappingMask2("_UVDetailsMappingMask2", Float) = 0
156-
[HideInInspector] _UVDetailsMappingMask3("_UVDetailsMappingMask3", Float) = 0
157+
[HideInInspector] _UVDetailsMappingMask0("_UVDetailsMappingMask0", Color) = (1, 0, 0, 0)
158+
[HideInInspector] _UVDetailsMappingMask1("_UVDetailsMappingMask1", Color) = (1, 0, 0, 0)
159+
[HideInInspector] _UVDetailsMappingMask2("_UVDetailsMappingMask2", Color) = (1, 0, 0, 0)
160+
[HideInInspector] _UVDetailsMappingMask3("_UVDetailsMappingMask3", Color) = (1, 0, 0, 0)
157161

158162
// Unused but to be able to share litUI.Sahder and layeredUI.Shader
159163
[HideInInspector] _UVBase("UV Set for base", Float) = 0

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ void ADD_IDX(ComputeLayerTexCoord)(FragInput input, bool isTriplanar, inout Laye
2222
// triplanar
2323
ADD_IDX(layerTexCoord.base).isTriplanar = isTriplanar;
2424

25-
ADD_IDX(layerTexCoord.base).uvYZ = position.yz;
26-
ADD_IDX(layerTexCoord.base).uvZX = position.zx;
27-
ADD_IDX(layerTexCoord.base).uvXY = position.xy;
25+
ADD_IDX(layerTexCoord.base).uvYZ = position.zy;
26+
ADD_IDX(layerTexCoord.base).uvZX = position.xz;
27+
ADD_IDX(layerTexCoord.base).uvXY = float2(-position.x, position.y);
2828

2929
ADD_IDX(layerTexCoord.details).isTriplanar = isTriplanar;
3030

31-
ADD_IDX(layerTexCoord.details).uvYZ = TRANSFORM_TEX(position.yz, ADD_IDX(_DetailMap));
32-
ADD_IDX(layerTexCoord.details).uvZX = TRANSFORM_TEX(position.zx, ADD_IDX(_DetailMap));
33-
ADD_IDX(layerTexCoord.details).uvXY = TRANSFORM_TEX(position.xy, ADD_IDX(_DetailMap));
31+
ADD_IDX(layerTexCoord.details).uvYZ = TRANSFORM_TEX(position.zy, ADD_IDX(_DetailMap));
32+
ADD_IDX(layerTexCoord.details).uvZX = TRANSFORM_TEX(position.xz, ADD_IDX(_DetailMap));
33+
ADD_IDX(layerTexCoord.details).uvXY = TRANSFORM_TEX(float2(-position.x, position.y), ADD_IDX(_DetailMap));
3434
}
3535

3636
void ADD_IDX(ApplyDisplacement)(inout FragInput input, inout LayerTexCoord layerTexCoord)

Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Ground.meta renamed to Assets/TestScenes/HDTest/LayeredLitTest.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)