浏览代码

Merge pull request #1275 from Unity-Technologies/stacklit

Stacklit
/main
GitHub 7 年前
当前提交
6dfee119
共有 5 个文件被更改,包括 380 次插入246 次删除
  1. 77
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs
  2. 198
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/StackLit/StackLitUI.cs
  3. 85
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLit.shader
  4. 208
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLitData.hlsl
  5. 58
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLitProperties.hlsl

77
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs


public string m_Title = string.Empty;
private readonly BaseProperty[] m_ChildProperties;
private readonly Property m_Show;
public bool Foldout = false;
public GroupProperty(BaseMaterialGUI parent, BaseProperty[] childProperties, Func<object, bool> isVisible = null)
: this(parent, string.Empty, childProperties, isVisible)
public GroupProperty(BaseMaterialGUI parent, string groupName, BaseProperty[] childProperties, Func<object, bool> isVisible = null)
: this(parent, groupName, string.Empty, childProperties, isVisible)
public GroupProperty(BaseMaterialGUI parent, string groupTitle, BaseProperty[] childProperties, Func<object, bool> isVisible = null)
public GroupProperty(BaseMaterialGUI parent, string groupName, string groupTitle, BaseProperty[] childProperties, Func<object, bool> isVisible = null)
m_Show = new Property(parent, groupName + "Show", "", false);
m_Title = groupTitle;
m_ChildProperties = childProperties;
}

