浏览代码

Merge pull request #118 from Unity-Technologies/Update-layered-material

HDRenderPipeline: Update layered material
/main
GitHub 8 年前
当前提交
ecd950f5
共有 9 个文件被更改,包括 208 次插入115 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  2. 165
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
  3. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  4. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  5. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
  6. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  7. 83
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
  8. 49
      Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_BlendColor.mat
  9. 1
      Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_BlendColor.mat.meta

2
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


using (new Utilities.ProfilingSample("Velocity Pass", renderContext))
{
// If opaque velocity have been render during GBuffer no need to render it here
if ((ShaderConfig.s_VelocityInGbuffer == 0) || debugParameters.ShouldUseForwardRenderingOnly())
if ((ShaderConfig.s_VelocityInGbuffer == 1) || debugParameters.ShouldUseForwardRenderingOnly())
return ;
int w = camera.pixelWidth;

165
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs


Triplanar,
}
public enum VertexColorMode
{
None,
Multiply,
Add
}
new GUIContent("Layer 0"),
new GUIContent("Layer 1"),
new GUIContent("Layer 2"),
new GUIContent("Layer 3"),
};
public readonly GUIContent[] baseLayerLabels =
{
new GUIContent("Base Layer"),
new GUIContent("Layer 1"),
new GUIContent("Layer 2"),

public readonly GUIContent layersText = new GUIContent("Layers");
public readonly GUIContent emissiveText = new GUIContent("Emissive");
public readonly GUIContent layerMapMaskText = new GUIContent("Layer Mask", "Layer mask (multiplied by vertex color if enabled)");
public readonly GUIContent layerMapVertexColorText = new GUIContent("Use Vertex Color", "If no layer mask is set, vertex color values between 0 and 1.0 are used as final mask.\nIf a layer mask is set, vertex color values are remapped between -1 and 1 and added to the mask (neutral at 0.5 vertex color).");
public readonly GUIContent vertexColorModeText = new GUIContent("Vertex Color Mode", "Mode multiply: vertex color is multiply with the mask. Mode additive: vertex color values are remapped between -1 and 1 and added to the mask (neutral at 0.5 vertex color).");
public readonly GUIContent BaseInfluenceText = new GUIContent("Base influence", "Base influence.");
public readonly GUIContent DensityOpacityInfluenceText = new GUIContent("Density / Opacity", "Density / Opacity");
public readonly GUIContent useBaseLayerModeText = new GUIContent("Use Base Mode", "Switch between regular layers mode and base/layers mode");
public readonly GUIContent heightControlText = new GUIContent("Height control");
public readonly GUIContent useHeightBasedBlendV2Text = new GUIContent("Use Height Based Blend V2", "Layer will be blended with the underlying layer based on the height.");
public readonly GUIContent useHeightBasedBlendV2Text = new GUIContent("Use V2", "Layer will be blended with the underlying layer based on the height.");
public readonly GUIContent inheritBaseNormalText = new GUIContent("Inherit Base Layer Normal", "Inherit the normal from the base layer.");
public readonly GUIContent inheritBaseHeightText = new GUIContent("Inherit Base Layer Height", "Inherit the height from the base layer.");
public readonly GUIContent inheritBaseColorText = new GUIContent("Inherit Base Layer Color", "Inherit the base color from the base layer.");
public readonly GUIContent inheritBaseNormalText = new GUIContent("Normal influence", "Inherit the normal from the base layer.");
public readonly GUIContent inheritBaseHeightText = new GUIContent("Heightmap influence", "Inherit the height from the base layer.");
public readonly GUIContent inheritBaseColorText = new GUIContent("BaseColor influence", "Inherit the base color from the base layer.");
layerLabelColors[0].normal.textColor = Color.white;
layerLabelColors[1].normal.textColor = Color.red;
layerLabelColors[2].normal.textColor = Color.green;
layerLabelColors[3].normal.textColor = Color.blue;

MaterialProperty layerMaskMap = null;
const string kLayerMaskMap = "_LayerMaskMap";
MaterialProperty layerMaskVertexColor = null;
const string kLayerMaskVertexColor = "_LayerMaskVertexColor";
MaterialProperty vertexColorMode = null;
const string kVertexColorMode = "_VertexColorMode";
MaterialProperty layerCount = null;
const string kLayerCount = "_LayerCount";
MaterialProperty[] layerTexWorldScale = new MaterialProperty[kMaxLayerCount];

MaterialProperty[] layerUVDetail = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] layerUVDetailsMappingMask = new MaterialProperty[kMaxLayerCount];
const string kkUseBaseLayerMode = "_UseBaseLayerMode";
MaterialProperty useBaseLayerMode = null;
const string kUseHeightBasedBlend = "_UseHeightBasedBlend";
MaterialProperty useHeightBasedBlend = null;
const string kUseHeightBasedBlendV2 = "_UseHeightBasedBlendV2";

