浏览代码

HDRenderPipeline: Update layered material based on artists feedback

/main
sebastienlagarde 8 年前
当前提交
ffb6c390
共有 6 个文件被更改,包括 113 次插入185 次删除
  1. 123
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
  2. 15
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  3. 15
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  4. 116
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
  5. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  6. 27
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl

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


public readonly GUIContent emissiveText = new GUIContent("Emissive");
public readonly GUIContent layerMapMaskText = new GUIContent("Layer Mask", "Layer mask");
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 vertexColorHeightMultiplierText = new GUIContent("Vertex Height Scale", "Scale applied to the vertex color height.");
public readonly GUIContent layerCountText = new GUIContent("Layer Count", "Number of layers.");
public readonly GUIContent layerTilingText = new GUIContent("Tiling", "Tiling factor applied to UVSet");
public readonly GUIContent layerTexWorldScaleText = new GUIContent("Tiling", "Tiling factor applied to Planar/Trilinear mapping");

public readonly GUIContent DensityOpacityInfluenceText = new GUIContent("Density / Opacity", "Density / Opacity");
public readonly GUIContent useHeightBasedBlendText = new GUIContent("Use Height Based Blend", "Layer will be blended with the underlying layer based on the height.");
public readonly GUIContent useMainLayerInfluenceModeText = new GUIContent("Main Layer Influence", "Switch between regular layers mode and base/layers mode");
public readonly GUIContent heightOffsetText = new GUIContent("Height Offset", "Height offset from the previous layer.");
public readonly GUIContent blendSizeText = new GUIContent("Blend Size", "Thickness over which the layer will be blended with the previous one.");
public readonly GUIContent useHeightBasedBlendV2Text = new GUIContent("Use V2", "Layer will be blended with the underlying layer based on the height.");
public readonly GUIContent blendUsingHeight = new GUIContent("Blend Using Height", "Blend Layers using height.");
public readonly GUIContent inheritBaseColorThresholdText = new GUIContent("Threshold", "Inherit the base color from the base layer.");
public readonly GUIContent minimumOpacityText = new GUIContent("Minimum Opacity", "Minimum Opacity.");

MaterialProperty useMainLayerInfluence = null;
const string kUseHeightBasedBlend = "_UseHeightBasedBlend";
MaterialProperty useHeightBasedBlend = null;
const string kUseHeightBasedBlendV2 = "_UseHeightBasedBlendV2";
MaterialProperty useHeightBasedBlendV2 = null;
const string kBlendUsingHeight = "_BlendUsingHeight";
MaterialProperty[] blendUsingHeight = new MaterialProperty[kMaxLayerCount - 1];
const string kHeightOffset = "_HeightOffset";
MaterialProperty[] heightOffset = new MaterialProperty[kMaxLayerCount-1];
const string kOpacityAsDensity = "_OpacityAsDensity";
MaterialProperty[] opacityAsDensity = new MaterialProperty[kMaxLayerCount];
const string kMinimumOpacity = "_MinimumOpacity";
MaterialProperty[] minimumOpacity = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] heightFactor = new MaterialProperty[kMaxLayerCount-1];
MaterialProperty[] heightFactor = new MaterialProperty[kMaxLayerCount];
MaterialProperty[] heightCenterOffset = new MaterialProperty[kMaxLayerCount - 1];
const string kBlendSize = "_BlendSize";
MaterialProperty[] blendSize = new MaterialProperty[kMaxLayerCount-1];
const string kVertexColorHeightFactor = "_VertexColorHeightFactor";
MaterialProperty vertexColorHeightFactor = null;
MaterialProperty[] heightCenterOffset = new MaterialProperty[kMaxLayerCount];
const string kBlendUsingHeight = "_BlendUsingHeight";
MaterialProperty[] blendUsingHeight = new MaterialProperty[kMaxLayerCount - 1];
// Height blend V2
// influence
const string kInheritBaseNormal = "_InheritBaseNormal";
MaterialProperty[] inheritBaseNormal = new MaterialProperty[kMaxLayerCount - 1];
const string kInheritBaseHeight = "_InheritBaseHeight";

