浏览代码

StackLit: New base parametrization and dual lobe hazy gloss parametrization.

-SpecularColor mode now selectable
-Dual specular lobe has two parametrization: direct and hazy gloss (Barla et al. 2018-07)
-UI changes to support multiple parametrizations and also avoid useless keyword switching in some instances
-Additional note on specular occlusion and anisotropy
/StackLit2
Stephane Laroche 6 年前
当前提交
12aebb34
共有 9 个文件被更改,包括 590 次插入107 次删除
  1. 15
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/CommonMaterial.hlsl
  2. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs
  3. 234
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitUI.cs
  4. 62
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.cs
  5. 69
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.cs.hlsl
  6. 141
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl
  7. 53
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader
  8. 60
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitData.hlsl
  9. 52
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitProperties.hlsl

15
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/CommonMaterial.hlsl


roughnessB = roughness * (1 - anisotropy);
}
void ConvertRoughnessTAndAnisotropyToRoughness(real roughnessT, real anisotropy, out real roughness)
{
roughness = roughnessT / (1 + anisotropy);
}
void ConvertValueAnisotropyToValueTB(real value, real anisotropy, out real valueT, out real valueB)
{
// Use the parametrization of Sony Imageworks.
// Ref: Revisiting Physically Based Shading at Imageworks, p. 15.
valueT = value * (1 + anisotropy);
valueB = value * (1 - anisotropy);
}
anisotropy = ((roughnessT - roughnessB) / (roughnessT + roughnessB + 0.0001));
anisotropy = ((roughnessT - roughnessB) / max(roughnessT + roughnessB, 0.0001));
}
// Same as ConvertAnisotropyToRoughness but

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs


public Property m_ConstantProperty;
public Property m_RangeScaleProperty;
public TextureOneLineProperty m_TextureProperty;
public ComboProperty m_UvSetProperty;

m_ConstantProperty = new Property(parent, constantPropertyName, guiText, toolTip, isMandatory);
}
m_RangeScaleProperty = new Property(parent, propertyName + "RangeScale", "Range Multiplier", false);
m_TextureProperty = new TextureOneLineProperty(parent, propertyName, pairConstantWithTexture ? constantPropertyName : string.Empty, guiText, toolTip, isMandatory);
m_UvSetProperty = new ComboProperty(parent, propertyName + "UV", "UV Mapping", Enum.GetNames(typeof(UVMapping)), false);

{
m_ConstantProperty.OnFindProperty(props);
}
m_RangeScaleProperty.OnFindProperty(props);
m_TextureProperty.OnFindProperty(props);
m_UvSetProperty.OnFindProperty(props);
m_LocalOrWorldProperty.OnFindProperty(props);