FindMaterialOptionProperties(props);
layerMaskMap = FindProperty(kLayerMaskMap, props);
layerMaskVertexColor = FindProperty(kLayerMaskVertexColor, props);
vertexColorMode = FindProperty(kVertexColorMode, props);
useBaseLayerMode = FindProperty(kkUseBaseLayerMode, props);
useHeightBasedBlend = FindProperty(kUseHeightBasedBlend, props);
useHeightBasedBlendV2 = FindProperty(kUseHeightBasedBlendV2, props);

Material material = m_MaterialEditor.target as Material;
EditorGUILayout.LabelField(styles.layerLabels[layerIndex], styles.layerLabelColors[layerIndex]);
bool baseLayerModeEnable = useBaseLayerMode.floatValue > 0.0f;
EditorGUILayout.LabelField(baseLayerModeEnable ? styles.baseLayerLabels[layerIndex] : styles.layerLabels[layerIndex], styles.layerLabelColors[layerIndex]);
EditorGUI.indentLevel++;

if(layerIndex > 0)
{
if (!useHeightBasedBlend.hasMixedValue && useHeightBasedBlend.floatValue != 0.0f)
bool heightBasedBlendEnable = useHeightBasedBlend.floatValue != 0.0f;
bool heightBasedBlendV2Enable = useHeightBasedBlendV2.floatValue != 1.0f;
int paramIndex = layerIndex - 1;
if (baseLayerModeEnable)
int heightParamIndex = layerIndex - 1;
EditorGUILayout.LabelField(styles.BaseInfluenceText, EditorStyles.label);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(inheritBaseColor[paramIndex], styles.inheritBaseColorText);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(inheritBaseColorThreshold[paramIndex], styles.inheritBaseColorThresholdText);
EditorGUI.indentLevel--;
m_MaterialEditor.ShaderProperty(inheritBaseNormal[paramIndex], styles.inheritBaseNormalText);
if (heightBasedBlendEnable)
{
m_MaterialEditor.ShaderProperty(inheritBaseHeight[paramIndex], styles.inheritBaseHeightText);
}
EditorGUI.indentLevel--;
EditorGUILayout.LabelField(styles.DensityOpacityInfluenceText, EditorStyles.label);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(opacityAsDensity[paramIndex], styles.opacityAsDensityText);
m_MaterialEditor.ShaderProperty(minimumOpacity[paramIndex], styles.minimumOpacityText);
EditorGUI.indentLevel--;
}
if (!useHeightBasedBlend.hasMixedValue && heightBasedBlendEnable)
{
EditorGUILayout.LabelField(styles.heightControlText, EditorStyles.label);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(heightFactor[paramIndex], styles.heightFactorText);
if(useHeightBasedBlendV2.floatValue != 1.0f)
if (!heightBasedBlendV2Enable)
m_MaterialEditor.ShaderProperty(heightOffset[heightParamIndex], styles.heightOffsetText);
m_MaterialEditor.ShaderProperty(heightFactor[heightParamIndex], styles.heightFactorText);
m_MaterialEditor.ShaderProperty(blendSize[heightParamIndex], styles.blendSizeText);
m_MaterialEditor.ShaderProperty(inheritBaseColor[heightParamIndex], styles.inheritBaseColorText);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(inheritBaseColorThreshold[heightParamIndex], styles.inheritBaseColorThresholdText);
EditorGUI.indentLevel--;
m_MaterialEditor.ShaderProperty(inheritBaseNormal[heightParamIndex], styles.inheritBaseNormalText);
m_MaterialEditor.ShaderProperty(heightOffset[paramIndex], styles.heightOffsetText);
m_MaterialEditor.ShaderProperty(blendSize[paramIndex], styles.blendSizeText);
m_MaterialEditor.ShaderProperty(heightFactor[heightParamIndex], styles.heightFactorText);
m_MaterialEditor.ShaderProperty(heightCenterOffset[heightParamIndex], styles.heightCenterOffsetText);
m_MaterialEditor.ShaderProperty(blendUsingHeight[heightParamIndex], styles.blendUsingHeight);
m_MaterialEditor.ShaderProperty(inheritBaseColor[heightParamIndex], styles.inheritBaseColorText);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(inheritBaseColorThreshold[heightParamIndex], styles.inheritBaseColorThresholdText);
EditorGUI.indentLevel--;
m_MaterialEditor.ShaderProperty(inheritBaseNormal[heightParamIndex], styles.inheritBaseNormalText);
m_MaterialEditor.ShaderProperty(inheritBaseHeight[heightParamIndex], styles.inheritBaseHeightText);
m_MaterialEditor.ShaderProperty(opacityAsDensity[heightParamIndex], styles.opacityAsDensityText);
m_MaterialEditor.ShaderProperty(minimumOpacity[heightParamIndex], styles.minimumOpacityText);
m_MaterialEditor.ShaderProperty(heightCenterOffset[paramIndex], styles.heightCenterOffsetText);
m_MaterialEditor.ShaderProperty(blendUsingHeight[paramIndex], styles.blendUsingHeight);
EditorGUI.indentLevel--;
}
}