const string kInheritBaseColorThreshold = "_InheritBaseColorThreshold";
MaterialProperty[] inheritBaseColorThreshold = new MaterialProperty[kMaxLayerCount - 1];
const string kOpacityAsDensity = "_OpacityAsDensity";
MaterialProperty[] opacityAsDensity = new MaterialProperty[kMaxLayerCount - 1];
const string kMinimumOpacity = "_MinimumOpacity";
MaterialProperty[] minimumOpacity = new MaterialProperty[kMaxLayerCount - 1];
MaterialProperty layerEmissiveColor = null;
MaterialProperty layerEmissiveColorMap = null;

FindMaterialOptionProperties(props);
layerMaskMap = FindProperty(kLayerMaskMap, props);
vertexColorHeightFactor = FindProperty(kVertexColorHeightFactor, props);
useHeightBasedBlendV2 = FindProperty(kUseHeightBasedBlendV2, props);
for (int i = 0; i < kMaxLayerCount; ++i)
{
layerTexWorldScale[i] = FindProperty(string.Format("{0}{1}", kTexWorldScale, i), props);

layerUVDetailsMappingMask[i] = FindProperty(string.Format("{0}{1}", kUVDetailsMappingMask, i), props);
layerTiling[i] = FindProperty(string.Format("{0}{1}", kLayerTiling, i), props);
minimumOpacity[i] = FindProperty(string.Format("{0}{1}", kMinimumOpacity, i), props);
opacityAsDensity[i] = FindProperty(string.Format("{0}{1}", kOpacityAsDensity, i), props);
heightFactor[i] = FindProperty(string.Format("{0}{1}", kHeightFactor, i), props);
heightCenterOffset[i] = FindProperty(string.Format("{0}{1}", kHeightCenterOffset, i), props);
heightOffset[i-1] = FindProperty(string.Format("{0}{1}", kHeightOffset, i), props);
heightFactor[i-1] = FindProperty(string.Format("{0}{1}", kHeightFactor, i), props);
blendSize[i-1] = FindProperty(string.Format("{0}{1}", kBlendSize, i), props);
heightCenterOffset[i - 1] = FindProperty(string.Format("{0}{1}", kHeightCenterOffset, i), props);
minimumOpacity[i - 1] = FindProperty(string.Format("{0}{1}", kMinimumOpacity, i), props);
opacityAsDensity[i - 1] = FindProperty(string.Format("{0}{1}", kOpacityAsDensity, i), props);
}
}

Material material = m_MaterialEditor.target as Material;
bool baseLayerModeEnable = useMainLayerInfluence.floatValue > 0.0f;
bool mainLayerInfluenceEnable = useMainLayerInfluence.floatValue > 0.0f;
EditorGUILayout.LabelField(styles.layerLabels[layerIndex], styles.layerLabelColors[layerIndex]);

}
}
if(layerIndex > 0)
EditorGUILayout.LabelField(styles.DensityOpacityInfluenceText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(opacityAsDensity[layerIndex], styles.opacityAsDensityText);
m_MaterialEditor.ShaderProperty(minimumOpacity[layerIndex], styles.minimumOpacityText);
EditorGUI.indentLevel--;
bool heightBasedBlendEnable = useHeightBasedBlend.floatValue != 0.0f;
if (!useHeightBasedBlend.hasMixedValue && heightBasedBlendEnable)
bool heightBasedBlendEnable = useHeightBasedBlend.floatValue != 0.0f;
bool heightBasedBlendV2Enable = useHeightBasedBlendV2.floatValue != 0.0f;
int paramIndex = layerIndex - 1;
EditorGUILayout.LabelField(styles.DensityOpacityInfluenceText, EditorStyles.boldLabel);
EditorGUILayout.LabelField(styles.heightControlText, EditorStyles.boldLabel);
m_MaterialEditor.ShaderProperty(heightFactor[layerIndex], styles.heightFactorText);
m_MaterialEditor.ShaderProperty(heightCenterOffset[layerIndex], styles.heightCenterOffsetText);
EditorGUI.indentLevel--;
}
m_MaterialEditor.ShaderProperty(opacityAsDensity[paramIndex], styles.opacityAsDensityText);
m_MaterialEditor.ShaderProperty(minimumOpacity[paramIndex], styles.minimumOpacityText);
// influence
if (layerIndex > 0)
{
int paramIndex = layerIndex - 1;
EditorGUI.indentLevel--;
if (!useHeightBasedBlend.hasMixedValue && heightBasedBlendEnable)
{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(blendUsingHeight[layerIndex], styles.blendUsingHeight);
EditorGUI.indentLevel--;
}
if (baseLayerModeEnable)
if (mainLayerInfluenceEnable)
{
EditorGUILayout.LabelField(styles.MainLayerInfluenceText, EditorStyles.boldLabel);

EditorGUI.indentLevel--;
}
if (!useHeightBasedBlend.hasMixedValue && heightBasedBlendEnable)
{
EditorGUILayout.LabelField(styles.heightControlText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(heightFactor[paramIndex], styles.heightFactorText);
if (!heightBasedBlendV2Enable)
{
m_MaterialEditor.ShaderProperty(heightOffset[paramIndex], styles.heightOffsetText);
m_MaterialEditor.ShaderProperty(blendSize[paramIndex], styles.blendSizeText);
}
else
{
m_MaterialEditor.ShaderProperty(heightCenterOffset[paramIndex], styles.heightCenterOffsetText);
m_MaterialEditor.ShaderProperty(blendUsingHeight[paramIndex], styles.blendUsingHeight);
}
EditorGUI.indentLevel--;
}
}
EditorGUI.indentLevel--;

{
useHeightBasedBlend.floatValue = enabled ? 1.0f : 0.0f;
}
if (enabled)
{
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
bool enabledV2 = EditorGUILayout.Toggle(styles.useHeightBasedBlendV2Text, useHeightBasedBlendV2.floatValue > 0.0f);
if (EditorGUI.EndChangeCheck())
{
useHeightBasedBlendV2.floatValue = enabledV2 ? 1.0f : 0.0f;
}
if(!enabledV2)
m_MaterialEditor.ShaderProperty(vertexColorHeightFactor, styles.vertexColorHeightMultiplierText);
EditorGUI.indentLevel--;
}
EditorGUILayout.Space();

}
bool useHeightBasedBlend = material.GetFloat(kUseHeightBasedBlend) != 0.0f;
bool useHeightBasedBlendV2 = material.GetFloat(kUseHeightBasedBlendV2) != 0.0f;
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;

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