if (m_Show.BoolValue)
{
EditorGUI.indentLevel++;
if (m_RangeScaleProperty.IsValid)
{
m_RangeScaleProperty.OnGUI();
}
if (m_ConstantProperty != null && m_ConstantProperty.IsValid
&& m_TextureProperty.TextureValue == null)
{

234
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitUI.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;

protected const string k_BaseColor = "_BaseColor";
protected const string k_BaseColorMap = "_BaseColorMap";
protected const string k_BaseColorMapUV = "_BaseColorMapUV";
protected const string k_SpecularColor = "_SpecularColor";
protected const string k_SpecularColorMap = "_SpecularColorMap";
protected const string k_SpecularColorMapUV = "_SpecularColorMapUV";
protected const string k_EnergyConservingSpecularColor = "_EnergyConservingSpecularColor";
protected const string k_BaseParametrization = "_BaseParametrization";
protected const string k_Metallic = "_Metallic";
protected const string k_MetallicMap = "_MetallicMap";

protected const string k_ThicknessMapUV = "_ThicknessMapUV";
// Second Lobe.
protected const string k_DualSpecularLobeParametrization = "_DualSpecularLobeParametrization";
protected const string k_EnableDualSpecularLobe = "_EnableDualSpecularLobe";
protected const string k_SmoothnessB = "_SmoothnessB";
protected const string k_SmoothnessBMap = "_SmoothnessBMap";

protected const string k_LobeMixMap = "_LobeMixMap";
protected const string k_LobeMixMapUV = "_LobeMixMapUV";
protected const string k_Haziness = "_Haziness";
protected const string k_HazinessMap = "_HazinessMap";
protected const string k_HazinessMapUV = "_HazinessMapUV";
protected const string k_HazeExtent = "_HazeExtent";
protected const string k_HazeExtentMap = "_HazeExtentMap";
protected const string k_HazeExtentMapUV = "_HazeExtentMapUV";
protected const string k_CapHazinessWrtMetallic = "_CapHazinessWrtMetallic";
// Anisotropy
protected const string k_EnableAnisotropy = "_EnableAnisotropy";

private Property EnableGeometricNormalFiltering;
private Property EnableTextureNormalFiltering;
private ComboProperty BaseParametrization;
private ComboProperty DualSpecularLobeParametrization;
private bool IsMetallicParametrizationUsed
{
get { return (!BaseParametrization.IsValid) || ((StackLit.BaseParametrization)BaseParametrization.FloatValue == StackLit.BaseParametrization.BaseMetallic); }
}
private bool IsHazyGlossParametrizationUsed
{
get { return DualSpecularLobeParametrization.IsValid && ((StackLit.DualSpecularLobeParametrization)DualSpecularLobeParametrization.FloatValue == StackLit.DualSpecularLobeParametrization.HazyGloss); }
}
public StackLitGUI()
{
_baseMaterialProperties = new GroupProperty(this, "_BaseMaterial", new BaseProperty[]

EnableGeometricNormalFiltering = new Property(this, k_GeometricNormalFilteringEnabled, "Enable Geometric filtering", "Enable specular antialiasing", true);
EnableTextureNormalFiltering = new Property(this, k_TextureNormalFilteringEnabled, "Enable Texture filtering", "Require normal map to use _NA or _OSNA suffix for normal map name", true);
// This property appears after one which references it:
var BentNormal = new TextureProperty(this, k_BentNormalMap, "", "Bent Normal Map", "Bent Normal Map", pairConstantWithTexture: true, isMandatory: false, isNormalMap: true, showScaleOffset: false);
// --------------------------------------------------------------------------
// Variable display configuration sections (depend on actual property values)
// --------------------------------------------------------------------------
// Base parametrization
BaseParametrization = new ComboProperty(this, k_BaseParametrization, "Base Parametrization", Enum.GetNames(typeof(StackLit.BaseParametrization)), false);
var BaseColor = new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Base Color + Opacity", "Albedo (RGB) and Opacity (A)", true, false);
var Metallic = new TextureProperty(this, k_MetallicMap, k_Metallic, "Metallic", "Metallic", false, false);
var DielectricIor = new Property(this, k_DielectricIor, "DieletricIor", "IOR use for dielectric material (i.e non metallic material)", false);
var SmoothnessA = new TextureProperty(this, k_SmoothnessAMap, k_SmoothnessA, "Smoothness", "Smoothness", false, false);
var NormalMap = new TextureProperty(this, k_NormalMap, k_NormalScale, "Normal Map", "Normal Map", pairConstantWithTexture: true, isMandatory: false, isNormalMap: true, showScaleOffset: true, slaveTexOneLineProp: BentNormal.m_TextureProperty);
var AmbientOcclusion = new TextureProperty(this, k_AmbientOcclusionMap, k_AmbientOcclusion, "AmbientOcclusion", "AmbientOcclusion Map", false, false);
var SpecularColor = new TextureProperty(this, k_SpecularColorMap, k_SpecularColor, "Specular Color (f0)", "Specular Color (f0) (RGB)", true, false);
var EnergyConservingSpecularColor = new Property(this, k_EnergyConservingSpecularColor, "Energy Conserving Specular Color", "Mimics legacy Unity and Lit shader to balance diffuse and specular color", false);
var StandardMetallicGroup = new GroupProperty(this, "_Standard", "Standard Basecolor and Metallic", new BaseProperty[]
{
BaseParametrization,
BaseColor,
Metallic,
DielectricIor,
SmoothnessA,
NormalMap,
BentNormal,
AmbientOcclusion,
}, _ => (IsMetallicParametrizationUsed));
// We keep the name "_Standard" so that the same UI-used foldout property "_StandardShow" is used
var StandardSpecularColorGroup = new GroupProperty(this, "_Standard", "Standard Diffuse and Specular Color", new BaseProperty[]
{
BaseParametrization,
BaseColor,
SpecularColor,
EnergyConservingSpecularColor,
SmoothnessA,
NormalMap,
BentNormal,
AmbientOcclusion,
}, _ => (!IsMetallicParametrizationUsed));
// Dual specular lobe parametrizations:
DualSpecularLobeParametrization = new ComboProperty(this, k_DualSpecularLobeParametrization, "Dual Specular Lobe Parametrization", Enum.GetNames(typeof(StackLit.DualSpecularLobeParametrization)), false);
var SmoothnessB = new TextureProperty(this, k_SmoothnessBMap, k_SmoothnessB, "Smoothness B", "Smoothness B", false, false);
//var LobeMix = new Property(this, k_LobeMix, "Lobe Mix", "Lobe Mix", false);
var LobeMix = new TextureProperty(this, k_LobeMixMap, k_LobeMix, "LobeMix", "LobeMix", false, false);
var Haziness = new TextureProperty(this, k_HazinessMap, k_Haziness, "Haziness", "Haziness", false, false);
var HazeExtent = new TextureProperty(this, k_HazeExtentMap, k_HazeExtent, "Haze Extent", "Haze Extent", false, false);
var CapHazinessWrtMetallic = new Property(this, k_CapHazinessWrtMetallic, "Cap Haziness Wrt Metallic", "Cap Haziness To Agree With Metallic", false,
_ => (IsMetallicParametrizationUsed));
var DualSpecularLobeDirectGroup = new GroupProperty(this, "_DualSpecularLobe", "Dual Specular Lobe (Direct Control Mode)", new BaseProperty[]
{
DualSpecularLobeParametrization,
SmoothnessB,
LobeMix,
}, _ => ( EnableDualSpecularLobe.BoolValue == true && !IsHazyGlossParametrizationUsed) );
var DualSpecularLobeHazyGlossGroup = new GroupProperty(this, "_DualSpecularLobe", "Dual Specular Lobe (Hazy Gloss Mode)", new BaseProperty[]
{
DualSpecularLobeParametrization,
Haziness,
CapHazinessWrtMetallic,
HazeExtent,
}, _ => (EnableDualSpecularLobe.BoolValue == true && IsHazyGlossParametrizationUsed) );
var BentNormalTexProp = new TextureProperty(this, k_BentNormalMap, "", "Bent Normal Map", "Bent Normal Map", pairConstantWithTexture: true, isMandatory: false, isNormalMap: true, showScaleOffset: false);
_materialProperties = new GroupProperty(this, "_Material", new BaseProperty[]
{

EnableTransmission
}),
new GroupProperty(this, "_Standard", "Standard", new BaseProperty[]
{
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 Property(this, k_DielectricIor, "DieletricIor", "IOR use for dielectric material (i.e non metallic material)", false),
new TextureProperty(this, k_SmoothnessAMap, k_SmoothnessA, "Smoothness", "Smoothness", false, false),
new TextureProperty(this, k_NormalMap, k_NormalScale, "Normal Map", "Normal Map", pairConstantWithTexture:true, isMandatory:false, isNormalMap:true, showScaleOffset:true, slaveTexOneLineProp:BentNormalTexProp.m_TextureProperty),
BentNormalTexProp,
//new TextureProperty(this, k_BentNormalMap, "", "Bent Normal Map", "Bent Normal Map", pairConstantWithTexture:true, isMandatory:false, isNormalMap:true, showScaleOffset:false),
new TextureProperty(this, k_AmbientOcclusionMap, k_AmbientOcclusion, "AmbientOcclusion", "AmbientOcclusion Map", false, false),
}),
StandardMetallicGroup,
StandardSpecularColorGroup,
new GroupProperty(this, "_Details", "Details", new BaseProperty[]
{

}, _ => EnableDetails.BoolValue == true),
new GroupProperty(this, "_DualSpecularLobe", "Dual Specular Lobe", new BaseProperty[]
{
new TextureProperty(this, k_SmoothnessBMap, k_SmoothnessB, "Smoothness B", "Smoothness B", false, false),
new Property(this, k_LobeMix, "Lobe Mix", "Lobe Mix", false),
}, _ => EnableDualSpecularLobe.BoolValue == true),
DualSpecularLobeDirectGroup,
DualSpecularLobeHazyGlossGroup,
new GroupProperty(this, "_Anisotropy", "Anisotropy", new BaseProperty[]
{

SetupTextureMaterialProperty(material, k_Metallic);
SetupTextureMaterialProperty(material, k_SmoothnessA);
SetupTextureMaterialProperty(material, k_SmoothnessB);
SetupTextureMaterialProperty(material, k_LobeMix);
SetupTextureMaterialProperty(material, k_Haziness);
SetupTextureMaterialProperty(material, k_HazeExtent);
SetupTextureMaterialProperty(material, k_AmbientOcclusion);
SetupTextureMaterialProperty(material, k_SubsurfaceMask);
SetupTextureMaterialProperty(material, k_Thickness);

SetupTextureMaterialProperty(material, k_DetailMask);
SetupTextureMaterialProperty(material, k_DetailSmoothness);
// 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_SmoothnessAMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_SmoothnessBMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_AmbientOcclusionMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_EmissiveColorMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_SubsurfaceMaskMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_ThicknessMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_AnisotropyMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_IridescenceThicknessMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_IridescenceMaskMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_CoatSmoothnessMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_CoatNormalMapUV),
// Details
(TextureProperty.UVMapping)material.GetFloat(k_DetailMaskMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_DetailSmoothnessMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_DetailNormalMapUV),
};
// Set keyword for mapping
//bool requireUv2 = false;
//bool requireUv3 = false;
bool requireTriplanar = false;
for (int i = 0; i < uvIndices.Length; ++i)
{
//requireUv2 = requireUv2 || uvIndices[i] == TextureProperty.UVMapping.UV2;
//requireUv3 = requireUv3 || uvIndices[i] == TextureProperty.UVMapping.UV3;
requireTriplanar = requireTriplanar || uvIndices[i] == TextureProperty.UVMapping.Triplanar;
}
CoreUtils.SetKeyword(material, "_MAPPING_TRIPLANAR", requireTriplanar);
bool detailsEnabled = material.HasProperty(k_EnableDetails) && material.GetFloat(k_EnableDetails) > 0.0f;
CoreUtils.SetKeyword(material, "_DETAILMAP", detailsEnabled);

bool specularOcclusionEnabled = material.HasProperty(k_EnableSpecularOcclusion) && material.GetFloat(k_EnableSpecularOcclusion) > 0.0f;
CoreUtils.SetKeyword(material, "_ENABLESPECULAROCCLUSION", specularOcclusionEnabled);
bool specularColorEnabled = material.HasProperty(k_BaseParametrization)
&& ((StackLit.BaseParametrization)material.GetFloat(k_BaseParametrization) == StackLit.BaseParametrization.SpecularColor);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SPECULAR_COLOR", specularColorEnabled);
bool hazyGlossEnabled = dualSpecularLobeEnabled && material.HasProperty(k_DualSpecularLobeParametrization)
&& ((StackLit.DualSpecularLobeParametrization)material.GetFloat(k_DualSpecularLobeParametrization) == StackLit.DualSpecularLobeParametrization.HazyGloss);
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_HAZY_GLOSS", hazyGlossEnabled);
bool anisotropyEnabled = material.HasProperty(k_EnableAnisotropy) && material.GetFloat(k_EnableAnisotropy) > 0.0f;
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_ANISOTROPY", anisotropyEnabled);

bool coatEnabled = material.HasProperty(k_EnableCoat) && material.GetFloat(k_EnableCoat) > 0.0f;
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_COAT", coatEnabled);
bool coatNormalMapEnabled = material.HasProperty(k_EnableCoatNormalMap) && material.GetFloat(k_EnableCoatNormalMap) > 0.0f;
bool coatNormalMapEnabled = coatEnabled && material.HasProperty(k_EnableCoatNormalMap) && material.GetFloat(k_EnableCoatNormalMap) > 0.0f;
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_COAT_NORMALMAP", coatNormalMapEnabled);
// TEMP - Remove once dev is finish

bool vlayerRecomputePerLight = material.HasProperty("_VlayerRecomputePerLight") && material.GetFloat("_VlayerRecomputePerLight") > 0.0f;
bool vlayerRecomputePerLight = (coatEnabled || iridescenceEnabled) && material.HasProperty("_VlayerRecomputePerLight") && material.GetFloat("_VlayerRecomputePerLight") > 0.0f;
bool vlayerUseRefractedAnglesForBase = material.HasProperty("_VlayerUseRefractedAnglesForBase") && material.GetFloat("_VlayerUseRefractedAnglesForBase") > 0.0f;
bool vlayerUseRefractedAnglesForBase = coatEnabled && material.HasProperty("_VlayerUseRefractedAnglesForBase") && material.GetFloat("_VlayerUseRefractedAnglesForBase") > 0.0f;
//
// Check if we are using specific UVs (but only for potentially used maps):
//
TextureProperty.UVMapping metallicMapUV = specularColorEnabled ? TextureProperty.UVMapping.UV0 : (TextureProperty.UVMapping)material.GetFloat(k_MetallicMapUV);
TextureProperty.UVMapping specularColorMapUV = specularColorEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_SpecularColorMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping smoothnessBMapUV = (dualSpecularLobeEnabled && !hazyGlossEnabled) ? (TextureProperty.UVMapping)material.GetFloat(k_SmoothnessBMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping lobeMixMapUV = (dualSpecularLobeEnabled && !hazyGlossEnabled) ? (TextureProperty.UVMapping)material.GetFloat(k_LobeMixMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping hazinessMapUV = (dualSpecularLobeEnabled && hazyGlossEnabled) ? (TextureProperty.UVMapping)material.GetFloat(k_HazinessMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping hazeExtentMapUV = (dualSpecularLobeEnabled && hazyGlossEnabled) ? (TextureProperty.UVMapping)material.GetFloat(k_HazeExtentMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping subsurfaceMaskMapUV = sssEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_SubsurfaceMaskMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping thicknessMapUV = sssEnabled || transmissionEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_ThicknessMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping anisotropyMapUV = anisotropyEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_AnisotropyMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping iridescenceThicknessMapUV = iridescenceEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_IridescenceThicknessMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping iridescenceMaskMapUV = iridescenceEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_IridescenceMaskMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping coatSmoothnessMapUV = coatEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_CoatSmoothnessMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping coatNormalMapUV = coatEnabled && coatNormalMapEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_CoatNormalMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping detailMaskMapUV = detailsEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_DetailMaskMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping detailSmoothnessMapUV = detailsEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_DetailSmoothnessMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping detailNormalMapUV = detailsEnabled ? (TextureProperty.UVMapping)material.GetFloat(k_DetailNormalMapUV) : TextureProperty.UVMapping.UV0;
TextureProperty.UVMapping[] uvIndices = new[]
{
metallicMapUV,
specularColorMapUV,
smoothnessBMapUV,
lobeMixMapUV,
hazinessMapUV,
hazeExtentMapUV,
subsurfaceMaskMapUV,
thicknessMapUV,
anisotropyMapUV,
iridescenceThicknessMapUV,
iridescenceMaskMapUV,
coatSmoothnessMapUV,
coatNormalMapUV,
detailMaskMapUV,
detailSmoothnessMapUV,
detailNormalMapUV,
(TextureProperty.UVMapping)material.GetFloat(k_BaseColorMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_NormalMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_SmoothnessAMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_AmbientOcclusionMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_EmissiveColorMapUV),
};
// Set keyword for mapping
//bool requireUv2 = false;
//bool requireUv3 = false;
bool requireTriplanar = false;
for (int i = 0; i < uvIndices.Length; ++i)
{
//requireUv2 = requireUv2 || uvIndices[i] == TextureProperty.UVMapping.UV2;
//requireUv3 = requireUv3 || uvIndices[i] == TextureProperty.UVMapping.UV3;
requireTriplanar = requireTriplanar || uvIndices[i] == TextureProperty.UVMapping.Triplanar;
}
CoreUtils.SetKeyword(material, "_MAPPING_TRIPLANAR", requireTriplanar);
// Set the reference value for the stencil test - required for SSS
int stencilRef = (int)StencilLightingUsage.RegularLighting;

62
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.cs


StackLitSubsurfaceScattering = 1 << 5,
StackLitTransmission = 1 << 6,
StackLitCoatNormalMap = 1 << 7,
StackLitSpecularColor = 1 << 8,
StackLitHazyGloss = 1 << 9,
};
// We will use keywords no need for [GenerateHLSL] as we don't test in HLSL such a value
public enum BaseParametrization
{
BaseMetallic = 0,
SpecularColor = 1, // MaterialFeatureFlags.StackLitSpecularColor
};
// We will use keywords no need for [GenerateHLSL] as we don't test in HLSL such a value
public enum DualSpecularLobeParametrization
{
Direct = 0,
HazyGloss = 1, // MaterialFeatureFlags.StackLitHazyGloss
// Pascal Barla, Romain Pacanowski, Peter Vangorp. A Composite BRDF Model for Hazy Gloss.
// Computer Graphics Forum, Wiley, 2018, 37, <10.1111/cgf.13475>. <hal-01818666v2>
// https://hal.inria.fr/hal-01818666v2
// Submitted on 6 Jul 2018
};
//-----------------------------------------------------------------------------

[SurfaceDataAttributes("IOR")]
public float dielectricIor;
[SurfaceDataAttributes("Specular Color", false, true)]
public Vector3 specularColor;
[SurfaceDataAttributes(new string[] {"Normal", "Normal View Space"}, true)]
public Vector3 normalWS;

[SurfaceDataAttributes("Smoothness A")]
public float perceptualSmoothnessA;
// Dual specular lobe
// Dual specular lobe: Direct parametrization (engine parameters)
[SurfaceDataAttributes("Smoothness B")]
public float perceptualSmoothnessB;

// Anisotropic
// Dual specular lobe: DualSpecularLobeParametrization == HazyGloss parametrization.
//
// Lobe B is the haze.
//
// In that mode, perceptual parameters of "haziness" and "hazeExtent" are used.
// The base layer f0 parameter when the DualSpecularLobeParametrization was == "Direct"
// is now also a perceptual parameter corresponding to a pseudo-f0 term, Fc(0) or
// "coreFresnel0" (r_c in the paper). Although an intermediate value, this original
// fresnel0 never reach the engine side (BSDFData).
//
// [ Without the HazyGloss parametrization, the original base layer f0 is directly inferred
// as f0 = f(baseColor, metallic) when the BaseParametrization is BaseMetallic
// or directly given via f0 = SpecularColor when the BaseParametrization == SpecularColor.
//
// When the DualSpecularLobeParametrization is "HazyGloss", this base layer f0 is
// now reinterpreted as the perceptual "core lobe reflectivity" or Fc(0) or r_c in
// the paper.]
//
// From these perceptual parameters, the engine-used lobeMix, fresnel0 (SpecularColor)
// and SmoothnessB parameters are set.
//
// [ TODO: We could actually scrap metallic and dielectricIor here and update specularColor
// to always hold the f0 intermediate value (r_c), although you could then go further and
// put the final "engine input" f0 in there, and other perceptuals like haziness and
// hazeExtent and update directly lobeMix here. For now we keep the shader mostly organized
// like Lit ]
[SurfaceDataAttributes("Haziness")]
public float haziness;
[SurfaceDataAttributes("Haze Extent")]
public float hazeExtent;
[SurfaceDataAttributes("Cap Haziness To Agree With Metallic")]
public bool capHazinessWrtMetallic;
// Anisotropy
[SurfaceDataAttributes("Tangent", true)]
public Vector3 tangentWS;

69
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.cs.hlsl


#define MATERIALFEATUREFLAGS_STACK_LIT_SUBSURFACE_SCATTERING (32)
#define MATERIALFEATUREFLAGS_STACK_LIT_TRANSMISSION (64)
#define MATERIALFEATUREFLAGS_STACK_LIT_COAT_NORMAL_MAP (128)
#define MATERIALFEATUREFLAGS_STACK_LIT_SPECULAR_COLOR (256)
#define MATERIALFEATUREFLAGS_STACK_LIT_HAZY_GLOSS (512)
//
// UnityEngine.Experimental.Rendering.HDPipeline.StackLit+SurfaceData: static fields

#define DEBUGVIEW_STACKLIT_SURFACEDATA_AMBIENT_OCCLUSION (1102)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_METALLIC (1103)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IOR (1104)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_NORMAL (1105)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_NORMAL_VIEW_SPACE (1106)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_GEOMETRIC_NORMAL (1107)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_GEOMETRIC_NORMAL_VIEW_SPACE (1108)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_NORMAL (1109)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_NORMAL_VIEW_SPACE (1110)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_BENT_NORMAL (1111)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_BENT_NORMAL_VIEW_SPACE (1112)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_SMOOTHNESS_A (1113)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_SMOOTHNESS_B (1114)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_LOBE_MIXING (1115)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_TANGENT (1116)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_ANISOTROPY (1117)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_IOR (1118)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_THICKNESS (1119)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_MASK (1120)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_SMOOTHNESS (1121)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_IOR (1122)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_THICKNESS (1123)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_EXTINCTION_COEFFICIENT (1124)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_DIFFUSION_PROFILE (1125)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_SUBSURFACE_MASK (1126)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_THICKNESS (1127)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_SPECULAR_COLOR (1105)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_NORMAL (1106)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_NORMAL_VIEW_SPACE (1107)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_GEOMETRIC_NORMAL (1108)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_GEOMETRIC_NORMAL_VIEW_SPACE (1109)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_NORMAL (1110)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_NORMAL_VIEW_SPACE (1111)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_BENT_NORMAL (1112)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_BENT_NORMAL_VIEW_SPACE (1113)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_SMOOTHNESS_A (1114)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_SMOOTHNESS_B (1115)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_LOBE_MIXING (1116)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_HAZINESS (1117)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_HAZE_EXTENT (1118)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_CAP_HAZINESS_TO_AGREE_WITH_METALLIC (1119)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_TANGENT (1120)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_ANISOTROPY (1121)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_IOR (1122)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_THICKNESS (1123)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_MASK (1124)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_SMOOTHNESS (1125)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_IOR (1126)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_THICKNESS (1127)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_EXTINCTION_COEFFICIENT (1128)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_DIFFUSION_PROFILE (1129)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_SUBSURFACE_MASK (1130)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_THICKNESS (1131)
//
// UnityEngine.Experimental.Rendering.HDPipeline.StackLit+BSDFData: static fields

float ambientOcclusion;
float metallic;
float dielectricIor;
float3 specularColor;
float3 normalWS;
float3 geomNormalWS;
float3 coatNormalWS;

float lobeMix;
float haziness;
float hazeExtent;
bool capHazinessWrtMetallic;
float3 tangentWS;
float anisotropy;
float iridescenceIor;

case DEBUGVIEW_STACKLIT_SURFACEDATA_IOR:
result = surfacedata.dielectricIor.xxx;
break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_SPECULAR_COLOR:
result = surfacedata.specularColor;
needLinearToSRGB = true;
break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_NORMAL:
result = surfacedata.normalWS * 0.5 + 0.5;
break;

break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_LOBE_MIXING:
result = surfacedata.lobeMix.xxx;
break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_HAZINESS:
result = surfacedata.haziness.xxx;
break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_HAZE_EXTENT:
result = surfacedata.hazeExtent.xxx;
break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_CAP_HAZINESS_TO_AGREE_WITH_METALLIC:
result = (surfacedata.capHazinessWrtMetallic) ? float3(1.0, 1.0, 1.0) : float3(0.0, 0.0, 0.0);
break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_TANGENT:
result = surfacedata.tangentWS * 0.5 + 0.5;

141
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl


#endif
#define VLAYERED_DIFFUSE_ENERGY_HACKED_TERM
//#define VLAYERED_ANISOTROPY_IBL_DESTRETCH
//#define VLAYERED_ANISOTROPY_IBL_DESTRETCH
#define VLAYERED_ANISOTROPY_SCALAR_ROUGHNESS
#define VLAYERED_ANISOTROPY_SCALAR_ROUGHNESS_CORRECTANISO

}
//-----------------------------------------------------------------------------
// Conversion function for hazy gloss parametrization
//-----------------------------------------------------------------------------
//
// Outputs:
// bsdfData.fresnel0
// bsdfData.lobeMix
// bsdfData.perceptualRoughnessB
// bsdfData.roughnessBT
// bsdfData.roughnessBB
//
// TODOTODO: capHazinessWrtMetallic and secondary anisotropy
//
void HazeMapping(float3 fresnel0, float roughnessAT, float roughnessAB, float haziness, float hazeExtent, float hazeExtentAnisotropy /* TODOTODO */, inout BSDFData bsdfData)
{
float w = 10.0; // interpolation steepness weight (Bezier weight of central point)
bool useBezierToMapKh = true;
float3 r_c = fresnel0;
float2 alpha_n = float2(roughnessAT, roughnessAB);
float alpha_n_xy = alpha_n.x * alpha_n.y;
float beta_h = haziness;
float2 lambda_h; // hazeExtent anisotropic
//ConvertValueAnisotropyToValueTB(hazeExtent, hazeExtentAnisotropy, lambda_h.x, lambda_h.y);
ConvertValueAnisotropyToValueTB(hazeExtent, 0.0, lambda_h.x, lambda_h.y);
float2 alpha_w = saturate(alpha_n + lambda_h * sqrt(alpha_n_xy)); // wide lobe (haze) roughness
// We saturate here as hazeExtent is scaled arbitrarily (Ideally, a max scale depends on the
// maximum core roughness and since this primary roughness (of lobe A) can be textured, we
// don't know it).
float p = alpha_n_xy/(alpha_w.x * alpha_w.y); // peak ratio formula at theta_d = 0 (ie p is in the paper := P(0))
float r_c_max = Max3(r_c.r, r_c.g, r_c.b);
float k_h_max = 0.0;
if (r_c_max <= FLT_EPS)
{
bsdfData.lobeMix = 0.0;
}
else
{
if (useBezierToMapKh)
{
// Smooth out C1 discontinuity at k_h = p with a Bezier curve
// (loose some hazeExtent in the process).
float b = 2*(r_c_max*(1-w)+w*p);
float u; // parametric coordinate for rational Bezier curve
if (abs(2*(b-1)) <= FLT_EPS)
{
// use Taylor expansion around singularity
u = (2*w*p-1- (4*Sq(w)*Sq(p)-4*Sq(w)*p+1)*(r_c_max-(0.5-w*p)/(1-w)) ) / (2*(w-1));
}
else
{
float D = Sq(b) - 4*(b-1)*r_c_max;
u = (b-sqrt(D)) / (2*(b-1));
}
k_h_max = (2*(1-u)*u*w*beta_h)/(Sq(1-u)+2*(1-u)*u*w+Sq(u)); // rational Bezier curve
}
else
{
// Interpolation between 0 and positivity and energy constraints: these are lines
// but form a triangle so there's a discontinuity at k_h := K_h(0) = p, hence the
// branch here:
k_h_max = (r_c_max > p) ? beta_h*(1-r_c_max)/(1-p) : beta_h*r_c_max/p;
}
float r_max = r_c_max + (1-p)*k_h_max; // compound reflectivity (max color channel)
float3 chromaVec = r_c/r_c_max;
bsdfData.fresnel0 = r_max*chromaVec;
bsdfData.lobeMix = k_h_max / r_max;
//bsdfData.lobeMix = 0.5;
float anisotropyB; // TODOTODO
float roughnessB;
ConvertRoughnessToAnisotropy(alpha_w.x, alpha_w.y, anisotropyB);
ConvertRoughnessTAndAnisotropyToRoughness(alpha_w.x, anisotropyB, roughnessB);
bsdfData.perceptualRoughnessB = RoughnessToPerceptualRoughness(roughnessB);
bsdfData.roughnessBT = alpha_w.x;
bsdfData.roughnessBB = alpha_w.y;
}
}
//-----------------------------------------------------------------------------
// conversion function for forward
//-----------------------------------------------------------------------------

bsdfData.perceptualRoughnessA = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothnessA);
bsdfData.perceptualRoughnessB = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothnessB);
bsdfData.lobeMix = surfaceData.lobeMix;
// There is no metallic with SSS and specular color mode
float metallic = HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_STACK_LIT_TRANSMISSION) ? 0.0 : surfaceData.metallic;
// We set metallic to 0 with SSS and specular color mode
float metallic = HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_SPECULAR_COLOR | MATERIALFEATUREFLAGS_STACK_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_STACK_LIT_TRANSMISSION) ? 0.0 : surfaceData.metallic;
bsdfData.fresnel0 = ComputeFresnel0(surfaceData.baseColor, surfaceData.metallic, IorToFresnel0(surfaceData.dielectricIor));
bsdfData.fresnel0 = HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_SPECULAR_COLOR) ? surfaceData.specularColor : ComputeFresnel0(surfaceData.baseColor, surfaceData.metallic, IorToFresnel0(surfaceData.dielectricIor));
// Kind of obsolete without gbuffer, ie could use _MATERIAL_FEATURE* shader_features directly, but
// if anything, makes the code more readable.
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_SUBSURFACE_SCATTERING))
{
// Assign profile id and overwrite fresnel0

FillMaterialAnisotropy(surfaceData.anisotropy, surfaceData.tangentWS, cross(surfaceData.normalWS, surfaceData.tangentWS), bsdfData);
}
// Extract T & B anisotropies
ConvertAnisotropyToRoughness(bsdfData.perceptualRoughnessA, bsdfData.anisotropy, bsdfData.roughnessAT, bsdfData.roughnessAB);
ConvertAnisotropyToRoughness(bsdfData.perceptualRoughnessB, bsdfData.anisotropy, bsdfData.roughnessBT, bsdfData.roughnessBB);
bsdfData.lobeMix = surfaceData.lobeMix;
// Note that if we're using the hazy gloss parametrization, these will all be changed again:
// fresnel0, lobeMix, perceptualRoughnessB, roughnessBT, roughnessBB.
//
// The fresnel0 is the only one used and needed in that case but it's ok, since materialFeatures are
// statically known, the compiler will prune the useless computations for the rest of the terms above
// when MATERIALFEATUREFLAGS_STACK_LIT_HAZY_GLOSS is set.
//
// It is important to deal with the hazy gloss parametrization after we have fresnel0 for the base but
// before the effect of the coat is applied on it. When hazy gloss is used, the current fresnel0 at this
// point is reinterpreted as a pseudo-f0 ("core lobe reflectivity" or Fc(0) or r_c in the paper)
//
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_HAZY_GLOSS))
{
HazeMapping(bsdfData.fresnel0, bsdfData.roughnessAT, bsdfData.roughnessAB, surfaceData.haziness, surfaceData.hazeExtent, bsdfData.anisotropy /* TODOTODO */, bsdfData);
}
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_IRIDESCENCE))
{
FillMaterialIridescence(surfaceData.iridescenceMask, surfaceData.iridescenceThickness, surfaceData.iridescenceIor, bsdfData);

// We have a coat top layer: change the base fresnel0 accordingdly:
bsdfData.fresnel0 = ConvertF0ForAirInterfaceToF0ForNewTopIor(bsdfData.fresnel0, bsdfData.coatIor);
// Dont clamp the roughnesses for now, ComputeAdding() will use those directly:
// We dont clamp the roughnesses for now, ComputeAdding() will use those directly, unclamped.
ConvertAnisotropyToRoughness(bsdfData.perceptualRoughnessA, bsdfData.anisotropy, bsdfData.roughnessAT, bsdfData.roughnessAB);
ConvertAnisotropyToRoughness(bsdfData.perceptualRoughnessB, bsdfData.anisotropy, bsdfData.roughnessBT, bsdfData.roughnessBB);
bsdfData.coatRoughness = PerceptualRoughnessToRoughness(bsdfData.coatPerceptualRoughness);
}
else

