Skip to content

Commit 9739c5e

Browse files
Merge pull request #33 from Unity-Technologies/LayeredLit
Layeredlit
2 parents dfe001c + 5a4d8fc commit 9739c5e

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private class StylesLayer
4141
public readonly GUIContent layerMapMaskText = new GUIContent("Layer Mask", "Layer mask (multiplied by vertex color if enabled)");
4242
public readonly GUIContent layerMapVertexColorText = new GUIContent("Use Vertex Color", "Layer mask (multiplied by layer mask if enabled)");
4343
public readonly GUIContent layerCountText = new GUIContent("Layer Count", "Number of layers.");
44-
public readonly GUIContent layerTexWorldScaleText = new GUIContent("Tex world scale", "Scale to apply to world position for Planar/Trilinear");
44+
public readonly GUIContent layerTexWorldScaleText = new GUIContent("Tiling", "Tiling factor applied to Planar/Trilinear mapping");
4545
public readonly GUIContent UVBaseText = new GUIContent("Base UV Mapping", "Base UV Mapping mode of the layer.");
4646
public readonly GUIContent UVDetailText = new GUIContent("Detail UV Mapping", "Detail UV Mapping mode of the layer.");
4747
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ Shader "HDRenderLoop/LayeredLit"
134134
// All the following properties that concern the UV mapping are the same as in the Lit shader.
135135
// This means that they will get overridden when synchronizing the various layers.
136136
// To avoid this, make sure that all properties here are in the exclusion list in LayeredLitUI.SynchronizeLayerProperties
137-
_TexWorldScale0("Scale to apply on world coordinate", Float) = 1.0
138-
_TexWorldScale1("Scale to apply on world coordinate", Float) = 1.0
139-
_TexWorldScale2("Scale to apply on world coordinate", Float) = 1.0
140-
_TexWorldScale3("Scale to apply on world coordinate", Float) = 1.0
137+
_TexWorldScale0("Tiling", Float) = 1.0
138+
_TexWorldScale1("Tiling", Float) = 1.0
139+
_TexWorldScale2("Tiling", Float) = 1.0
140+
_TexWorldScale3("Tiling", Float) = 1.0
141141

142142
[Enum(UV0, 0, UV1, 1, UV3, 2, Planar, 3, Triplanar, 4)] _UVBase0("UV Set for base0", Float) = 0
143143
[Enum(UV0, 0, UV1, 1, UV3, 2, Planar, 3, Triplanar, 4)] _UVBase1("UV Set for base1", Float) = 0
@@ -162,7 +162,7 @@ Shader "HDRenderLoop/LayeredLit"
162162
// Unused but to be able to share litUI.Sahder and layeredUI.Shader
163163
[HideInInspector] _UVBase("UV Set for base", Float) = 0
164164
[HideInInspector] _UVDetail("UV Set for base", Float) = 0
165-
[HideInInspector] _TexWorldScale("Scale to apply on world coordinate", Float) = 1.0
165+
[HideInInspector] _TexWorldScale("Tiling", Float) = 1.0
166166
[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0)
167167
[HideInInspector] _UVDetailsMappingMask("_UVDetailsMappingMask", Color) = (1, 0, 0, 0)
168168
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected static class Styles
2525

2626
public static GUIContent smoothnessMapChannelText = new GUIContent("Smoothness Source", "Smoothness texture and channel");
2727
public static GUIContent UVBaseMappingText = new GUIContent("UV set for Base", "");
28-
public static GUIContent texWorldScaleText = new GUIContent("Scale to apply on world coordinate in case of Planar/Triplanar", "");
28+
public static GUIContent texWorldScaleText = new GUIContent("Tiling", "Tiling factor applied to Planar/Trilinear mapping");
2929
public static GUIContent UVBaseDetailMappingText = new GUIContent("UV set for Base and Detail", "");
3030
public static GUIContent normalMapSpaceText = new GUIContent("Normal/Tangent Map space", "");
3131
public static GUIContent heightMapModeText = new GUIContent("Height Map Mode", "");

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,33 @@ void ADD_IDX(ComputeLayerTexCoord)(FragInput input, bool isTriplanar, inout Laye
99
ADD_IDX(layerTexCoord.base).uv = ADD_IDX(_UVMappingMask).x * input.texCoord0 +
1010
ADD_IDX(_UVMappingMask).y * input.texCoord1 +
1111
ADD_IDX(_UVMappingMask).z * input.texCoord3 +
12-
ADD_IDX(_UVMappingMask).w * position.xz;
12+
ADD_IDX(_UVMappingMask).w * -position.xz;
1313

1414
float2 uvDetails = ADD_IDX(_UVDetailsMappingMask).x * input.texCoord0 +
1515
ADD_IDX(_UVDetailsMappingMask).y * input.texCoord1 +
1616
ADD_IDX(_UVDetailsMappingMask).z * input.texCoord3 +
1717
// Note that if base is planar, detail map is planar
18-
ADD_IDX(_UVMappingMask).w * position.xz;
18+
ADD_IDX(_UVMappingMask).w * -position.xz;
1919

2020
ADD_IDX(layerTexCoord.details).uv = TRANSFORM_TEX(uvDetails, ADD_IDX(_DetailMap));
2121

2222
// triplanar
2323
ADD_IDX(layerTexCoord.base).isTriplanar = isTriplanar;
2424

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);
25+
float3 direction = sign(input.tangentToWorld[2].xyz);
26+
27+
// In triplanar, if we are facing away from the world axis, a different axis will be flipped for each direction.
28+
// This is particularly problematic for tangent space normal maps which need to be in the right direction.
29+
// So we multiplying the offending coordinate by the sign of the normal.
30+
ADD_IDX(layerTexCoord.base).uvYZ = float2(direction.x * position.z, position.y);
31+
ADD_IDX(layerTexCoord.base).uvZX = -float2(position.x, direction.y * position.z);
32+
ADD_IDX(layerTexCoord.base).uvXY = float2(-position.x, direction.z * position.y);
2833

2934
ADD_IDX(layerTexCoord.details).isTriplanar = isTriplanar;
3035

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));
36+
ADD_IDX(layerTexCoord.details).uvYZ = TRANSFORM_TEX(ADD_IDX(layerTexCoord.base).uvYZ, ADD_IDX(_DetailMap));
37+
ADD_IDX(layerTexCoord.details).uvZX = TRANSFORM_TEX(ADD_IDX(layerTexCoord.base).uvZX, ADD_IDX(_DetailMap));
38+
ADD_IDX(layerTexCoord.details).uvXY = TRANSFORM_TEX(ADD_IDX(layerTexCoord.base).uvXY, ADD_IDX(_DetailMap));
3439
}
3540

3641
void ADD_IDX(ApplyDisplacement)(inout FragInput input, inout LayerTexCoord layerTexCoord)
@@ -156,7 +161,7 @@ float ADD_IDX(GetSurfaceData)(FragInput input, LayerTexCoord layerTexCoord, out
156161
#else
157162
surfaceData.perceptualSmoothness = 1.0;
158163
#endif
159-
surfaceData.perceptualSmoothness *= ADD_IDX(_Smoothness);
164+
surfaceData.perceptualSmoothness *= ADD_IDX(_Smoothness);
160165
#ifdef _DETAIL_MAP
161166
surfaceData.perceptualSmoothness *= LerpWhiteTo(2.0 * saturate(detailSmoothness * ADD_IDX(_DetailSmoothnessScale)), detailMask);
162167
#endif

0 commit comments

Comments
 (0)