[ToggleOff] _UseHeightBasedBlendV2("Use Height Blend V2", Float) = 0.0
[ToggleOff] _UseMainLayerInfluence("UseMainLayerInfluence", Float) = 0.0
_HeightOffset1("_HeightOffset1", Range(-0.3, 0.3)) = 0.0
_HeightOffset2("_HeightOffset2", Range(-0.3, 0.3)) = 0.0
_HeightOffset3("_HeightOffset3", Range(-0.3, 0.3)) = 0.0
_HeightFactor0("_HeightFactor0", Float) = 1
_BlendSize1("_BlendSize1", Range(0, 0.30)) = 0.0
_BlendSize2("_BlendSize2", Range(0, 0.30)) = 0.0
_BlendSize3("_BlendSize3", Range(0, 0.30)) = 0.0
_VertexColorHeightFactor("_VertexColorHeightFactor", Float) = 0.3
_HeightCenterOffset0("_HeightCenterOffset0", Float) = 0.0
_HeightCenterOffset1("_HeightCenterOffset1", Float) = 0.0
_HeightCenterOffset2("_HeightCenterOffset2", Float) = 0.0
_HeightCenterOffset3("_HeightCenterOffset3", Float) = 0.0

_InheritBaseColorThreshold2("_InheritBaseColorThreshold2", Range(0, 1.0)) = 1.0
_InheritBaseColorThreshold3("_InheritBaseColorThreshold3", Range(0, 1.0)) = 1.0
_MinimumOpacity0("_MinimumOpacity0", Range(0, 1.0)) = 1.0
_OpacityAsDensity0("_OpacityAsDensity0", Range(0, 1.0)) = 0.0
_OpacityAsDensity1("_OpacityAsDensity1", Range(0, 1.0)) = 0.0
_OpacityAsDensity2("_OpacityAsDensity2", Range(0, 1.0)) = 0.0
_OpacityAsDensity3("_OpacityAsDensity3", Range(0, 1.0)) = 0.0

#pragma shader_feature _ _LAYER_MASK_VERTEX_COLOR_MUL _LAYER_MASK_VERTEX_COLOR_ADD
#pragma shader_feature _MAIN_LAYER_INFLUENCE_MODE
#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _HEIGHT_BASED_BLEND_V2
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON

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