// TODO: add tangent map for anisotropy;
ConvertAnisotropyToClampRoughness(bsdfData.perceptualRoughnessA, bsdfData.anisotropy, bsdfData.roughnessAT, bsdfData.roughnessAB);
ConvertAnisotropyToClampRoughness(bsdfData.perceptualRoughnessB, bsdfData.anisotropy, bsdfData.roughnessBT, bsdfData.roughnessBB);
bsdfData.roughnessAT = ClampRoughnessForAnalyticalLights(bsdfData.roughnessAT);
bsdfData.roughnessAB = ClampRoughnessForAnalyticalLights(bsdfData.roughnessAB);
bsdfData.roughnessBT = ClampRoughnessForAnalyticalLights(bsdfData.roughnessBT);
bsdfData.roughnessBB = ClampRoughnessForAnalyticalLights(bsdfData.roughnessBB);
}
bsdfData.ambientOcclusion = surfaceData.ambientOcclusion;

int bentVisibilityAlgorithm, bool useHemisphereClip, float3 fresnel0)
{
SphereCap hemiSphere = GetSphereCap(normalWS, 0.0);
//test: SphereCap hemiSphere = GetSphereCap(normalWS, cos(HALF_PI*0.4));
float ambientOcclusionFromData = bsdfData.ambientOcclusion;
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);