m_MaterialEditor.TexturePropertySingleLine(styles.layerMapMaskText, layerMaskMap);
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = useBaseLayerMode.hasMixedValue;
bool enabledBaseMode = EditorGUILayout.Toggle(styles.useBaseLayerModeText, useBaseLayerMode.floatValue > 0.0f);
if (EditorGUI.EndChangeCheck())
{
useBaseLayerMode.floatValue = enabledBaseMode ? 1.0f : 0.0f;
}
m_MaterialEditor.ShaderProperty(vertexColorMode, styles.vertexColorModeText);
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = useHeightBasedBlend.hasMixedValue;
bool enabled = EditorGUILayout.Toggle(styles.useHeightBasedBlendText, useHeightBasedBlend.floatValue > 0.0f);
if (EditorGUI.EndChangeCheck())

if (enabled)
{
EditorGUI.BeginChangeCheck();
bool enabledV2 = EditorGUILayout.Toggle(styles.useHeightBasedBlendV2Text, useHeightBasedBlendV2.floatValue > 0.0f);
EditorGUI.indentLevel++;
bool enabledV2 = EditorGUILayout.Toggle(styles.useHeightBasedBlendV2Text, useHeightBasedBlendV2.floatValue > 0.0f);
if (EditorGUI.EndChangeCheck())
{
useHeightBasedBlendV2.floatValue = enabledV2 ? 1.0f : 0.0f;

}
else
{
m_MaterialEditor.ShaderProperty(layerMaskVertexColor, styles.layerMapVertexColorText);
EditorGUI.indentLevel--;
EditorGUILayout.Space();

}
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));
bool useHeightBasedBlend = material.GetFloat(kUseHeightBasedBlend) != 0.0f;
if(useHeightBasedBlend)
SetKeyword(material, "_BASE_LAYER_MODE", material.GetFloat(kkUseBaseLayerMode) != 0.0f);
VertexColorMode VCMode = (VertexColorMode)vertexColorMode.floatValue;
if (VCMode == VertexColorMode.Multiply)
bool useHeightBasedBlendV2 = material.GetFloat(kUseHeightBasedBlendV2) != 0.0f;
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", true);
}
else if (VCMode == VertexColorMode.Add)
{
SetKeyword(material, "_HEIGHT_BASED_BLEND", true);
SetKeyword(material, "_HEIGHT_BASED_BLEND_V2", useHeightBasedBlendV2);
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", true);
if (material.GetTexture(kLayerMaskMap) != null)
{
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", material.GetFloat(kLayerMaskVertexColor) != 0.0f);
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
}
else
{
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", material.GetFloat(kLayerMaskVertexColor) != 0.0f);
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
}
SetKeyword(material, "_HEIGHT_BASED_BLEND", false);
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_MUL", false);
SetKeyword(material, "_LAYER_MASK_VERTEX_COLOR_ADD", false);
bool useHeightBasedBlend = material.GetFloat(kUseHeightBasedBlend) != 0.0f;
bool useHeightBasedBlendV2 = material.GetFloat(kUseHeightBasedBlendV2) != 0.0f;
SetKeyword(material, "_HEIGHT_BASED_BLEND", useHeightBasedBlend);
SetKeyword(material, "_HEIGHT_BASED_BLEND_V2", useHeightBasedBlend && useHeightBasedBlendV2);
// We have to check for each layer if the UV2 or UV3 is needed.
bool needUV3 = false;

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


// Layer blending options
_LayerMaskMap("LayerMaskMap", 2D) = "white" {}
[ToggleOff] _LayerMaskVertexColor("Use Vertex Color Mask", Float) = 0.0
// Layer blending options V2
[ToggleOff] _UseHeightBasedBlendV2("Use Height Blend V2", Float) = 0.0
[ToggleOff] _UseBaseLayerMode("UseBaseLayerMode", Float) = 0.0
_HeightOffset1("_HeightOffset1", Range(-0.3, 0.3)) = 0.0
_HeightOffset2("_HeightOffset2", Range(-0.3, 0.3)) = 0.0

_VertexColorHeightFactor("_VertexColorHeightFactor", Float) = 0.3
// Layer blending options V2
[ToggleOff] _UseHeightBasedBlendV2("Use Height Blend V2", Float) = 0.0
_HeightCenterOffset1("_HeightCenterOffset1", Float) = 0.0
_HeightCenterOffset2("_HeightCenterOffset2", Float) = 0.0
_HeightCenterOffset3("_HeightCenterOffset3", Float) = 0.0

[HideInInspector] _LayerCount("_LayerCount", Float) = 2.0
[Enum(None, 0, Multiply, 1, Add, 2)] _VertexColorMode("Vertex color mode", Float) = 0
// WARNING
// All the following properties that concern the UV mapping are the same as in the Lit shader.
// This means that they will get overridden when synchronizing the various layers.

#pragma shader_feature _HEIGHTMAP
#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _ _LAYER_MASK_VERTEX_COLOR_MUL _LAYER_MASK_VERTEX_COLOR_ADD
#pragma shader_feature _BASE_LAYER_MODE
#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _HEIGHT_BASED_BLEND_V2
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader


// Layer blending options
_LayerMaskMap("LayerMaskMap", 2D) = "white" {}
[ToggleOff] _LayerMaskVertexColor("Use Vertex Color Mask", Float) = 0.0
// Layer blending options V2
[ToggleOff] _UseHeightBasedBlendV2("Use Height Blend V2", Float) = 0.0
[ToggleOff] _UseBaseLayerMode("UseBaseLayerMode", Float) = 0.0
_HeightOffset1("_HeightOffset1", Range(-0.3, 0.3)) = 0.0
_HeightOffset2("_HeightOffset2", Range(-0.3, 0.3)) = 0.0

_VertexColorHeightFactor("_VertexColorHeightFactor", Float) = 0.3
// Layer blending options V2
[ToggleOff] _UseHeightBasedBlendV2("Use Height Blend V2", Float) = 0.0
_HeightCenterOffset1("_HeightCenterOffset1", Float) = 0.0
_HeightCenterOffset2("_HeightCenterOffset2", Float) = 0.0
_HeightCenterOffset3("_HeightCenterOffset3", Float) = 0.0

[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
[HideInInspector] _LayerCount("_LayerCount", Float) = 2.0
[Enum(None, 0, Multiply, 1, Add, 2)] _VertexColorMode("Vertex color mode", Float) = 0
// WARNING
// All the following properties that concern the UV mapping are the same as in the Lit shader.

#pragma shader_feature _HEIGHTMAP
#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _ _LAYER_MASK_VERTEX_COLOR_MUL _LAYER_MASK_VERTEX_COLOR_ADD
#pragma shader_feature _BASE_LAYER_MODE
#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _HEIGHT_BASED_BLEND_V2
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS

1
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs


public static string surfaceTypeText = "Surface Type";
public static string blendModeText = "Blend Mode";
public static string detailText = "Inputs Detail";
public static string textureControlText = "Input textures control";
public static string lightingText = "Inputs Lighting";
public static GUIContent alphaCutoffEnableText = new GUIContent("Alpha Cutoff Enable", "Threshold for alpha cutoff");

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


m_MaterialEditor.TexturePropertySingleLine(Styles.anisotropyMapText, anisotropyMap);
EditorGUILayout.Space();
GUILayout.Label(Styles.textureControlText, EditorStyles.label);
m_MaterialEditor.TextureScaleOffsetProperty(baseColorMap);
EditorGUILayout.Space();

83
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl


float3 ComputeInheritedNormalTS(FragInputs input, float3 normalTS0, float3 normalTS1, float3 normalTS2, float3 normalTS3, LayerTexCoord layerTexCoord, float weights[_MAX_LAYER])
{
float3 normalTS;
//#if !defined(_HEIGHT_BASED_BLEND_V2)
// float _InheritBaseLayer0 = 1.0; // Default value for lerp when all weights but base layer are zero.
//
// // Compute the combined inheritance factor of layers 1,2 and 3
// float inheritFactor = PROP_BLEND_SCALAR(_InheritBaseLayer, weights);
// float3 vertexNormalTS = float3(0.0, 0.0, 1.0);
// // The idea here is to lerp toward vertex normal. This way when we don't want to inherit, we will combine layer 1/2/3 normal with a vertex normal which is neutral.
// float3 baseLayerNormalTS = normalize(lerp(vertexNormalTS, normalTS0, inheritFactor));
// // Blend layer 1/2/3 normals before combining to the base layer. Again we need to have a neutral value for base layer (vertex normal) in case all weights are zero.
// float3 layersNormalTS = BlendLayeredVector3(vertexNormalTS, normalTS1, normalTS2, normalTS3, weights);
// normalTS = BlendNormalRNM(baseLayerNormalTS, layersNormalTS);
//#else
// Compute how much we want to inherit from base layer normal base on the mask. Base layer always fully inherit from "itself" if it's the visible layer.
float inheritBaseNormal = BlendLayeredScalar(1.0, _InheritBaseNormal1, _InheritBaseNormal2, _InheritBaseNormal3, weights);

float3 layersNormalTS = BlendLayeredVector3(float3(0.0, 0.0, 1.0), normalTS1, normalTS2, normalTS3, weights);
// Add the inherited normal to the blended top layers.
normalTS = BlendNormalRNM(inheritedBaseNormalTS, layersNormalTS);
//#endif
return normalTS;
}

inheritBaseColor = inheritBaseColor * (1.0 - saturate(compoMask / inheritBaseColorThreshold));
// We want to calculate the mean color of the texture. For this we will sample a low mipmap
float textureBias = 16.0; // Force a high number to be sure we get the lowest mip
float textureBias = 15.0; // Force a high number to be sure we get the lowest mip
float3 baseMeanColor0 = SAMPLE_LAYER_TEXTURE2D_BIAS(_BaseColorMap0, sampler_BaseColorMap0, layerTexCoord.base0, textureBias).rgb * _BaseColor0.rgb;
float3 baseMeanColor1 = SAMPLE_LAYER_TEXTURE2D_BIAS(_BaseColorMap1, sampler_BaseColorMap0, layerTexCoord.base1, textureBias).rgb * _BaseColor1.rgb;
float3 baseMeanColor2 = SAMPLE_LAYER_TEXTURE2D_BIAS(_BaseColorMap2, sampler_BaseColorMap0, layerTexCoord.base2, textureBias).rgb * _BaseColor2.rgb;

// Calculate displacement for per vertex displacement mapping
float ComputePerVertexDisplacement(LayerTexCoord layerTexCoord, float4 vertexColor, float lod)
{
float height0 = SampleHeightmapLod0(layerTexCoord, lod);
float height1 = SampleHeightmapLod1(layerTexCoord, lod, _HeightCenterOffset1, _HeightFactor1);
float height2 = SampleHeightmapLod2(layerTexCoord, lod, _HeightCenterOffset2, _HeightFactor2);
float height3 = SampleHeightmapLod3(layerTexCoord, lod, _HeightCenterOffset3, _HeightFactor3);
float4 heights = float4(height0, height1, height2, height3);
// Mask Values : Layer 1, 2, 3 are r, g, b
// Mask Values : Layer 1, 2, 3 are r, g, b. Always use layer0 parametrization for the mask
// Mutually exclusive with _HEIGHT_BASED_BLEND
#if defined(_LAYER_MASK_VERTEX_COLOR_MUL) // Used when no layer mask is set
#if defined(_LAYER_MASK_VERTEX_COLOR_MUL)
#elif defined(_LAYER_MASK_VERTEX_COLOR_ADD) || defined(_HEIGHT_BASED_BLEND_V2) // When layer mask is set, color is additive to enable user to override it.
#elif defined(_LAYER_MASK_VERTEX_COLOR_ADD)
inputMaskValues = saturate(inputMaskValues + vertexColor.rgb * 2.0 - 1.0);
#endif

float height0 = SampleHeightmapLod0(layerTexCoord, lod);
float height1 = SampleHeightmapLod1(layerTexCoord, lod, _HeightCenterOffset1, _HeightFactor1);
float height2 = SampleHeightmapLod2(layerTexCoord, lod, _HeightCenterOffset2, _HeightFactor2);
float height3 = SampleHeightmapLod3(layerTexCoord, lod, _HeightCenterOffset3, _HeightFactor3);
#if defined(_HEIGHT_BASED_BLEND_V2)
#if defined(_BASE_LAYER_MODE)
// Think that inheritbasedheight will be 0 if height0 is fully visible in weights. So there is no double contribution of height0
float inheritBaseHeight = BlendLayeredScalar(0.0, _InheritBaseHeight1, _InheritBaseHeight2, _InheritBaseHeight3, weights);
return heightResult + height0 * inheritBaseHeight;

// this function handle triplanar
void ComputeLayerWeights(FragInputs input, LayerTexCoord layerTexCoord, float4 inputAlphaMask, out float outWeights[_MAX_LAYER])
{
// Mask Values : Layer 1, 2, 3 are r, g, b. Always use layer0 parametrization for the mask
float3 inputMaskValues = SAMPLE_LAYER_TEXTURE2D(_LayerMaskMap, sampler_LayerMaskMap, layerTexCoord.base0).rgb;
#if defined(_LAYER_MASK_VERTEX_COLOR_MUL)
inputMaskValues *= input.color.rgb;
#elif defined(_LAYER_MASK_VERTEX_COLOR_ADD)
inputMaskValues = saturate(inputMaskValues + input.color.rgb * 2.0 - 1.0);
#endif
#if defined(_BASE_LAYER_MODE)
float3 minOpaParam = float3(_MinimumOpacity1, _MinimumOpacity2, _MinimumOpacity3);
float3 remapedOpacity = (float3(1.0, 1.0, 1.0) - minOpaParam) * inputAlphaMask.yzw + minOpaParam; // Remap opacity mask from [0..1] to [minOpa..1]
float3 opacityAsDensity = saturate((inputAlphaMask.yzw - (float3(1.0, 1.0, 1.0) - inputMaskValues)) * 20.0);
float3 useOpacityAsDensityParam = float3(_OpacityAsDensity1, _OpacityAsDensity2, _OpacityAsDensity3);
inputMaskValues = lerp(inputMaskValues * remapedOpacity, opacityAsDensity, useOpacityAsDensityParam);
#endif
#if defined(_HEIGHT_BASED_BLEND)
float height0 = SampleHeightmap0(layerTexCoord);
float height1 = SampleHeightmap1(layerTexCoord, _HeightCenterOffset1, _HeightFactor1);
float height2 = SampleHeightmap2(layerTexCoord, _HeightCenterOffset2, _HeightFactor2);

// Mask Values : Layer 1, 2, 3 are r, g, b
// Always use layer0 parametrization for the mask
float3 inputMaskValues = SAMPLE_LAYER_TEXTURE2D(_LayerMaskMap, sampler_LayerMaskMap, layerTexCoord.base0).rgb;
// Mutually exclusive with _HEIGHT_BASED_BLEND
#if defined(_LAYER_MASK_VERTEX_COLOR_MUL) // Used when no layer mask is set
inputMaskValues *= input.color.rgb;
#elif defined(_LAYER_MASK_VERTEX_COLOR_ADD) || defined(_HEIGHT_BASED_BLEND_V2) // When layer mask is set, color is additive to enable user to override it.
inputMaskValues = saturate(inputMaskValues + input.color.rgb * 2.0 - 1.0);
#endif
#if defined(_HEIGHT_BASED_BLEND)
#if !defined(_HEIGHT_BASED_BLEND_V2)
float baseLayerHeight = heights.x;
baseLayerHeight = ApplyHeightBasedBlend(inputMaskValues.r, baseLayerHeight, heights.y, _HeightOffset1, _HeightFactor1, _BlendSize1, input.color.r);

float3 minOpaParam = float3(_MinimumOpacity1, _MinimumOpacity2, _MinimumOpacity3);
float3 remapedOpacity = (float3(1.0, 1.0, 1.0) - minOpaParam) * inputAlphaMask.yzw + minOpaParam; // Remap opacity mask from [0..1] to [minOpa..1]
float3 opacityAsDensity = saturate((inputAlphaMask.yzw - (float3(1.0, 1.0, 1.0) - inputMaskValues))*20.0);
float3 useOpacityAsDensityParam = float3(_OpacityAsDensity1, _OpacityAsDensity2, _OpacityAsDensity3);
inputMaskValues = lerp(inputMaskValues * remapedOpacity, opacityAsDensity, useOpacityAsDensityParam);
// HACK, use height0 to avoid compiler error for unused sampler
// To remove once we have POM

// For layered shader, alpha of base color is used as either an opacity mask, a composition mask for inheritance parameters or a density mask.
float alpha = PROP_BLEND_SCALAR(alpha, weights);
#if defined(_HEIGHT_BASED_BLEND)
#if defined(_BASE_LAYER_MODE)
float3 normalTS = ComputeInheritedNormalTS(input, normalTS0, normalTS1, normalTS2, normalTS3, layerTexCoord, weights);
float3 normalTS = BlendLayeredVector3(normalTS0, normalTS1, normalTS2, normalTS3, weights);
float3 normalTS;
#if defined(_HEIGHT_BASED_BLEND)
normalTS = ComputeInheritedNormalTS(input, normalTS0, normalTS1, normalTS2, normalTS3, layerTexCoord, weights);
#else
normalTS = BlendLayeredVector3(normalTS0, normalTS1, normalTS2, normalTS3, weights);
#endif
// Init other unused parameter
surfaceData.tangentWS = normalize(input.tangentToWorld[0].xyz);

49
Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_BlendColor.mat


m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DETAIL_MAP_WITH_NORMAL _DISTORTIONDEPTHTEST_OFF
_DISTORTIONONLY_OFF _EMISSION _EMISSIVE_COLOR _LAYEREDLIT_4_LAYER _LAYEREDLIT_4_LAYERS
_LAYERMASKMAP _LAYER_MAPPING_PLANAR0 _LAYER_MAPPING_PLANAR_0 _LAYER_MAPPING_PLANAR_1
_LAYER_MAPPING_PLANAR_2 _LAYER_MAPPING_PLANAR_3 _LAYER_MASK_VERTEX_COLOR _NORMALMAP_TANGENT_SPACE
_LAYER_MAPPING_PLANAR_2 _LAYER_MAPPING_PLANAR_3 _LAYER_MASK_VERTEX_COLOR _LAYER_MASK_VERTEX_COLOR_MUL
_NORMALMAP_TANGENT_SPACE
m_EnableInstancingVariants: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses:

- _BlendSize1: 0
- _BlendSize2: 0
- _BlendSize3: 0
- _BlendUsingHeight1: 0
- _BlendUsingHeight2: 0
- _BlendUsingHeight3: 0
- _BumpScale: 1
- _CullMode: 2
- _Cutoff: 0.5

- _EmissiveIntensity1: 0
- _EmissiveIntensity2: 0
- _EmissiveIntensity3: 0
- _EnablePerPixelDisplacement: 0
- _HeightAmplitude0: 1
- _HeightAmplitude1: 1
- _HeightAmplitude2: 1
- _HeightAmplitude3: 1
- _HeightCenter0: 0
- _HeightCenter1: 0
- _HeightCenter2: 0
- _HeightCenter3: 0
- _HeightCenterOffset1: 0
- _HeightCenterOffset2: 0
- _HeightCenterOffset3: 0
- _HeightFactor1: 1
- _HeightFactor2: 1
- _HeightFactor3: 1

- _HeightScale1: 1
- _HeightScale2: 1
- _HeightScale3: 1
- _InheritBaseColor1: 0
- _InheritBaseColor2: 0
- _InheritBaseColor3: 0
- _InheritBaseColorThreshold1: 1
- _InheritBaseColorThreshold2: 1
- _InheritBaseColorThreshold3: 1
- _InheritBaseHeight1: 0
- _InheritBaseHeight2: 0
- _InheritBaseHeight3: 0
- _InheritBaseLayer1: 0
- _InheritBaseLayer2: 0
- _InheritBaseLayer3: 0
- _InheritBaseNormal1: 0
- _InheritBaseNormal2: 0
- _InheritBaseNormal3: 0
- _LayerCount: 4
- _LayerMapping0: 2
- _LayerMapping1: 2

- _Metallic1: 0
- _Metallic2: 0
- _Metallic3: 0
- _MinimumOpacity1: 1
- _MinimumOpacity2: 1
- _MinimumOpacity3: 1
- _NormalScale0: 1
- _NormalScale1: 1
- _NormalScale2: 1
- _NormalScale3: 1
- _OpacityAsDensity1: 0
- _OpacityAsDensity2: 0
- _OpacityAsDensity3: 0
- _PPDMaxSamples: 15
- _PPDMinSamples: 5
- _Parallax: 0.02
- _Smoothness: 0.5
- _Smoothness0: 0.5

- _UVMappingPlanar2: 0
- _UVMappingPlanar3: 0
- _UVSec: 0
- _UseBaseLayerMode: 0
- _UseHeightBasedBlendV2: 0
- _VertexColorMode: 1
- _ZTestMode: 8
- _ZWrite: 1
m_Colors:

1
Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_BlendColor.mat.meta


timeCreated: 1480943223
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: -1
userData: '{"GUIDArray":["fbea672215bd9944f8d9f98d5437e3cb","b91619c97bb14b64b82c0cdeaac0cc68","be6f395f0458348419faf76aca4cf856","000d0f1d5b188ed43a674de93e854997"]}'
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存