[ToggleOff] _UseHeightBasedBlendV2("Use Height Blend V2", Float) = 0.0
[ToggleOff] _UseMainLayerInfluence("UseMainLayerInfluence", Float) = 0.0
_HeightOffset1("_HeightOffset1", Range(-0.3, 0.3)) = 0.0
_HeightOffset2("_HeightOffset2", Range(-0.3, 0.3)) = 0.0
_HeightOffset3("_HeightOffset3", Range(-0.3, 0.3)) = 0.0
_HeightFactor0("_HeightFactor0", Float) = 1
_BlendSize1("_BlendSize1", Range(0, 0.30)) = 0.0
_BlendSize2("_BlendSize2", Range(0, 0.30)) = 0.0
_BlendSize3("_BlendSize3", Range(0, 0.30)) = 0.0
_VertexColorHeightFactor("_VertexColorHeightFactor", Float) = 0.3
_HeightCenterOffset0("_HeightCenterOffset0", Float) = 0.0
_HeightCenterOffset1("_HeightCenterOffset1", Float) = 0.0
_HeightCenterOffset2("_HeightCenterOffset2", Float) = 0.0
_HeightCenterOffset3("_HeightCenterOffset3", Float) = 0.0

_InheritBaseColorThreshold2("_InheritBaseColorThreshold2", Range(0, 1.0)) = 1.0
_InheritBaseColorThreshold3("_InheritBaseColorThreshold3", Range(0, 1.0)) = 1.0
_MinimumOpacity0("_MinimumOpacity0", Range(0, 1.0)) = 1.0
_OpacityAsDensity0("_OpacityAsDensity0", Range(0, 1.0)) = 0.0
_OpacityAsDensity1("_OpacityAsDensity1", Range(0, 1.0)) = 0.0
_OpacityAsDensity2("_OpacityAsDensity2", Range(0, 1.0)) = 0.0
_OpacityAsDensity3("_OpacityAsDensity3", Range(0, 1.0)) = 0.0

#pragma shader_feature _ _LAYER_MASK_VERTEX_COLOR_MUL _LAYER_MASK_VERTEX_COLOR_ADD
#pragma shader_feature _MAIN_LAYER_INFLUENCE_MODE
#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _HEIGHT_BASED_BLEND_V2
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON

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


#undef LAYER_INDEX
#undef ADD_IDX
void ComputeMaskWeights(float3 inputMasks, out float outWeights[_MAX_LAYER])
void ComputeMaskWeights(float4 inputMasks, out float outWeights[_MAX_LAYER])
masks[0] = 1.0; // Layer 0 is always full
masks[0] = inputMasks.a; // Should be 1.0 in most case except when alpha masked and desnity mode is used
masks[1] = inputMasks.r;
masks[2] = inputMasks.g;
masks[3] = inputMasks.b;

#define SURFACEDATA_BLEND_VECTOR3(surfaceData, name, mask) BlendLayeredVector3(surfaceData##0.##name, surfaceData##1.##name, surfaceData##2.##name, surfaceData##3.##name, mask);
#define SURFACEDATA_BLEND_SCALAR(surfaceData, name, mask) BlendLayeredScalar(surfaceData##0.##name, surfaceData##1.##name, surfaceData##2.##name, surfaceData##3.##name, mask);
#define PROP_BLEND_SCALAR(name, mask) BlendLayeredScalar(name##0, name##1, name##2, name##3, mask);
float ApplyHeightBasedBlend(inout float inputFactor, float previousLayerHeight, float layerHeight, float heightOffset, float heightFactor, float edgeBlendStrength, float vertexColor)
{
float finalLayerHeight = heightFactor * layerHeight + heightOffset + _VertexColorHeightFactor * (vertexColor * 2.0 - 1.0);
edgeBlendStrength = max(0.00001, edgeBlendStrength);
if (previousLayerHeight >= finalLayerHeight)
{
inputFactor = 0.0;
}
else if (finalLayerHeight > previousLayerHeight && finalLayerHeight < previousLayerHeight + edgeBlendStrength)
{
inputFactor = inputFactor * pow((finalLayerHeight - previousLayerHeight) / edgeBlendStrength, 0.5);
}
return max(finalLayerHeight, previousLayerHeight);
}
float3 ApplyHeightBasedBlendV2(float3 inputMask, float3 inputHeight, float3 blendUsingHeight)
{
return saturate(lerp(inputMask * inputHeight * blendUsingHeight * 100, 1, inputMask * inputMask)); // 100 arbitrary scale to limit blendUsingHeight values.
}
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3,
float3 positionWS, float3 normalWS, out LayerTexCoord layerTexCoord)