// Call after LTC so orthoBasisViewNormal[] are setup along with other preLightData fields:
//
// Makes use of ComputeAdding modified iblPerceptualRoughness, vLayerEnergyCoeff (if vlayered)
// Makes use of ComputeAdding modified (if vlayered) iblPerceptualRoughness, vLayerEnergyCoeff
//
// Note: We make use of iblPerceptualRoughness[] even while at the point where we call _SetupOcclusion, we will have
// modified those in case of anisotropy (it is modified by vlayering if present and not clamped, and then by an empirical
// formula in case anisotropy is present too specifically for the IBL hack).
// Since specular occlusion is not anisotropic anyways, we use these as-is, instead of a version
// "pre-GetGGXAnisotropicModifiedNormalAndRoughness".
//
void PreLightData_SetupOcclusion(PositionInputs posInput, BSDFData bsdfData, float3 V, float3 N[NB_NORMALS], float NdotV[NB_NORMALS] /* clamped */, inout PreLightData preLightData)
{
float screenSpaceSpecularOcclusion[TOTAL_NB_LOBES];

53
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader


_BaseColorMapUV("BaseColor Map UV", Float) = 0.0
_BaseColorMapUVLocal("BaseColorMap UV Local", Float) = 0.0
[Enum(Disney BaseColor and Metallic, 0, BaseColor as Diffuse and SpecularColor aka f0, 1)] _BaseParametrization("Base Parametrization", Float) = 0
[HideInInspector] _MetallicMapShow("Metallic Map Show", Float) = 0
_Metallic("Metallic", Range(0.0, 1.0)) = 0
_MetallicMap("Metallic Map", 2D) = "black" {}

_DielectricIor("DielectricIor IOR", Range(1.0, 2.5)) = 1.5
_SpecularColor("SpecularColor", Color) = (1,1,1,1)
_SpecularColorMap("SpecularColor Map", 2D) = "white" {}
[HideInInspector] _SpecularColorMapShow("SpecularColor Map Show", Float) = 0
_SpecularColorMapUV("SpecularColor Map UV", Float) = 0.0
_SpecularColorMapUVLocal("SpecularColorMap UV Local", Float) = 0.0
[ToggleUI] _EnergyConservingSpecularColor("_EnergyConservingSpecularColor", Float) = 1.0
[HideInInspector] _SmoothnessAMapShow("SmoothnessA Map Show", Float) = 0
_SmoothnessA("SmoothnessA", Range(0.0, 1.0)) = 1.0
_SmoothnessAMap("SmoothnessA Map", 2D) = "white" {}

[ToggleUI] _SmoothnessAMapRemapInverted("Invert SmoothnessA Remap", Float) = 0.0
[HideInInspector] _SmoothnessAMapRange("SmoothnessA Range", Vector) = (0, 1, 0, 0)
[Enum(Direct Parameter Control, 0, Hazy Gloss Parametrization of Barla Pacanowski Vangorp, 1)] _DualSpecularLobeParametrization("Dual Specular Lobe Parametrization", Float) = 0
[ToggleUI] _EnableDualSpecularLobe("Enable Dual Specular Lobe", Float) = 0.0 // UI only
[HideInInspector] _SmoothnessBMapShow("SmoothnessB Map Show", Float) = 0
_SmoothnessB("SmoothnessB", Range(0.0, 1.0)) = 1.0

_SmoothnessBMapRemap("SmoothnessB Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _SmoothnessBMapRemapInverted("Invert SmoothnessB Remap", Float) = 0.0
[HideInInspector] _SmoothnessBMapRange("SmoothnessB Range", Vector) = (0, 1, 0, 0)
_LobeMix("Lobe Mix", Range(0.0, 1.0)) = 0
[HideInInspector] _LobeMixMapShow("LobeMix Map Show", Float) = 0
_LobeMix("LobeMix", Range(0.0, 1.0)) = 0
_LobeMixMap("LobeMix Map", 2D) = "white" {}
_LobeMixUseMap("LobeMix Use Map", Float) = 0
_LobeMixMapUV("LobeMix Map UV", Float) = 0.0
_LobeMixMapUVLocal("_LobeMix Map UV Local", Float) = 0.0
_LobeMixMapChannel("LobeMix Map Channel", Float) = 0.0
[HideInInspector] _LobeMixMapChannelMask("LobeMix Map Channel Mask", Vector) = (1, 0, 0, 0)
_LobeMixMapRemap("LobeMix Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _LobeMixMapRemapInverted("Invert LobeMix Remap", Float) = 0.0
[HideInInspector] _LobeMixMapRange("LobeMix Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _HazinessMapShow("Haziness Map Show", Float) = 0
_Haziness("Haziness", Range(0.0, 1.0)) = 0
_HazinessMap("Haziness Map", 2D) = "white" {}
_HazinessUseMap("Haziness Use Map", Float) = 0
_HazinessMapUV("Haziness Map UV", Float) = 0.0
_HazinessMapUVLocal("_Haziness Map UV Local", Float) = 0.0
_HazinessMapChannel("Haziness Map Channel", Float) = 0.0
[HideInInspector] _HazinessMapChannelMask("Haziness Map Channel Mask", Vector) = (1, 0, 0, 0)
_HazinessMapRemap("Haziness Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _HazinessMapRemapInverted("Invert Haziness Remap", Float) = 0.0
[HideInInspector] _HazinessMapRange("Haziness Range", Vector) = (0, 1, 0, 0)
[ToggleUI] _CapHazinessWrtMetallic("Cap Haziness Wrt Metallic", Float) = 0.0
[HideInInspector] _HazeExtentMapShow("HazeExtent Map Show", Float) = 0
_HazeExtentMapRangeScale("HazeExtent Range Scale", Float) = 8.0
_HazeExtent("HazeExtent", Range(0.0, 1.0)) = 0
_HazeExtentMap("HazeExtent Map", 2D) = "white" {}
_HazeExtentUseMap("HazeExtent Use Map", Float) = 0
_HazeExtentMapUV("HazeExtent Map UV", Float) = 0.0
_HazeExtentMapUVLocal("_HazeExtent Map UV Local", Float) = 0.0
_HazeExtentMapChannel("HazeExtent Map Channel", Float) = 0.0
[HideInInspector] _HazeExtentMapChannelMask("HazeExtent Map Channel Mask", Vector) = (1, 0, 0, 0)
_HazeExtentMapRemap("HazeExtent Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _HazeExtentMapRemapInverted("Invert HazeExtent Remap", Float) = 0.0
[HideInInspector] _HazeExtentMapRange("HazeExtent Range", Vector) = (0, 1, 0, 0)
[ToggleUI] _VlayerRecomputePerLight("Vlayer Recompute Per Light", Float) = 0.0 // UI only
[ToggleUI] _VlayerUseRefractedAnglesForBase("Vlayer Use Refracted Angles For Base", Float) = 0.0 // UI only

#pragma shader_feature _MATERIAL_FEATURE_IRIDESCENCE
#pragma shader_feature _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
#pragma shader_feature _MATERIAL_FEATURE_TRANSMISSION
#pragma shader_feature _MATERIAL_FEATURE_SPECULAR_COLOR
#pragma shader_feature _MATERIAL_FEATURE_HAZY_GLOSS
#pragma shader_feature _VLAYERED_RECOMPUTE_PERLIGHT
#pragma shader_feature _VLAYERED_USE_REFRACTED_ANGLES_FOR_BASE

60
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitData.hlsl


DoAlphaTest(alpha, _AlphaCutoff);
#endif
// These static material feature allow compile time optimization
surfaceData.materialFeatures = MATERIALFEATUREFLAGS_STACK_LIT_STANDARD;
// Standard
surfaceData.baseColor = SAMPLE_TEXTURE2D_SCALE_BIAS(_BaseColorMap).rgb * _BaseColor.rgb;

surfaceData.perceptualSmoothnessA = lerp(_SmoothnessAMapRange.x, _SmoothnessAMapRange.y, surfaceData.perceptualSmoothnessA);
surfaceData.perceptualSmoothnessA = lerp(_SmoothnessA, surfaceData.perceptualSmoothnessA, _SmoothnessAUseMap);
// Metallic / specular color
surfaceData.dielectricIor = _DielectricIor; // shouldn't be needed if _MATERIAL_FEATURE_SPECULAR_COLOR
surfaceData.specularColor = float3(1.0, 1.0, 1.0);
surfaceData.metallic = 0.0;
#ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_STACK_LIT_SPECULAR_COLOR;
surfaceData.specularColor = SAMPLE_TEXTURE2D_SCALE_BIAS(_SpecularColorMap).rgb * _SpecularColor.rgb;
// Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
surfaceData.baseColor *= _EnergyConservingSpecularColor > 0.0 ? (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)) : 1.0;
#else
surfaceData.dielectricIor = _DielectricIor;
#endif
// Ambient Occlusion
// These static material feature allow compile time optimization
surfaceData.materialFeatures = MATERIALFEATUREFLAGS_STACK_LIT_STANDARD;
// Dual specular lobe
surfaceData.lobeMix = 0.0;
surfaceData.perceptualSmoothnessB = 1.0;
surfaceData.haziness = 0.0;
surfaceData.hazeExtent = 0.0;
surfaceData.capHazinessWrtMetallic = false;
// Feature dependent data
surfaceData.lobeMix = _LobeMix;
#ifdef _MATERIAL_FEATURE_HAZY_GLOSS
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_STACK_LIT_HAZY_GLOSS;
surfaceData.haziness = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_HazinessMap), _HazinessMapChannelMask);
surfaceData.haziness = lerp(_HazinessMapRange.x, _HazinessMapRange.y, surfaceData.haziness);
surfaceData.haziness = lerp(_Haziness, surfaceData.haziness, _HazinessUseMap);
surfaceData.hazeExtent = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_HazeExtentMap), _HazeExtentMapChannelMask);
surfaceData.hazeExtent = lerp(_HazeExtentMapRange.x, _HazeExtentMapRange.y, surfaceData.hazeExtent);
surfaceData.hazeExtent = lerp(_HazeExtent, surfaceData.hazeExtent, _HazeExtentUseMap);
surfaceData.hazeExtent *= _HazeExtentMapRangeScale;
#ifndef _MATERIAL_FEATURE_SPECULAR_COLOR
// base parametrization is baseColor + metallic, check option regarding how high can hazeExtent go:
surfaceData.capHazinessWrtMetallic = (_CapHazinessWrtMetallic == 1.0);
#endif
#else // else not def _MATERIAL_FEATURE_HAZY_GLOSS
surfaceData.lobeMix = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_LobeMixMap), _LobeMixMapChannelMask);
surfaceData.lobeMix = lerp(_LobeMixMapRange.x, _LobeMixMapRange.y, surfaceData.lobeMix);
surfaceData.lobeMix = lerp(_LobeMix, surfaceData.lobeMix, _LobeMixUseMap);
#else
surfaceData.lobeMix = 0.0;
surfaceData.perceptualSmoothnessB = 1.0;
#endif
#endif // _MATERIAL_FEATURE_HAZY_GLOSS
#endif // _MATERIAL_FEATURE_DUAL_SPECULAR_LOBE
#ifdef _MATERIAL_FEATURE_ANISOTROPY
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_STACK_LIT_ANISOTROPY;