m_Show.OnFindProperty(props);
foreach (var c in m_ChildProperties)
{
c.OnFindProperty(props);

{
if (!string.IsNullOrEmpty(m_Title))
{
Foldout = EditorGUILayout.Foldout(Foldout, m_Title);
m_Show.BoolValue = EditorGUILayout.Foldout(m_Show.BoolValue, m_Title);
else
else if (m_Show.IsValid)
Foldout = true;
m_Show.BoolValue = true;
if (Foldout)
if (!m_Show.IsValid || m_Show.BoolValue)
{
EditorGUI.indentLevel++;

public string PropertyName;
public string PropertyText;
protected MaterialProperty m_MaterialProperty = null;
public MaterialProperty m_MaterialProperty = null;
protected readonly GUIContent m_GuiContent = null;

public bool BoolValue
{
get { return Math.Abs(m_MaterialProperty.floatValue) > 0.0f; }
get { return m_MaterialProperty == null || Math.Abs(m_MaterialProperty.floatValue) > 0.0f; }
set { m_MaterialProperty.floatValue = value ? 1.0f : 0.0f; }
}

Triplanar,
}
public Property m_Show;
public Property m_ConstantProperty;
public TextureOneLineProperty m_TextureProperty;
public ComboProperty m_UvSetProperty;

public ComboProperty m_TilingProperty;
public Property m_ChannelProperty;
public Property m_RemapProperty;

public bool Foldout = false;
public TextureProperty(BaseMaterialGUI parent, string propertyName, string constantPropertyName, string guiText, bool isMandatory = true, bool isNormalMap = false)
: this(parent, propertyName, constantPropertyName, guiText, string.Empty, isMandatory, isNormalMap)
public TextureProperty(BaseMaterialGUI parent, string propertyName, string constantPropertyName, string guiText, bool useConstantAsTint, bool isMandatory = true, bool isNormalMap = false)
: this(parent, propertyName, constantPropertyName, guiText, string.Empty, useConstantAsTint, isMandatory, isNormalMap)
public TextureProperty(BaseMaterialGUI parent, string propertyName, string constantPropertyName, string guiText, string toolTip, bool isMandatory = true, bool isNormalMap = false)
public TextureProperty(BaseMaterialGUI parent, string propertyName, string constantPropertyName, string guiText, string toolTip, bool useConstantAsTint, bool isMandatory = true, bool isNormalMap = false)
m_TextureProperty = new TextureOneLineProperty(parent, propertyName, constantPropertyName, guiText, toolTip, isMandatory);
m_Show = new Property(parent, propertyName + "Show", "", isMandatory);
if (useConstantAsTint == false)
{
m_ConstantProperty = new Property(parent, constantPropertyName, guiText, toolTip, isMandatory);
}
m_TextureProperty = new TextureOneLineProperty(parent, propertyName, useConstantAsTint ? constantPropertyName : string.Empty, guiText, toolTip, isMandatory);
m_TilingProperty = new ComboProperty(parent, propertyName + "Tiling", "Tiling", Enum.GetNames(typeof(Tiling)), false);
m_ChannelProperty = new Property(parent, propertyName + "Channel", "Channel", false);
m_ChannelProperty = new ComboProperty(parent, propertyName + "Channel", "Channel", Enum.GetNames(typeof(Channel)), false);
m_RemapProperty = new Property(parent, constantPropertyName + "Remap", "Remapping", "Defines the range to remap/scale the values in texture", false);
m_InvertRemapProperty = new Property(parent, constantPropertyName + "RemapInverted", "Invert Remapping", "Whether the mapping values are inverted.", false);

{
base.OnFindProperty(props);
m_Show.OnFindProperty(props);
if (m_ConstantProperty != null)
{
m_ConstantProperty.OnFindProperty(props);
}
m_TilingProperty.OnFindProperty(props);
m_ChannelProperty.OnFindProperty(props);
m_RemapProperty.OnFindProperty(props);
m_InvertRemapProperty.OnFindProperty(props);

{
if (m_TextureProperty.IsValid
&& (IsVisible == null || IsVisible(this)))
if ((IsVisible == null || IsVisible(this))
&& m_Show.IsValid
&& m_TextureProperty.IsValid)
Foldout = EditorGUILayout.Foldout(Foldout, PropertyText);
if (Foldout)
m_Show.BoolValue = EditorGUILayout.Foldout(m_Show.BoolValue, PropertyText);
if (m_Show.BoolValue)
if (m_ConstantProperty != null && m_ConstantProperty.IsValid
&& m_TextureProperty.TextureValue == null)
{
m_ConstantProperty.OnGUI();
}
m_TextureProperty.OnGUI();

m_LocalOrWorldProperty.OnGUI();
m_TilingProperty.OnGUI();
Parent.m_MaterialEditor.TextureScaleOffsetProperty(m_TextureProperty.m_MaterialProperty);
m_LocalOrWorldProperty.OnGUI();
if (m_RemapProperty.IsValid)

198
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/StackLit/StackLitUI.cs


// Base
protected const string k_BaseColor = "_BaseColor";
protected const string k_BaseColorMap = "_BaseColorMap";
protected const string k_BaseColorMapUV = "_BaseColorMapUV";
protected const string k_MetallicRemapMin = "_MetallicRemap";
protected const string k_MetallicMapUV = "_MetallicMapUV";
protected const string k_MetallicRemap = "_MetallicRemap";
protected const string k_MetallicRemapInverted = "_MetallicRemapInverted";
protected const string k_MetallicRange = "_MetallicRange";
protected const string k_Smoothness1RemapMin = "_SmoothnessARemap";
protected const string k_Smoothness1MapUV = "_SmoothnessAMapUV";
protected const string k_Smoothness1Remap = "_SmoothnessARemap";
protected const string k_Smoothness1RemapInverted = "_SmoothnessARemapInverted";
protected const string k_Smoothness1Range = "_SmoothnessARange";
protected const string k_NormalMapUV = "_NormalMapUV";
protected const string k_EmissiveColorMapUV = "_EmissiveColorMapUV";
protected const string k_DiffusionProfileName = "_DiffusionProfile";
protected const string k_SubsurfaceMaskName = "_SubsurfaceMask";
protected const string k_DiffusionProfile = "_DiffusionProfile";
protected const string k_SubsurfaceMask = "_SubsurfaceMask";
protected const string k_SubsurfaceMaskMapUV = "_SubsurfaceMaskMapUV";
protected const string k_SubsurfaceMaskRemap = "_SubsurfaceMaskRemap";
protected const string k_SubsurfaceMaskRemapInverted = "_SubsurfaceMaskRemapInverted";
protected const string k_SubsurfaceMaskRange = "_SubsurfaceMaskRange";
protected const string k_ThicknessName = "_Thickness";
protected const string k_ThicknessMapName = "_ThicknessMap";
protected const string k_ThicknessRemapName = "_ThicknessRemap";
// Translucency
protected const string k_Thickness = "_Thickness";
protected const string k_ThicknessMap = "_ThicknessMap";
protected const string k_ThicknessMapUV = "_ThicknessMapUV";
protected const string k_ThicknessRemap = "_ThicknessRemap";
protected const string k_ThicknessRemapInverted = "_ThicknessRemapInverted";
protected const string k_ThicknessRange = "_ThicknessRange";
protected const string k_SmoothnessRemap2Min = "_SmoothnessBRemap";
protected const string k_Smoothness2MapUV = "_SmoothnessBMapUV";
protected const string k_Smoothness2Remap = "_SmoothnessBRemap";
protected const string k_Smoothness2RemapInverted = "_SmoothnessBRemapInverted";
protected const string k_Smoothness2Range = "_SmoothnessBRange";
protected const string k_LobeMix = "_LobeMix";

public StackLitGUI()
{
_baseMaterialProperties = new GroupProperty(this, new BaseProperty[]
_baseMaterialProperties = new GroupProperty(this, "_BaseMaterial", new BaseProperty[]
_materialProperties = new GroupProperty(this, new BaseProperty[]
_materialProperties = new GroupProperty(this, "_Material", new BaseProperty[]
new GroupProperty(this, "Standard", new BaseProperty[]
new GroupProperty(this, "_Standard", "Standard", new BaseProperty[]
new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Base Color + Opacity", "Albedo (RGB) and Opacity (A)", false),
new TextureProperty(this, k_MetallicMap, k_Metallic, "Metallic", "Metallic", false),
new TextureProperty(this, k_Smoothness1Map, k_Smoothness1, "Smoothness", "Smoothness", false),
new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Base Color + Opacity", "Albedo (RGB) and Opacity (A)", true, false),
new TextureProperty(this, k_MetallicMap, k_Metallic, "Metallic", "Metallic", false, false),
new TextureProperty(this, k_Smoothness1Map, k_Smoothness1, "Smoothness", "Smoothness", false, false),
new TextureProperty(this, k_NormalMap, k_NormalScale, "Normal TODO", "Normal Map", false, true),
new TextureProperty(this, k_NormalMap, k_NormalScale, "Normal TODO", "Normal Map", false, false, true),
new GroupProperty(this, "Emissive", new BaseProperty[]
new GroupProperty(this, "_Emissive", "Emissive", new BaseProperty[]
new TextureProperty(this, k_EmissiveColorMap, k_EmissiveColor, "Emissive Color", "Emissive", false),
new TextureProperty(this, k_EmissiveColorMap, k_EmissiveColor, "Emissive Color", "Emissive", true, false),
//new GroupProperty(this, "Coat", new BaseProperty[]
//new GroupProperty(this, "_Coat", "Coat", new BaseProperty[]
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "SmoothnessCoat", "smoothnessCoat", false),
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Index Of Refraction", "iorCoat", false),
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Normal", "normal Coat", false),
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "SmoothnessCoat", "smoothnessCoat", false, false),
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Index Of Refraction", "iorCoat", false, false),
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Normal", "normal Coat", false, false),
new GroupProperty(this, "Sub-Surface Scattering", new BaseProperty[]
new GroupProperty(this, "_SSS", "Sub-Surface Scattering", new BaseProperty[]
new DiffusionProfileProperty(this, k_DiffusionProfileName, "Diffusion Profile", "A profile determines the shape of the SSS/transmission filter.", false),
new TextureProperty(this, k_SubsurfaceMaskName, "Subsurface mask map (R)", "Determines the strength of the subsurface scattering effect.", false),
new DiffusionProfileProperty(this, k_DiffusionProfile, "Diffusion Profile", "A profile determines the shape of the SSS/transmission filter.", false),
new TextureProperty(this, k_SubsurfaceMaskMap, k_SubsurfaceMask, "Subsurface mask map (R)", "Determines the strength of the subsurface scattering effect.", false, false),
new GroupProperty(this, "Second Specular Lobe", new BaseProperty[]
new GroupProperty(this, "_Lobe2", "Second Specular Lobe", new BaseProperty[]
new TextureProperty(this, k_Smoothness2Map, k_Smoothness2, "Smoothness2", "Smoothness2", false),
new TextureProperty(this, k_Smoothness2Map, k_Smoothness2, "Smoothness2", "Smoothness2", false, false),
//new GroupProperty(this, "Anisotropy", new BaseProperty[]
//new GroupProperty(this, "_Anisotropy", "Anisotropy", new BaseProperty[]
//{
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Anisotropy Strength", "anisotropy strength", false),
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Rotation", "rotation", false),

new GroupProperty(this, "Transmission", new BaseProperty[]
new GroupProperty(this, "_Transmission", "Transmission", new BaseProperty[]
new DiffusionProfileProperty(this, k_DiffusionProfileName, "Diffusion Profile", "A profile determines the shape of the SSS/transmission filter.", false),
new TextureProperty(this, k_ThicknessName, "Thickness", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object.", false),
new DiffusionProfileProperty(this, k_DiffusionProfile, "Diffusion Profile", "A profile determines the shape of the SSS/transmission filter.", false),
new TextureProperty(this, k_ThicknessMap, k_Thickness, "Thickness", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object.", false),
//new GroupProperty(this, "Iridescence", new BaseProperty[]
//new GroupProperty(this, "_Iridescence", "Iridescence", new BaseProperty[]
//new GroupProperty(this, "Glint", new BaseProperty[]
//new GroupProperty(this, "_Glint", "Glint", new BaseProperty[]
//{
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Density", "Density:", false),
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Tint", "Tint", false),

SetupMaterialKeywordsAndPass(material);
}
protected static void SetupTextureMaterialProperty(Material material, string basePropertyName)
{
string useMapPropertyName = basePropertyName + "UseMap";
string mapPropertyName = basePropertyName + "Map";
string remapPropertyName = basePropertyName + "Remap";
string invertPropertyName = basePropertyName + "RemapInverted";
string rangePropertyName = basePropertyName + "Range";
string channelPropertyName = basePropertyName + "MapChannel";
string channelMaskPropertyName = basePropertyName + "MapChannelMask";
if (material.GetTexture(mapPropertyName))
{
Vector4 rangeVector = material.GetVector(remapPropertyName);
if (material.GetFloat(invertPropertyName) > 0.0f)
{
float s = rangeVector.x;
rangeVector.x = rangeVector.y;
rangeVector.y = s;
}
material.SetFloat(useMapPropertyName, 1.0f);
material.SetVector(rangePropertyName, rangeVector);
int channel = (int)material.GetFloat(channelPropertyName);
switch (channel)
{
case 0:
material.SetVector(channelMaskPropertyName, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
break;
case 1:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
break;
case 2:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 0.0f, 1.0f, 0.0f));
break;
case 3:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
break;
}
}
else
{
material.SetFloat(useMapPropertyName, 0.0f);
material.SetVector(rangePropertyName, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
material.SetVector(channelMaskPropertyName, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
}
}
static public void SetupMaterialKeywordsAndPass(Material material)
public static void SetupMaterialKeywordsAndPass(Material material)
{
//TODO see BaseLitUI.cs:SetupBaseLitKeywords (stencil etc)
SetupBaseUnlitKeywords(material);

CoreUtils.SetKeyword(material, "_NORMALMAP_TANGENT_SPACE", true);
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture(k_NormalMap));
CoreUtils.SetKeyword(material, "_SMOOTHNESSMASKMAPA", material.GetTexture(k_Smoothness1Map));
CoreUtils.SetKeyword(material, "_SMOOTHNESSMASKMAPB", material.GetTexture(k_Smoothness2Map));
CoreUtils.SetKeyword(material, "_METALLICMAP", material.GetTexture(k_MetallicMap));
CoreUtils.SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(k_EmissiveColorMap));
SetupTextureMaterialProperty(material, k_Metallic);
SetupTextureMaterialProperty(material, k_Smoothness1);
SetupTextureMaterialProperty(material, k_Smoothness2);
SetupTextureMaterialProperty(material, k_SubsurfaceMask);
SetupTextureMaterialProperty(material, k_Thickness);
// Check if we are using specific UVs.
TextureProperty.UVMapping[] uvIndices = new[]
{
(TextureProperty.UVMapping)material.GetFloat(k_BaseColorMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_MetallicMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_NormalMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_Smoothness1MapUV),
(TextureProperty.UVMapping)material.GetFloat(k_Smoothness2MapUV),
(TextureProperty.UVMapping)material.GetFloat(k_EmissiveColorMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_SubsurfaceMaskMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_ThicknessMapUV),
};
//bool needUV2 = (LitGUI.UVBaseMapping)material.GetFloat(k_UVBase) == LitGUI.UVBaseMapping.UV2;
//bool needUV3 = (LitGUI.UVBaseMapping)material.GetFloat(k_UVBase) == LitGUI.UVBaseMapping.UV3;
bool requireUv2 = false;
bool requireUv3 = false;
for (int i = 0; i < uvIndices.Length; ++i)
{
requireUv2 = requireUv2 || uvIndices[i] == TextureProperty.UVMapping.UV2;
requireUv3 = requireUv3 || uvIndices[i] == TextureProperty.UVMapping.UV3;
}
//if (needUV3)
//{
// material.DisableKeyword("_REQUIRE_UV2");
// material.EnableKeyword("_REQUIRE_UV3");
//}
//else if (needUV2)
//{
// material.EnableKeyword("_REQUIRE_UV2");
// material.DisableKeyword("_REQUIRE_UV3");
//}
//else
//{
// material.DisableKeyword("_REQUIRE_UV2");
// material.DisableKeyword("_REQUIRE_UV3");
//}
if (requireUv2)
{
material.EnableKeyword("_REQUIRE_UV2");
}
else
{
material.DisableKeyword("_REQUIRE_UV2");
}
CoreUtils.SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(k_EmissiveColorMap));
if (requireUv3)
{
material.EnableKeyword("_REQUIRE_UV3");
}
else
{
material.DisableKeyword("_REQUIRE_UV3");
}
}
}
} // namespace UnityEditor

85
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLit.shader


// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear
// Be careful, do not change the name here to _Color. It will conflict with the "fake" parameters (see end of properties) required for GI.
_BaseColor("BaseColor", Color) = (1,1,1,1)
_BaseColorMap("BaseColorMap", 2D) = "white" {}
_BaseColorMapUV("BaseColorMapUV", Float) = 0.0
_BaseColorMap("BaseColor Map", 2D) = "white" {}
[HideInInspector] _BaseColorMapShow("BaseColor Map Show", Float) = 0
_BaseColorMapUV("BaseColor Map UV", Float) = 0.0
[HideInInspector] _MetallicMapShow("Metallic Map Show", Float) = 0
_MetallicMap("MetallicMap", 2D) = "black" {}
_MetallicMapUV("MetallicMapUV", Float) = 0.0
_MetallicMapChannel("MetallicMapChannel", Vector) = (1, 0, 0, 0)
_MetallicMap("Metallic Map", 2D) = "black" {}
_MetallicUseMap("Metallic Use Map", Float) = 0
_MetallicMapUV("Metallic Map UV", Float) = 0.0
_MetallicMapChannel("Metallic Map Channel", Float) = 0.0
_MetallicMapChannelMask("Metallic Map Channel Mask", Vector) = (1, 0, 0, 0)
[HideInInspector] _MetallicRange("Metallic Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _SmoothnessAMapShow("SmoothnessA Map Show", Float) = 0
_SmoothnessAMap("BaseColorMap", 2D) = "white" {}
_SmoothnessAMapUV("SmoothnessAMapUV", Float) = 0.0
_SmoothnessAMapChannel("SmoothnessA Map Channel", Vector) = (1, 0, 0, 0)
_SmoothnessAMap("SmoothnessA Map", 2D) = "white" {}
_SmoothnessAUseMap("SmoothnessA Use Map", Float) = 0
_SmoothnessAMapUV("SmoothnessA Map UV", Float) = 0.0
_SmoothnessAMapChannel("SmoothnessA Map Channel", Float) = 0.0
_SmoothnessAMapChannelMask("SmoothnessA Map Channel Mask", Vector) = (1, 0, 0, 0)
[HideInInspector] _SmoothnessARange("SmoothnessA Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _SmoothnessBMapShow("SmoothnessB Map Show", Float) = 0
_SmoothnessBMap("SmoothnessBMap", 2D) = "white" {}
_SmoothnessBMapUV("SmoothnessBMapUV", Float) = 0.0
_SmoothnessBMapChannel("SmoothnessB Map Channel", Vector) = (1, 0, 0, 0)
_SmoothnessBMap("SmoothnessB Map", 2D) = "white" {}
_SmoothnessBUseMap("SmoothnessB Use Map", Float) = 0
_SmoothnessBMapUV("SmoothnessB Map UV", Float) = 0.0
_SmoothnessBMapChannel("SmoothnessB Map Channel", Float) = 0.0
_SmoothnessBMapChannelMask("SmoothnessB Map Channel Mask", Vector) = (1, 0, 0, 0)
[HideInInspector] _SmoothnessBRange("SmoothnessB Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _NormalMapShow("NormalMap Show", Float) = 0.0
_NormalScale("_NormalScale", Range(0.0, 2.0)) = 1
_NormalScale("Normal Scale", Range(0.0, 2.0)) = 1
[HideInInspector] _EmissiveColorMapShow("Emissive Color Map Show", Float) = 0.0
_EmissiveColor("Emissive Color", Color) = (1, 1, 1)
_EmissiveColorMap("Emissive Color Map", 2D) = "white" {}
_EmissiveColorMapUV("Emissive Color Map UV", Range(0.0, 1.0)) = 0
_EmissiveIntensity("Emissive Intensity", Float) = 0
[ToggleUI] _AlbedoAffectEmissive("Albedo Affect Emissive", Float) = 0.0
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase("UV Set for base", Float) = 0
[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0)
[HideInInspector] _SubsurfaceMaskMapShow("Subsurface Mask Map Show", Float) = 0
_SubsurfaceMask("Subsurface Mask", Range(0.0, 1.0)) = 1.0
_SubsurfaceMaskMap("Subsurface Mask Map", 2D) = "black" {}
_SubsurfaceMaskUSeMap("Subsurface Mask Use Map", Float) = 0
_SubsurfaceMaskMapUV("Subsurface Mask Map UV", Float) = 0.0
_SubsurfaceMaskMapChannel("Subsurface Mask Map Channel", Float) = 0.0
_SubsurfaceMaskMapChannelMask("Subsurface Mask Map Channel Mask", Vector) = (1, 0, 0, 0)
_SubsurfaceMaskRemap("Subsurface Mask Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _SubsurfaceMaskRemapInverted("Invert Subsurface Mask Remap", Float) = 0.0
[HideInInspector] _SubsurfaceMaskRange("Subsurface Mask Range", Vector) = (0, 1, 0, 0)
_EmissiveColor("EmissiveColor", Color) = (1, 1, 1)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveColorMapUV("EmissiveColorMap", Range(0.0, 1.0)) = 0
_EmissiveIntensity("EmissiveIntensity", Float) = 0
[ToggleUI] _AlbedoAffectEmissive("Albedo Affect Emissive", Float) = 0.0
[HideInInspector] _ThicknessMapShow("Thickness Show", Float) = 0
_Thickness("Thickness", Range(0.0, 1.0)) = 1.0
_ThicknessMap("Thickness Map", 2D) = "black" {}
_ThicknessUseMap("Thickness Use Map", Float) = 0
_ThicknessMapUV("Thickness Map UV", Float) = 0.0
_ThicknessMapChannel("Thickness Map Channel", Float) = 0.0
_ThicknessMapChannelMask("Thickness Map Channel Mask", Vector) = (1, 0, 0, 0)
_ThicknessRemap("Thickness Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _ThicknessRemapInverted("Invert Thickness Remap", Float) = 0.0
[HideInInspector] _ThicknessRange("Thickness Range", Vector) = (0, 1, 0, 0)
_DistortionVectorMap("DistortionVectorMap", 2D) = "black" {}
[ToggleUI] _DistortionEnable("Enable Distortion", Float) = 0.0

[ToggleUI] _DoubleSidedEnable("Double sided enable", Float) = 0.0
[Enum(Flip, 0, Mirror, 1, None, 2)] _DoubleSidedNormalMode("Double sided normal mode", Float) = 1 // This is for the editor only, see BaseLitUI.cs: _DoubleSidedConstants will be set based on the mode.
[HideInInspector] _DoubleSidedConstants("_DoubleSidedConstants", Vector) = (1, 1, -1, 0)
// Sections show values.
[HideInInspector] _StandardShow("_StandardShow", Float) = 0.0
[HideInInspector] _EmissiveShow("_EmissiveShow", Float) = 0.0
[HideInInspector] _CoatShow("_CoatShow", Float) = 0.0
[HideInInspector] _SSSShow("_SSSShow", Float) = 0.0
[HideInInspector] _Lobe2Show("_Lobe2Show", Float) = 0.0
[HideInInspector] _AnisotropyShow("_AnisotropyShow", Float) = 0.0
[HideInInspector] _TransmissionShow("_TransmissionShow", Float) = 0.0
[HideInInspector] _IridescenceShow("_IridescenceShow", Float) = 0.0
[HideInInspector] _GlintShow("_GlintShow", Float) = 0.0
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor"
// value that exist to identify if the GI emission need to be enabled.

208
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLitData.hlsl


#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl"
#include "../MaterialUtilities.hlsl"
//-----------------------------------------------------------------------------
// Texture Mapping (think of LayerTexCoord as simply TexCoordMappings,
// ie no more layers here - cf Lit materials)
//-----------------------------------------------------------------------------
////-----------------------------------------------------------------------------
//// Texture Mapping (think of LayerTexCoord as simply TexCoordMappings,
//// ie no more layers here - cf Lit materials)
////-----------------------------------------------------------------------------
// For easier copying of code for now use a LayerTexCoord wrapping struct.
// We don't have details yet.
////
//// For easier copying of code for now use a LayerTexCoord wrapping struct.
//// We don't have details yet.
////
//// NEWLITTODO: Eventually, we could quickly share GetBuiltinData of LitBuiltinData.hlsl
//// in our GetSurfaceAndBuiltinData( ) here, since we will use the LayerTexCoord identifier,
//// and an identical ComputeLayerTexCoord( ) prototype
////
//struct LayerTexCoord
//{
// UVMapping base;
// NEWLITTODO: Eventually, we could quickly share GetBuiltinData of LitBuiltinData.hlsl
// in our GetSurfaceAndBuiltinData( ) here, since we will use the LayerTexCoord identifier,
// and an identical ComputeLayerTexCoord( ) prototype
// // Store information that will be share by all UVMapping
// float3 vertexNormalWS; // TODO: store also object normal map for object triplanar
//};
struct LayerTexCoord
{
UVMapping base;
UVMapping details;
// Store information that will be share by all UVMapping
float3 vertexNormalWS; // TODO: store also object normal map for object triplanar
};
//// Want to use only one sampler for normalmap/bentnormalmap either we use OS or TS. And either we have normal map or bent normal or both.
////
//// Note (compared to Lit shader):
////
//// We don't have a layered material with which we are sharing code here like the LayeredLit shader, but we can also save a couple of
//// samplers later if we use bentnormals.
////
//// _IDX suffix is meaningless here, could use the name SAMPLER_NORMALMAP_ID instead of SAMPLER_NORMALMAP_IDX and replace all
//// indirect #ifdef _NORMALMAP_TANGENT_SPACE_IDX #ifdef and _NORMALMAP_IDX tests with the more direct
//// shader_feature keywords _NORMALMAP_TANGENT_SPACE and _NORMALMAP.
////
//// (Originally in the LayeredLit shader, shader_feature keywords like _NORMALMAP become _NORMALMAP0 but since files are shared,
//// LitDataIndividualLayer will use a generic _NORMALMAP_IDX defined before its inclusion by the client LitData or LayeredLitData.
//// That way, LitDataIndividualLayer supports multiple inclusions)
// Want to use only one sampler for normalmap/bentnormalmap either we use OS or TS. And either we have normal map or bent normal or both.
//
// Note (compared to Lit shader):
//
// We don't have a layered material with which we are sharing code here like the LayeredLit shader, but we can also save a couple of
// samplers later if we use bentnormals.
//
// _IDX suffix is meaningless here, could use the name SAMPLER_NORMALMAP_ID instead of SAMPLER_NORMALMAP_IDX and replace all
// indirect #ifdef _NORMALMAP_TANGENT_SPACE_IDX #ifdef and _NORMALMAP_IDX tests with the more direct
// shader_feature keywords _NORMALMAP_TANGENT_SPACE and _NORMALMAP.
//
// (Originally in the LayeredLit shader, shader_feature keywords like _NORMALMAP become _NORMALMAP0 but since files are shared,
// LitDataIndividualLayer will use a generic _NORMALMAP_IDX defined before its inclusion by the client LitData or LayeredLitData.
// That way, LitDataIndividualLayer supports multiple inclusions)
//
//
#ifdef _NORMALMAP_TANGENT_SPACE
#if defined(_NORMALMAP)
#define SAMPLER_NORMALMAP_ID sampler_NormalMap

//#endif
#endif
void ComputeLayerTexCoord( // Uv related parameters
float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3, float4 uvMappingMask,
// scale and bias for base
float2 texScale, float2 texBias,
// mapping type and output
int mappingType, inout LayerTexCoord layerTexCoord)
{
//TODO: Planar, Triplanar, detail map, surface_gradient.
// Handle uv0, uv1, uv2, uv3 based on _UVMappingMask weight (exclusif 0..1)
float2 uvBase = uvMappingMask.x * texCoord0 +
uvMappingMask.y * texCoord1 +
uvMappingMask.z * texCoord2 +
uvMappingMask.w * texCoord3;
// Copy data in uvmapping fields: used by generic sampling code (see especially SampleUVMappingNormalInternal.hlsl)
layerTexCoord.base.mappingType = mappingType;
layerTexCoord.base.normalWS = layerTexCoord.vertexNormalWS;
// Apply tiling options
layerTexCoord.base.uv = uvBase * texScale + texBias;
}
float3 GetNormalTS(FragInputs input, LayerTexCoord layerTexCoord, float3 detailNormalTS, float detailMask)
float3 GetNormalTS(FragInputs input, float2 texCoord, float3 detailNormalTS, float detailMask)
{
// TODO: different spaces (eg #ifdef _NORMALMAP_TANGENT_SPACE #elif object space, SURFACE_GRADIENT, etc.)
// and use detail map

// Note we don't use the _NORMALMAP_IDX mechanism of the Lit shader, since we don't have "layers", we can
// directly use the shader_feature keyword:
#ifdef _NORMALMAP
normalTS = SAMPLE_UVMAPPING_NORMALMAP(_NormalMap, SAMPLER_NORMALMAP_ID, layerTexCoord.base, _NormalScale);
normalTS = SAMPLE_UVMAPPING_NORMALMAP(_NormalMap, SAMPLER_NORMALMAP_ID, texCoord, _NormalScale);
#else
normalTS = float3(0.0, 0.0, 1.0);
#endif

// This maybe call directly by tessellation (domain) shader, thus all part regarding surface gradient must be done
// in function with FragInputs input as parameters
// layerTexCoord must have been initialize to 0 outside of this function
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3,
float3 positionWS, float3 vertexNormalWS, inout LayerTexCoord layerTexCoord)
{
layerTexCoord.vertexNormalWS = vertexNormalWS;
// TODO:
//layerTexCoord.triplanarWeights = ComputeTriplanarWeights(vertexNormalWS);
int mappingType = UV_MAPPING_UVSET;
//TODO: _MAPPING_PLANAR, _MAPPING_TRIPLANAR
// Be sure that the compiler is aware that we don't use UV1 to UV3 for main layer so it can optimize code
ComputeLayerTexCoord( texCoord0, texCoord1, texCoord2, texCoord3, _UVMappingMask, /* TODO _UVDetailsMappingMask, */
_BaseColorMap_ST.xy, _BaseColorMap_ST.zw, /* TODO _DetailMap_ST.xy, _DetailMap_ST.zw, 1.0, _LinkDetailsWithBase,
/* TODO positionWS, _TexWorldScale, */
mappingType, layerTexCoord);
}
// This is call only in this file
// layerTexCoord must have been initialize to 0 outside of this function
void GetLayerTexCoord(FragInputs input, inout LayerTexCoord layerTexCoord)
{
// TODO: SURFACE_GRADIENT
//#ifdef SURFACE_GRADIENT
//GenerateLayerTexCoordBasisTB(input, layerTexCoord);
//#endif
GetLayerTexCoord( input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3,
input.positionWS, input.worldToTangent[2].xyz, layerTexCoord);
}
#define TEXCOORD_INDEX_UV0 (0)
#define TEXCOORD_INDEX_UV1 (1)
#define TEXCOORD_INDEX_UV2 (2)
#define TEXCOORD_INDEX_UV3 (3)
#define TEXCOORD_INDEX_PLANAR_XY (4)
#define TEXCOORD_INDEX_PLANAR_YZ (5)
#define TEXCOORD_INDEX_PLANAR_ZX (6)
#define TEXCOORD_INDEX_TRIPLANAR (7)
#define TEXCOORD_INDEX_COUNT (8)
#define SAMPLE_TEXTURE2D_SCALE_BIAS(name) \
SAMPLE_TEXTURE2D(name, sampler##name, (texcoords[name##UV] * name##_ST.xy + name##_ST.zw))
//
// cf with
// LitData.hlsl:GetSurfaceAndBuiltinData()

//
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
{
ApplyDoubleSidedFlipOrMirror(input); // Apply double sided flip on the vertex normal
ApplyDoubleSidedFlipOrMirror(input); // Apply double sided flip on the vertex normal.
// Build the texcoords array.
float3 positionWS = GetAbsolutePositionWS(input.positionWS);
LayerTexCoord layerTexCoord;
ZERO_INITIALIZE(LayerTexCoord, layerTexCoord);
GetLayerTexCoord(input, layerTexCoord);
float2 texcoords[TEXCOORD_INDEX_COUNT];
texcoords[TEXCOORD_INDEX_UV0] = input.texCoord0;
texcoords[TEXCOORD_INDEX_UV1] = input.texCoord1;
texcoords[TEXCOORD_INDEX_UV2] = input.texCoord2;
texcoords[TEXCOORD_INDEX_UV3] = input.texCoord3;
texcoords[TEXCOORD_INDEX_PLANAR_XY] = float2(positionWS.x, positionWS.y);
texcoords[TEXCOORD_INDEX_PLANAR_YZ] = float2(positionWS.y, positionWS.z);
texcoords[TEXCOORD_INDEX_PLANAR_ZX] = float2(positionWS.z, positionWS.x);
texcoords[TEXCOORD_INDEX_TRIPLANAR] = input.texCoord0;
// -------------------------------------------------------------
// Surface Data:

//float3 bentNormalTS;
//float3 bentNormalWS;
//float alpha = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, baseColorMapUv).a * _BaseColor.a;
float alpha = SAMPLE_UVMAPPING_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, layerTexCoord.base).a * _BaseColor.a;
float alpha = SAMPLE_TEXTURE2D_SCALE_BIAS(_BaseColorMap).a * _BaseColor.a;
#ifdef _ALPHATEST_ON
//NEWLITTODO: Once we include those passes in the main StackLit.shader, add handling of CUTOFF_TRANSPARENT_DEPTH_PREPASS and _POSTPASS
// and the related properties (in the .shader) and uniforms (in the StackLitProperties file) _AlphaCutoffPrepass, _AlphaCutoffPostpass

float3 detailNormalTS = float3(0.0, 0.0, 0.0);
float detailMask = 0.0;
//TODO remove the following and use fetching macros that use uvmapping :
//float2 baseColorMapUv = TRANSFORM_TEX(input.texCoord0, _BaseColorMap);
//surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, baseColorMapUv).rgb * _BaseColor.rgb;
surfaceData.baseColor = SAMPLE_UVMAPPING_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, layerTexCoord.base).rgb * _BaseColor.rgb;
surfaceData.baseColor = SAMPLE_TEXTURE2D_SCALE_BIAS(_BaseColorMap).rgb * _BaseColor.rgb;
normalTS = GetNormalTS(input, layerTexCoord, detailNormalTS, detailMask);
normalTS = GetNormalTS(input, texcoords[_NormalMapUV], detailNormalTS, detailMask);
#if defined(_SMOOTHNESSMASKMAPA)
surfaceData.perceptualSmoothnessA = dot(SAMPLE_UVMAPPING_TEXTURE2D(_SmoothnessAMap, sampler_SmoothnessAMap, layerTexCoord.base), _MetallicMapChannel, _SmoothnessAMapChannel);
surfaceData.perceptualSmoothnessA = lerp(_SmoothnessARemap.x, _SmoothnessARemap.y, surfaceData.perceptualSmoothnessA);
#else
surfaceData.perceptualSmoothnessA = _SmoothnessA;
#endif
surfaceData.perceptualSmoothnessA = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_SmoothnessAMap), _SmoothnessAMapChannelMask);
surfaceData.perceptualSmoothnessA = lerp(_SmoothnessARange.x, _SmoothnessARange.y, surfaceData.perceptualSmoothnessA);
surfaceData.metallic = lerp(_SmoothnessA, surfaceData.perceptualSmoothnessA, _SmoothnessAUseMap);
#if defined(_SMOOTHNESSMASKMAPB)
surfaceData.perceptualSmoothnessB = dot(SAMPLE_UVMAPPING_TEXTURE2D(_SmoothnessAMaB, sampler_SmoothnessBMap, layerTexCoord.base), _SmoothnessBMapChannel);
surfaceData.perceptualSmoothnessB = lerp(_SmoothnessBRemap.x, _SmoothnessBRemap.y, surfaceData.perceptualSmoothnessB);
#else
surfaceData.perceptualSmoothnessB = _SmoothnessB;
#endif
surfaceData.perceptualSmoothnessB = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_SmoothnessBMap), _SmoothnessBMapChannelMask);
surfaceData.perceptualSmoothnessB = lerp(_SmoothnessBRange.x, _SmoothnessBRange.y, surfaceData.perceptualSmoothnessB);
surfaceData.metallic = lerp(_SmoothnessB, surfaceData.perceptualSmoothnessB, _SmoothnessBUseMap);
#ifdef _METALLICMAP
surfaceData.metallic = dot(SAMPLE_UVMAPPING_TEXTURE2D(_MetallicMap, sampler_MetallicMap, layerTexCoord.base), _MetallicMapChannel);
#else
surfaceData.metallic = 1.0;
#endif
surfaceData.metallic *= _Metallic;
surfaceData.metallic = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_MetallicMap), _MetallicMapChannelMask);
surfaceData.metallic = lerp(_MetallicRange.x, _MetallicRange.y, surfaceData.metallic);
surfaceData.metallic = lerp(_Metallic, surfaceData.metallic, _MetallicUseMap);
// These static material feature allow compile time optimization
// TODO: As we add features, or-set the flags eg MATERIALFEATUREFLAGS_LIT_* with #ifdef

// -------------------------------------------------------------
GetNormalWS(input, V, normalTS, surfaceData.normalWS); // MaterialUtilities.hlsl
// TODO: decal etc.

surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, layerTexCoord.base.uv, _BaseColorMap, _BaseColorMap_TexelSize, _BaseColorMap_MipInfo, surfaceData.baseColor);
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, texcoords[_BaseColorMapUV], _BaseColorMap, _BaseColorMap_TexelSize, _BaseColorMap_MipInfo, surfaceData.baseColor);
surfaceData.metallic = 0;
}
#endif

// Emissive Intensity is only use here, but is part of BuiltinData to enforce UI parameters as we want the users to fill one color and one intensity
builtinData.emissiveIntensity = _EmissiveIntensity; // We still store intensity here so we can reuse it with debug code
builtinData.emissiveColor = _EmissiveColor * builtinData.emissiveIntensity * lerp(float3(1.0, 1.0, 1.0), surfaceData.baseColor.rgb, _AlbedoAffectEmissive);
#ifdef _EMISSIVE_COLOR_MAP
builtinData.emissiveColor *= SAMPLE_TEXTURE2D(_EmissiveColorMap, sampler_EmissiveColorMap, TRANSFORM_TEX(input.texCoord0, _EmissiveColorMap)).rgb;
#endif
builtinData.emissiveColor *= SAMPLE_TEXTURE2D_SCALE_BIAS(_EmissiveColorMap).rgb;
//NEWLITTODO: shader feature SHADOWS_SHADOWMASK not there yet.
builtinData.shadowMask0 = 0.0;

#endif
builtinData.depthOffset = 0.0;
}

58
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLitProperties.hlsl


TEXTURE2D(_SmoothnessBMap);
SAMPLER(sampler_SmoothnessBMap);
TEXTURE2D(_SubsurfaceMaskMap);
SAMPLER(sampler_SubsurfaceMaskMap);
TEXTURE2D(_ThicknessMap);
SAMPLER(sampler_ThicknessMap);
TEXTURE2D(_EmissiveColorMap);
SAMPLER(sampler_EmissiveColorMap);

float _BaseColorMapUV;
float _Metallic;
float _MetallicUseMap;
float4 _MetallicMapChannel;
float4 _MetallicMap_ST;
float4 _MetallicMap_TexelSize;
float4 _MetallicMap_MipInfo;
float4 _MetallicMapChannelMask;
float4 _MetallicRange;
float _SmoothnessAUseMap;
float4 _SmoothnessAMapChannel;
float4 _SmoothnessARemap;
float4 _SmoothnessAMap_ST;
float4 _SmoothnessAMap_TexelSize;
float4 _SmoothnessAMap_MipInfo;
float4 _SmoothnessAMapChannelMask;
float4 _SmoothnessARange;
float _SmoothnessBUV;
float4 _SmoothnessBMapChannel;
float4 _SmoothnessBRemap;
float _SmoothnessBUseMap;
float _SmoothnessBMapUV;
float4 _SmoothnessBMap_ST;
float4 _SmoothnessBMap_TexelSize;
float4 _SmoothnessBMap_MipInfo;
float4 _SmoothnessBMapChannelMask;
float4 _SmoothnessBRange;
float4 _UVMappingMask;
float4 _NormalMap_ST;
float4 _NormalMap_TexelSize;
float4 _NormalMap_MipInfo;
float4 _EmissiveColorMap_TexelSize;
float4 _EmissiveColorMap_MipInfo;
float _EmissiveColorMapUV;
float _SubsurfaceMask;
float _SubsurfaceMaskUseMap;
float _SubsurfaceMaskMapUV;
float4 _SubsurfaceMaskMap_ST;
float4 _SubsurfaceMaskMap_TexelSize;
float4 _SubsurfaceMaskMap_MipInfo;
float4 _SubsurfaceMaskMapChannelMask;
float4 _SubsurfaceMaskRange;
float _Thickness;
float _ThicknessUseMap;
float _ThicknessMapUV;
float4 _ThicknessMap_ST;
float4 _ThicknessMap_TexelSize;
float4 _ThicknessMap_MipInfo;
float4 _ThicknessMapChannelMask;
float4 _ThicknessRange;
float _AlphaCutoff;
float4 _DoubleSidedConstants;

正在加载...
取消
保存