return inheritBaseColor * (baseColor0 - meanColor) + baseColor;
}
// Calculate displacement for per vertex displacement mapping
float ComputePerVertexDisplacement(LayerTexCoord layerTexCoord, float4 vertexColor, float lod)
// Caution: Blend mask are Layer 1 R - Layer 2 G - Layer 3 B - Main Layer A
float4 GetBlendMask(LayerTexCoord layerTexCoord, float4 vertexColor, bool useLodSampling = false, float lod = 0)
// Mask Values : Layer 1, 2, 3 are r, g, b. Always use layer0 parametrization for the mask
float3 inputMaskValues = SAMPLE_LAYER_TEXTURE2D_LOD(_LayerMaskMap, sampler_LayerMaskMap, layerTexCoord.base0, lod).rgb;
// Caution:
// Blend mask are Main Layer A - Layer 1 R - Layer 2 G - Layer 3 B
// Value for Mani layer is not use for blending itself but for alternate weighting like density.
// Settings this specific Main layer blend mask in alpha allow to be transparent in case we don't use it and 1 is provide by default.
float4 blendMasks = useLodSampling ? SAMPLE_LAYER_TEXTURE2D_LOD(_LayerMaskMap, sampler_LayerMaskMap, layerTexCoord.base0, lod) : SAMPLE_LAYER_TEXTURE2D(_LayerMaskMap, sampler_LayerMaskMap, layerTexCoord.base0);
/*
inputMaskValues *= vertexColor.rgb;
blendMasks *= vertexColor;
inputMaskValues = saturate(inputMaskValues + vertexColor.rgb * 2.0 - 1.0);
blendMasks = saturate(blendMasks + vertexColor * 2.0 - 1.0);
*/
return blendMasks;
}
// Calculate displacement for per vertex displacement mapping
float ComputePerVertexDisplacement(LayerTexCoord layerTexCoord, float4 vertexColor, float lod)
{
float4 blendMasks = GetBlendMask(layerTexCoord, vertexColor, true, lod);
ComputeMaskWeights(inputMaskValues, weights);
ComputeMaskWeights(blendMasks, weights);
float height0 = SampleHeightmapLod0(layerTexCoord, lod);
float height0 = SampleHeightmapLod0(layerTexCoord, lod, _HeightCenterOffset0, _HeightFactor0);
float height1 = SampleHeightmapLod1(layerTexCoord, lod, _HeightCenterOffset1, _HeightFactor1);
float height2 = SampleHeightmapLod2(layerTexCoord, lod, _HeightCenterOffset2, _HeightFactor2);
float height3 = SampleHeightmapLod3(layerTexCoord, lod, _HeightCenterOffset3, _HeightFactor3);

return heightResult;
}
float3 ApplyHeightBasedBlend(float3 inputMask, float3 inputHeight, float3 blendUsingHeight)
{
return saturate(lerp(inputMask * inputHeight * blendUsingHeight * 100, 1, inputMask * inputMask)); // 100 arbitrary scale to limit blendUsingHeight values.
}
// 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;
float4 blendMasks = GetBlendMask(layerTexCoord, input.color);
#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
// Note: blendMasks.argb because a is main layer
float4 minOpaParam = float4(_MinimumOpacity0, _MinimumOpacity1, _MinimumOpacity2, _MinimumOpacity3);
float4 remapedOpacity = lerp(minOpaParam, float4(1.0, 1.0, 1.0, 1.0), inputAlphaMask); // Remap opacity mask from [0..1] to [minOpa..1]
float4 opacityAsDensity = saturate((inputAlphaMask - (float4(1.0, 1.0, 1.0, 1.0) - blendMasks.argb)) * 20.0);
float3 minOpaParam = float3(_MinimumOpacity1, _MinimumOpacity2, _MinimumOpacity3);
float3 remapedOpacity = lerp(minOpaParam, float3(1.0, 1.0, 1.0), inputAlphaMask.yzw); // 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);
float4 useOpacityAsDensityParam = float4(_OpacityAsDensity0, _OpacityAsDensity1, _OpacityAsDensity2, _OpacityAsDensity3);
blendMasks.argb = lerp(blendMasks.argb * remapedOpacity, opacityAsDensity, useOpacityAsDensityParam);
float height0 = SampleHeightmap0(layerTexCoord);
float height0 = SampleHeightmap0(layerTexCoord, _HeightCenterOffset0, _HeightFactor0);
#if !defined(_HEIGHT_BASED_BLEND_V2)
float baseLayerHeight = heights.x;
baseLayerHeight = ApplyHeightBasedBlend(inputMaskValues.r, baseLayerHeight, heights.y, _HeightOffset1, _HeightFactor1, _BlendSize1, input.color.r);
baseLayerHeight = ApplyHeightBasedBlend(inputMaskValues.g, baseLayerHeight, heights.z, _HeightOffset2 + _HeightOffset1, _HeightFactor2, _BlendSize2, input.color.g);
ApplyHeightBasedBlend(inputMaskValues.b, baseLayerHeight, heights.w, _HeightOffset3 + _HeightOffset2 + _HeightOffset1, _HeightFactor3, _BlendSize3, input.color.b);
#else
// HACK, use height0 to avoid compiler error for unused sampler
// To remove once we have POM
heights.y += (heights.x * 0.0001);
// HACK, use height0 to avoid compiler error for unused sampler
// To remove once we have POM
heights.y += (heights.x * 0.0001);
inputMaskValues = ApplyHeightBasedBlendV2(inputMaskValues, heights.yzw, float3(_BlendUsingHeight1, _BlendUsingHeight2, _BlendUsingHeight3));
#endif
// don't apply on main layer
blendMasks.rgb = ApplyHeightBasedBlend(blendMasks.rgb, heights.yzw, float3(_BlendUsingHeight1, _BlendUsingHeight2, _BlendUsingHeight3));
ComputeMaskWeights(inputMaskValues, outWeights);
ComputeMaskWeights(blendMasks, outWeights);
}
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)