surfaceData.perceptualSmoothnessA = lerp(surfaceData.perceptualSmoothnessA, saturate(smoothnessOverlay), detailMask);
#ifdef _MATERIAL_FEATURE_DUAL_SPECULAR_LOBE
// Use overlay blend mode for detail abledo: (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))
// TODOTODO: Note that this will be ignored when using Hazy Gloss parametrization. This could be translated to apply to hazeExtent instead.
// Use overlay blend mode for detail abledo: (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))
smoothnessOverlay = (detailPerceptualSmoothness < 0.5) ?
surfaceData.perceptualSmoothnessB * PositivePow(2.0 * detailPerceptualSmoothness, _DetailSmoothnessScale) :
1.0 - (1.0 - surfaceData.perceptualSmoothnessB) * PositivePow(2.0 * (1.0 - detailPerceptualSmoothness), _DetailSmoothnessScale);

52
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitProperties.hlsl


TEXTURE2D(_BaseColorMap);
SAMPLER(sampler_BaseColorMap);
TEXTURE2D(_SpecularColorMap);
SAMPLER(sampler_SpecularColorMap);
TEXTURE2D(_AmbientOcclusionMap);
SAMPLER(sampler_AmbientOcclusionMap);

TEXTURE2D(_SmoothnessBMap);
SAMPLER(sampler_SmoothnessBMap);
TEXTURE2D(_LobeMixMap);
SAMPLER(sampler_LobeMixMap);
TEXTURE2D(_HazinessMap);
SAMPLER(sampler_HazinessMap);
TEXTURE2D(_HazeExtentMap);
SAMPLER(sampler_HazeExtentMap);
TEXTURE2D(_AnisotropyMap);
SAMPLER(sampler_AnisotropyMap);