float alpha1 = GetSurfaceData1(input, layerTexCoord, surfaceData1, normalTS1);
float alpha2 = GetSurfaceData2(input, layerTexCoord, surfaceData2, normalTS2);
float alpha3 = GetSurfaceData3(input, layerTexCoord, surfaceData3, normalTS3);
// For layering we kill pixel based on maximun alpha
#ifdef _ALPHATEST_ON
#if _LAYER_COUNT == 2
clip(max(alpha0, alpha1) - _AlphaCutoff);
#endif
#if _LAYER_COUNT == 3
clip(max3(alpha0, alpha1, alpha2) - _AlphaCutoff);
#endif
#if _LAYER_COUNT == 4
clip(max(alpha3, max3(alpha0, alpha1, alpha2)) - _AlphaCutoff);
#endif
#endif
float weights[_MAX_LAYER];
ComputeLayerWeights(input, layerTexCoord, float4(alpha0, alpha1, alpha2, alpha3), weights);

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


#endif
// Perform alha test very early to save performance (a killed pixel will not sample textures)
#ifdef _ALPHATEST_ON
#if defined(_ALPHATEST_ON) && !defined(LAYERED_LIT_SHADER)
clip(alpha - _AlphaCutoff);
#endif

27
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl


TEXTURE2D(_LayerMaskMap);
SAMPLER2D(sampler_LayerMaskMap);
float _HeightOffset1;
float _HeightOffset2;
float _HeightOffset3;
float _HeightFactor1;
float _HeightFactor2;
float _HeightFactor3;
float _BlendSize1;
float _BlendSize2;
float _BlendSize3;
float _VertexColorHeightFactor;
// Blend Properties V2
float _UseHeightBasedBlendV2;
float _HeightCenterOffset1;
float _HeightCenterOffset2;
float _HeightCenterOffset3;
PROP_DECL(float, _HeightFactor);
PROP_DECL(float, _HeightCenterOffset);
PROP_DECL(float, _MinimumOpacity);
PROP_DECL(float, _OpacityAsDensity);
float _InheritBaseNormal1;
float _InheritBaseNormal2;
float _InheritBaseNormal3;

float _InheritBaseColorThreshold1;
float _InheritBaseColorThreshold2;
float _InheritBaseColorThreshold3;
float _MinimumOpacity1;
float _MinimumOpacity2;
float _MinimumOpacity3;
float _OpacityAsDensity1;
float _OpacityAsDensity2;
float _OpacityAsDensity3;
PROP_DECL(float, _LayerTiling);
float3 _EmissiveColor;

正在加载...
取消
保存