float _BaseColorMapUV;
float _BaseColorMapUVLocal;
float4 _SpecularColor;
float4 _SpecularColorMap_ST;
float4 _SpecularColorMap_TexelSize;
float4 _SpecularColorMap_MipInfo;
float _SpecularColorMapUV;
float _SpecularColorMapUVLocal;
float _EnergyConservingSpecularColor;
float _Metallic;
float _MetallicUseMap;
float _MetallicMapUV;

float4 _SmoothnessBMap_MipInfo;
float4 _SmoothnessBMapChannelMask;
float4 _SmoothnessBMapRange;
float _LobeMixUseMap;
float _LobeMixMapUV;
float _LobeMixMapUVLocal;
float4 _LobeMixMap_ST;
float4 _LobeMixMap_TexelSize;
float4 _LobeMixMap_MipInfo;
float4 _LobeMixMapChannelMask;
float4 _LobeMixMapRange;
float _Haziness;
float _HazinessUseMap;
float _HazinessMapUV;
float _HazinessMapUVLocal;
float4 _HazinessMap_ST;
float4 _HazinessMap_TexelSize;
float4 _HazinessMap_MipInfo;
float4 _HazinessMapChannelMask;
float4 _HazinessMapRange;
float _CapHazinessWrtMetallic;
float _HazeExtent;
float _HazeExtentUseMap;
float _HazeExtentMapUV;
float _HazeExtentMapUVLocal;
float4 _HazeExtentMap_ST;
float4 _HazeExtentMap_TexelSize;
float4 _HazeExtentMap_MipInfo;
float4 _HazeExtentMapChannelMask;
float4 _HazeExtentMapRange;
float _HazeExtentMapRangeScale;
float _Anisotropy;
float _AnisotropyUseMap;

正在加载...
取消
保存