浏览代码

First working version of the UI.

Still missing implementation for UVs and channels.
/main
Jean-François F Fortin 7 年前
当前提交
059f098f
共有 6 个文件被更改,包括 639 次插入299 次删除
  1. 429
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/StackLit/StackLitUI.cs
  2. 25
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLit.shader
  3. 18
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLitData.hlsl
  4. 29
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLitProperties.hlsl
  5. 426
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs
  6. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs.meta

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


using System;
class StackLitGUI : BaseUnlitGUI
class StackLitGUI : BaseMaterialGUI
protected static class Styles
{
public static string InputsText = "Inputs";
public static GUIContent doubleSidedNormalModeText = new GUIContent("Normal mode", "This will modify the normal base on the selected mode. Mirror: Mirror the normal with vertex normal plane, Flip: Flip the normal");
#region Strings
public static GUIContent baseColorText = new GUIContent("Base Color + Opacity", "Albedo (RGB) and Opacity (A)");
protected const string k_DoubleSidedNormalMode = "_DoubleSidedNormalMode";
protected const string k_UVBase = "_UVBase";
// Scalar scale factors for: metallic and the two lobe perceptual smoothness.
public static GUIContent metallicText = new GUIContent("Metallic", "Metallic scale factor");
public static GUIContent smoothnessAText = new GUIContent("Primary Lobe Smoothness", "Primary lobe smoothness scale factor");
public static GUIContent smoothnessBText = new GUIContent("Secondary Lobe Smoothness", "Secondary lobe smoothness scale factor");
public static GUIContent lobeMixText = new GUIContent("Lobe Mixing", "Lobe mixing factor");
// Base
protected const string k_BaseColor = "_BaseColor";
protected const string k_BaseColorMap = "_BaseColorMap";
public static GUIContent smoothnessARemappingText = new GUIContent("Primary Lobe Smoothness Remapping", "Primary lobe smoothness remapping");
public static GUIContent smoothnessBRemappingText = new GUIContent("Secondary Lobe Smoothness Remapping", "Secondary lobe smoothness remapping");
public static GUIContent maskMapASText = new GUIContent("Primary mask map - M(R), AO(G), D(B), S1(A)", "Primary mask map");
public static GUIContent maskMapBSText = new GUIContent("Secondary mask Map - (R), (G), (B), S2(A)", "Secondary mask map");
protected const string k_Metallic = "_Metallic";
protected const string k_MetallicMap = "_MetallicMap";
protected const string k_MetallicRemapMin = "_MetallicRemap";
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map (BC7/BC5/DXT5(nm))");
protected const string k_Smoothness1 = "_SmoothnessA";
protected const string k_Smoothness1Map = "_SmoothnessAMap";
protected const string k_Smoothness1RemapMin = "_SmoothnessARemap";
public static GUIContent UVBaseMappingText = new GUIContent("UV mapping usage", "");
protected const string k_NormalMap = "_NormalMap";
protected const string k_NormalScale = "_NormalScale";
// Emissive
protected const string k_EmissiveColor = "_EmissiveColor";
protected const string k_EmissiveColorMap = "_EmissiveColorMap";
protected const string k_EmissiveIntensity = "_EmissiveIntensity";
protected const string k_AlbedoAffectEmissive = "_AlbedoAffectEmissive";
// Emissive
public static string emissiveLabelText = "Emissive Inputs";
public static GUIContent emissiveText = new GUIContent("Emissive Color", "Emissive");
public static GUIContent emissiveIntensityText = new GUIContent("Emissive Intensity", "Emissive");
public static GUIContent albedoAffectEmissiveText = new GUIContent("Albedo Affect Emissive", "Specifies whether or not the emissive color is multiplied by the albedo.");
// SSS
protected const string k_DiffusionProfileName = "_DiffusionProfile";
protected const string k_SubsurfaceMaskName = "_SubsurfaceMask";
protected const string k_SubsurfaceMaskMap = "_SubsurfaceMaskMap";
}
protected const string k_ThicknessName = "_Thickness";
protected const string k_ThicknessMapName = "_ThicknessMap";
protected const string k_ThicknessRemapName = "_ThicknessRemap";
public enum DoubleSidedNormalMode
{
Flip,
Mirror,
None
}
// Second Lobe.
protected const string k_Smoothness2 = "_SmoothnessB";
protected const string k_Smoothness2Map = "_SmoothnessBMap";
protected const string k_SmoothnessRemap2Min = "_SmoothnessBRemap";
public enum UVBaseMapping
protected const string k_LobeMix = "_LobeMix";
//// transparency params
//protected MaterialProperty transmissionEnable = null;
//protected const string kTransmissionEnable = "_TransmissionEnable";
//protected MaterialProperty ior = null;
//protected const string kIor = "_Ior";
//protected MaterialProperty transmittanceColor = null;
//protected const string kTransmittanceColor = "_TransmittanceColor";
//protected MaterialProperty transmittanceColorMap = null;
//protected const string kTransmittanceColorMap = "_TransmittanceColorMap";
//protected MaterialProperty atDistance = null;
//protected const string kATDistance = "_ATDistance";
//protected MaterialProperty thicknessMultiplier = null;
//protected const string kThicknessMultiplier = "_ThicknessMultiplier";
//protected MaterialProperty refractionModel = null;
//protected const string kRefractionModel = "_RefractionModel";
//protected MaterialProperty refractionSSRayModel = null;
//protected const string kRefractionSSRayModel = "_RefractionSSRayModel";
#endregion
// Add the properties into an array.
private readonly GroupProperty _baseMaterialProperties = null;
private readonly GroupProperty _materialProperties = null;
public StackLitGUI()
UV0,
UV1,
UV2,
UV3,
Planar,
Triplanar
}
_baseMaterialProperties = new GroupProperty(this, new BaseProperty[]
{
// JFFTODO: Find the proper condition, and proper way to display this.
new Property(this, k_DoubleSidedNormalMode, "Normal mode", "This will modify the normal base on the selected mode. Mirror: Mirror the normal with vertex normal plane, Flip: Flip the normal.", false),
});
protected MaterialProperty doubleSidedNormalMode = null;
protected const string kDoubleSidedNormalMode = "_DoubleSidedNormalMode";
_materialProperties = new GroupProperty(this, new BaseProperty[]
{
new GroupProperty(this, "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),
// TODO: Special case for normal maps.
new TextureProperty(this, k_NormalMap, k_NormalScale, "Normal TODO", "Normal Map", false, true),
// Example UV mapping mask, TODO: could have for multiple maps, and channel mask for scalars
protected MaterialProperty UVBase = null;
protected const string kUVBase = "_UVBase";
protected MaterialProperty UVMappingMask = null;
protected const string kUVMappingMask = "_UVMappingMask"; // hidden, see enum material property drawer in .shader
//new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Dielectric IoR", "Index of Refraction for Dielectric", false),
}),
new GroupProperty(this, "Emissive", new BaseProperty[]
{
new TextureProperty(this, k_EmissiveColorMap, k_EmissiveColor, "Emissive Color", "Emissive", false),
new Property(this, k_EmissiveIntensity, "Emissive Intensity", "Emissive", false),
new Property(this, k_AlbedoAffectEmissive, "Albedo Affect Emissive", "Specifies whether or not the emissive color is multiplied by the albedo.", false),
}),
protected MaterialProperty baseColor = null;
protected const string kBaseColor = "_BaseColor";
protected MaterialProperty baseColorMap = null;
protected const string kBaseColorMap = "_BaseColorMap";
//new GroupProperty(this, "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),
//}),
protected const string kMetallic = "_Metallic";
protected MaterialProperty metallic = null;
new GroupProperty(this, "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),
}/*, _ => _materialId == MaterialId.SubSurfaceScattering*/),
// Primary lobe smoothness
protected MaterialProperty smoothnessA = null;
protected const string kSmoothnessA = "_SmoothnessA";
protected MaterialProperty smoothnessARemapMin = null;
protected const string kSmoothnessARemapMin = "_SmoothnessARemapMin";
protected MaterialProperty smoothnessARemapMax = null;
protected const string kSmoothnessARemapMax = "_SmoothnessARemapMax";
protected const string klobeMix = "_LobeMix";
protected MaterialProperty lobeMix = null;
new GroupProperty(this, "Second Specular Lobe", new BaseProperty[]
{
new TextureProperty(this, k_Smoothness2Map, k_Smoothness2, "Smoothness2", "Smoothness2", false),
new Property(this, k_LobeMix, "Lobe Mix", "Lobe Mix", false),
}),
// Secondary lobe smoothness
protected MaterialProperty smoothnessB = null;
protected const string kSmoothnessB = "_SmoothnessB";
protected MaterialProperty smoothnessBRemapMin = null;
protected const string kSmoothnessBRemapMin = "_SmoothnessBRemapMin";
protected MaterialProperty smoothnessBRemapMax = null;
protected const string kSmoothnessBRemapMax = "_SmoothnessBRemapMax";
//new GroupProperty(this, "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 TextureProperty(this, k_BaseColorMap, k_BaseColor, "Tangent", "tangent", false),
//}),
new GroupProperty(this, "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),
}),
// Two mask maps for the two smoothnesses
protected MaterialProperty maskMapA = null;
protected const string kMaskMapA = "_MaskMapA";
protected MaterialProperty maskMapB = null;
protected const string kMaskMapB = "_MaskMapB";
//new GroupProperty(this, "Iridescence", new BaseProperty[]
//{
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Index of Refraction", "Index of Refraction for Iridescence", false),
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Thickness", "Thickness", false),
//}),
protected MaterialProperty normalScale = null;
protected const string kNormalScale = "_NormalScale";
protected MaterialProperty normalMap = null;
protected const string kNormalMap = "_NormalMap";
//new GroupProperty(this, "Glint", new BaseProperty[]
//{
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Density", "Density:", false),
// new TextureProperty(this, k_BaseColorMap, k_BaseColor, "Tint", "Tint", false),
//}),
});
}
protected MaterialProperty emissiveColor = null;
protected const string kEmissiveColor = "_EmissiveColor";
protected MaterialProperty emissiveColorMap = null;
protected const string kEmissiveColorMap = "_EmissiveColorMap";
protected MaterialProperty emissiveIntensity = null;
protected const string kEmissiveIntensity = "_EmissiveIntensity";
protected MaterialProperty albedoAffectEmissive = null;
protected const string kAlbedoAffectEmissive = "_AlbedoAffectEmissive";
protected override bool ShouldEmissionBeEnabled(Material material)
{
return material.GetFloat(k_EmissiveIntensity) > 0.0f;
}
doubleSidedNormalMode = FindProperty(kDoubleSidedNormalMode, props);
_baseMaterialProperties.OnFindProperty(props);
override protected void FindMaterialProperties(MaterialProperty[] props)
protected override void FindMaterialProperties(MaterialProperty[] props)
UVBase = FindProperty(kUVBase, props);
UVMappingMask = FindProperty(kUVMappingMask, props);
baseColor = FindProperty(kBaseColor, props);
baseColorMap = FindProperty(kBaseColorMap, props);
metallic = FindProperty(kMetallic, props);
smoothnessA = FindProperty(kSmoothnessA, props);
smoothnessARemapMin = FindProperty(kSmoothnessARemapMin, props);
smoothnessARemapMax = FindProperty(kSmoothnessARemapMax, props);
smoothnessB = FindProperty(kSmoothnessB, props);
smoothnessBRemapMin = FindProperty(kSmoothnessBRemapMin, props);
smoothnessBRemapMax = FindProperty(kSmoothnessBRemapMax, props);
lobeMix = FindProperty(klobeMix, props);
maskMapA = FindProperty(kMaskMapA, props);
maskMapB = FindProperty(kMaskMapB, props);
normalMap = FindProperty(kNormalMap, props);
normalScale = FindProperty(kNormalScale, props);
emissiveColor = FindProperty(kEmissiveColor, props);
emissiveColorMap = FindProperty(kEmissiveColorMap, props);
emissiveIntensity = FindProperty(kEmissiveIntensity, props);
albedoAffectEmissive = FindProperty(kAlbedoAffectEmissive, props);
}
//base.FindMaterialProperties(props);
_materialProperties.OnFindProperty(props);
}
EditorGUI.indentLevel++;
// This follow double sided option, see BaseUnlitUI.BaseMaterialPropertiesGUI()
// Don't put anything between base.BaseMaterialPropertiesGUI(); above and this:
if (doubleSidedEnable.floatValue > 0.0f)
{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(doubleSidedNormalMode, Styles.doubleSidedNormalModeText);
EditorGUI.indentLevel--;
}
//TODO: m_MaterialEditor.ShaderProperty(enableMotionVectorForVertexAnimation, StylesBaseUnlit.enableMotionVectorForVertexAnimationText);
//refs to this ?
EditorGUI.indentLevel--;
_baseMaterialProperties.OnGUI();
EditorGUILayout.LabelField(Styles.InputsText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap, baseColor);
m_MaterialEditor.ShaderProperty(metallic, Styles.metallicText);
// maskMaps and smoothness rescaling controls:
if(maskMapA.textureValue == null)
{
m_MaterialEditor.ShaderProperty(smoothnessA, Styles.smoothnessAText);
}
else
{
float remapMin = smoothnessARemapMin.floatValue;
float remapMax = smoothnessARemapMax.floatValue;
EditorGUI.BeginChangeCheck();
EditorGUILayout.MinMaxSlider(Styles.smoothnessARemappingText, ref remapMin, ref remapMax, 0.0f, 1.0f);
if (EditorGUI.EndChangeCheck())
{
smoothnessARemapMin.floatValue = remapMin;
smoothnessARemapMax.floatValue = remapMax;
}
}
if(maskMapB.textureValue == null)
{
m_MaterialEditor.ShaderProperty(smoothnessB, Styles.smoothnessBText);
}
else
{
float remapMin = smoothnessBRemapMin.floatValue;
float remapMax = smoothnessBRemapMax.floatValue;
EditorGUI.BeginChangeCheck();
EditorGUILayout.MinMaxSlider(Styles.smoothnessBRemappingText, ref remapMin, ref remapMax, 0.0f, 1.0f);
if (EditorGUI.EndChangeCheck())
{
smoothnessBRemapMin.floatValue = remapMin;
smoothnessBRemapMax.floatValue = remapMax;
}
}
m_MaterialEditor.ShaderProperty(lobeMix, Styles.lobeMixText);
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapASText, maskMapA);
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapBSText, maskMapB);
// Normal map:
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap, normalScale);
// UV Mapping:
EditorGUILayout.Space();
EditorGUI.BeginChangeCheck(); // UV mapping selection
m_MaterialEditor.ShaderProperty(UVBase, Styles.UVBaseMappingText);
UVBaseMapping uvBaseMapping = (UVBaseMapping)UVBase.floatValue;
float X, Y, Z, W;
X = (uvBaseMapping == UVBaseMapping.UV0) ? 1.0f : 0.0f;
Y = (uvBaseMapping == UVBaseMapping.UV1) ? 1.0f : 0.0f;
Z = (uvBaseMapping == UVBaseMapping.UV2) ? 1.0f : 0.0f;
W = (uvBaseMapping == UVBaseMapping.UV3) ? 1.0f : 0.0f;
UVMappingMask.colorValue = new Color(X, Y, Z, W);
//TODO:
//if ((uvBaseMapping == UVBaseMapping.Planar) || (uvBaseMapping == UVBaseMapping.Triplanar))
//{
// m_MaterialEditor.ShaderProperty(TexWorldScale, Styles.texWorldScaleText);
//}
m_MaterialEditor.TextureScaleOffsetProperty(baseColorMap);
if (EditorGUI.EndChangeCheck()) // ...UV mapping selection
{
}
EditorGUI.indentLevel--; // inputs
EditorGUILayout.Space();
// Surface type:
var surfaceTypeValue = (SurfaceType)surfaceType.floatValue;
if (surfaceTypeValue == SurfaceType.Transparent)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(StylesBaseUnlit.TransparencyInputsText, EditorStyles.boldLabel);
++EditorGUI.indentLevel;
DoDistortionInputsGUI();
--EditorGUI.indentLevel;
}
// TODO: see DoEmissiveGUI( ) in LitUI.cs: custom uvmapping for emissive
EditorGUILayout.Space();
EditorGUILayout.LabelField(Styles.emissiveLabelText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColor);
m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
m_MaterialEditor.ShaderProperty(albedoAffectEmissive, Styles.albedoAffectEmissiveText);
EditorGUI.indentLevel--;
_materialProperties.OnGUI();
}
protected override void MaterialPropertiesAdvanceGUI(Material material)

protected override void VertexAnimationPropertiesGUI()
{
}
protected override bool ShouldEmissionBeEnabled(Material mat)
{
return mat.GetFloat(kEmissiveIntensity) > 0.0f;
}
protected override void SetupMaterialKeywordsAndPassInternal(Material material)

if (doubleSidedEnable)
{
DoubleSidedNormalMode doubleSidedNormalMode = (DoubleSidedNormalMode)material.GetFloat(kDoubleSidedNormalMode);
BaseLitGUI.DoubleSidedNormalMode doubleSidedNormalMode = (BaseLitGUI.DoubleSidedNormalMode)material.GetFloat(k_DoubleSidedNormalMode);
case DoubleSidedNormalMode.Mirror: // Mirror mode (in tangent space)
case BaseLitGUI.DoubleSidedNormalMode.Mirror: // Mirror mode (in tangent space)
case DoubleSidedNormalMode.Flip: // Flip mode (in tangent space)
case BaseLitGUI.DoubleSidedNormalMode.Flip: // Flip mode (in tangent space)
case DoubleSidedNormalMode.None: // None mode (in tangent space)
case BaseLitGUI.DoubleSidedNormalMode.None: // None mode (in tangent space)
material.SetVector("_DoubleSidedConstants", new Vector4(1.0f, 1.0f, 1.0f, 0.0f));
break;
}

// so no stencil tagging there, but velocity? To check...
//TODO: stencil state, displacement, wind, depthoffset, tesselation
//TODO: stencil state, displacement, wind, depthoffset, tessellation
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap));
CoreUtils.SetKeyword(material, "_MASKMAPA", material.GetTexture(kMaskMapA));
CoreUtils.SetKeyword(material, "_MASKMAPB", material.GetTexture(kMaskMapB));
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));
bool needUV2 = (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV2;
bool needUV3 = (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV3;
//bool needUV2 = (LitGUI.UVBaseMapping)material.GetFloat(k_UVBase) == LitGUI.UVBaseMapping.UV2;
//bool needUV3 = (LitGUI.UVBaseMapping)material.GetFloat(k_UVBase) == LitGUI.UVBaseMapping.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 (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");
//}
CoreUtils.SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));
CoreUtils.SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(k_EmissiveColorMap));
}
}
} // namespace UnityEditor

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


// 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
_MetallicMap("MetallicMap", 2D) = "white" {}
_MetallicMapUV("MetallicMapUV", Float) = 0.0
_MetallicRemap("Metallic Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _MetallicRemapInverted("Invert Metallic Remap", Float) = 0.0
_SmoothnessARemapMin("SmoothnessARemapMin", Float) = 0.0
_SmoothnessARemapMax("SmoothnessARemapMax", Float) = 1.0
_SmoothnessAMap("BaseColorMap", 2D) = "white" {}
_SmoothnessAMapUV("SmoothnessAMapUV", Float) = 0.0
_SmoothnessARemap("SmoothnessA Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _SmoothnessARemapInverted("Invert SmoothnessA Remap", Float) = 0.0
_SmoothnessBRemapMin("SmoothnessBRemapMin", Float) = 0.0
_SmoothnessBRemapMax("SmoothnessBRemapMax", Float) = 1.0
_LobeMix("lobeMix", Range(0.0, 1.0)) = 0
_MaskMapA("MaskMapA", 2D) = "white" {}
_MaskMapB("MaskMapB", 2D) = "white" {}
_SmoothnessBMap("SmoothnessBMap", 2D) = "white" {}
_SmoothnessBMapUV("SmoothnessBMapUV", Float) = 0.0
_SmoothnessBRemap("SmoothnessB Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _SmoothnessBRemapInverted("Invert SmoothnessB Remap", Float) = 0.0
_LobeMix("Lobe Mix", Range(0.0, 1.0)) = 0
_NormalMapUV("NormalMapUV", Float) = 0.0
_EmissiveColorMapUV("EmissiveColorMap", Range(0.0, 1.0)) = 0
_EmissiveIntensity("EmissiveIntensity", Float) = 0
[ToggleUI] _AlbedoAffectEmissive("Albedo Affect Emissive", Float) = 0.0

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


normalTS = GetNormalTS(input, layerTexCoord, detailNormalTS, detailMask);
//TODO: bentNormalTS
#if defined(_MASKMAPA)
surfaceData.perceptualSmoothnessA = SAMPLE_UVMAPPING_TEXTURE2D(_MaskMapA, sampler_MaskMapA, layerTexCoord.base).a;
surfaceData.perceptualSmoothnessA = lerp(_SmoothnessARemapMin, _SmoothnessARemapMax, surfaceData.perceptualSmoothnessA);
#if defined(_SMOOTHNESSMASKMAPA)
surfaceData.perceptualSmoothnessA = SAMPLE_UVMAPPING_TEXTURE2D(_SmoothnessAMap, sampler_SmoothnessAMap, layerTexCoord.base).a;
surfaceData.perceptualSmoothnessA = lerp(_SmoothnessARemap.x, _SmoothnessARemap.y, surfaceData.perceptualSmoothnessA);
#if defined(_MASKMAPB)
surfaceData.perceptualSmoothnessB = SAMPLE_UVMAPPING_TEXTURE2D(_MaskMapB, sampler_MaskMapB, layerTexCoord.base).a;
surfaceData.perceptualSmoothnessB = lerp(_SmoothnessBRemapMin, _SmoothnessBRemapMax, surfaceData.perceptualSmoothnessB);
#if defined(_SMOOTHNESSMASKMAPB)
surfaceData.perceptualSmoothnessB = SAMPLE_UVMAPPING_TEXTURE2D(_SmoothnessAMaB, sampler_SmoothnessBMap, layerTexCoord.base).a;
surfaceData.perceptualSmoothnessB = lerp(_SmoothnessBRemap.x, _SmoothnessBRemap.y, surfaceData.perceptualSmoothnessB);
// MaskMapA is RGBA: Metallic, Ambient Occlusion (Optional), detail Mask (Optional), Smoothness
#ifdef _MASKMAPA
surfaceData.metallic = SAMPLE_UVMAPPING_TEXTURE2D(_MaskMapA, sampler_MaskMapA, layerTexCoord.base).r;
#ifdef _METALLICMAP
surfaceData.metallic = SAMPLE_UVMAPPING_TEXTURE2D(_MetallicMap, sampler_MetallicMap, layerTexCoord.base).r;
#else
surfaceData.metallic = 1.0;
#endif

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


TEXTURE2D(_DistortionVectorMap);
SAMPLER(sampler_DistortionVectorMap);
TEXTURE2D(_EmissiveColorMap);
SAMPLER(sampler_EmissiveColorMap);
TEXTURE2D(_MaskMapA);
SAMPLER(sampler_MaskMapA);
TEXTURE2D(_MetallicMap);
SAMPLER(sampler_MetallicMap);
TEXTURE2D(_SmoothnessAMap);
SAMPLER(sampler_SmoothnessAMap);
TEXTURE2D(_SmoothnessBMap);
SAMPLER(sampler_SmoothnessBMap);
TEXTURE2D(_MaskMapB);
SAMPLER(sampler_MaskMapB);
TEXTURE2D(_EmissiveColorMap);
SAMPLER(sampler_EmissiveColorMap);
TEXTURE2D(_NormalMap);
SAMPLER(sampler_NormalMap);

float4 _BaseColorMap_ST;
float4 _BaseColorMap_TexelSize;
float4 _BaseColorMap_MipInfo;
float _BaseColorMapUV;
float _MetallicMapUV;
float _SmoothnessARemapMin;
float _SmoothnessARemapMax;
float _SmoothnessAMapUV;
float4 _SmoothnessARemap;
float _SmoothnessBRemapMin;
float _SmoothnessBRemapMax;
float _SmoothnessBUV;
float4 _SmoothnessBRemap;
float _NormalMapUV;
float4 _UVMappingMask;

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


using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
public abstract class BaseMaterialGUI : BaseUnlitGUI
{
#region GUI Property Classes
public abstract class BaseProperty
{
public BaseMaterialGUI Parent = null;
protected Func<object, bool> IsVisible;
protected BaseProperty(BaseMaterialGUI parent, Func<object, bool> isVisible = null)
{
Parent = parent;
IsVisible = isVisible;
}
public abstract void OnFindProperty(MaterialProperty[] props);
public abstract void OnGUI();
}
public class GroupProperty : BaseProperty
{
public string m_Title = string.Empty;
private readonly BaseProperty[] m_ChildProperties;
public GroupProperty(BaseMaterialGUI parent, BaseProperty[] childProperties, Func<object, bool> isVisible = null)
: this(parent, string.Empty, childProperties, isVisible)
{
}
public GroupProperty(BaseMaterialGUI parent, string groupTitle, BaseProperty[] childProperties, Func<object, bool> isVisible = null)
: base(parent, isVisible)
{
m_Title = groupTitle;
m_ChildProperties = childProperties;
}
public override void OnFindProperty(MaterialProperty[] props)
{
foreach (var c in m_ChildProperties)
{
c.OnFindProperty(props);
}
}
public override void OnGUI()
{
if (IsVisible == null || IsVisible(this))
{
if (!string.IsNullOrEmpty(m_Title))
{
EditorGUILayout.LabelField(m_Title, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
}
foreach (var c in m_ChildProperties)
{
c.OnGUI();
}
if (!string.IsNullOrEmpty(m_Title))
{
EditorGUI.indentLevel--;
}
}
}
}
public class Property : BaseProperty
{
public string PropertyName;
public string PropertyText;
protected MaterialProperty m_MaterialProperty = null;
protected readonly GUIContent m_GuiContent = null;
public bool IsMandatory = false;
public bool IsValid
{
get { return m_MaterialProperty != null; }
}
public float FloatValue
{
get { return m_MaterialProperty.floatValue; }
set { m_MaterialProperty.floatValue = value; }
}
public bool BoolValue
{
get { return Math.Abs(m_MaterialProperty.floatValue) > 0.0f; }
set { m_MaterialProperty.floatValue = value ? 1.0f : 0.0f; }
}
public Texture TextureValue
{
get { return m_MaterialProperty != null ? m_MaterialProperty.textureValue : null; }
set { if (m_MaterialProperty != null) { m_MaterialProperty.textureValue = value; } }
}
public Vector4 VectorValue
{
get { return m_MaterialProperty.vectorValue; }
set { m_MaterialProperty.vectorValue = value; }
}
public Property(BaseMaterialGUI parent, string propertyName, string guiText, bool isMandatory = true)
: this(parent, propertyName, guiText, string.Empty, isMandatory)
{
}
public Property(BaseMaterialGUI parent, string propertyName, string guiText, string toolTip, bool isMandatory = true)
: base(parent)
{
m_GuiContent = new GUIContent(guiText, toolTip);
PropertyName = propertyName;
PropertyText = guiText;
IsMandatory = isMandatory;
}
public override void OnFindProperty(MaterialProperty[] props)
{
m_MaterialProperty = ShaderGUI.FindProperty(PropertyName, props, IsMandatory);
}
public override void OnGUI()
{
if (IsValid
&& (IsVisible == null || IsVisible(this)))
{
Parent.m_MaterialEditor.ShaderProperty(m_MaterialProperty, m_GuiContent);
}
}
}
public class ComboProperty : Property
{
private readonly string[] m_Options;
private readonly int[] m_Values = null;
public ComboProperty(BaseMaterialGUI parent, string propertyName, string guiText, string[] options, bool isMandatory = true)
: base(parent, propertyName, guiText, isMandatory)
{
m_Options = options;
}
public ComboProperty(BaseMaterialGUI parent, string propertyName, string guiText, string toolTip, string[] options, bool isMandatory = true)
: base(parent, propertyName, guiText, toolTip, isMandatory)
{
m_Options = options;
}
public ComboProperty(BaseMaterialGUI parent, string propertyName, string guiText, string[] options, int[] values, bool isMandatory = true)
: base(parent, propertyName, guiText, isMandatory)
{
m_Options = options;
m_Values = values;
}
public ComboProperty(BaseMaterialGUI parent, string propertyName, string guiText, string toolTip, string[] options, int[] values, bool isMandatory = true)
: base(parent, propertyName, guiText, toolTip, isMandatory)
{
m_Options = options;
m_Values = values;
}
public override void OnGUI()
{
if (IsValid
&& (IsVisible == null || IsVisible(this)))
{
EditorGUI.showMixedValue = m_MaterialProperty.hasMixedValue;
float floatValue = m_MaterialProperty.floatValue;
EditorGUI.BeginChangeCheck();
if (m_Values == null)
{
floatValue = EditorGUILayout.Popup(m_GuiContent, (int)floatValue, m_Options);
}
else
{
floatValue = EditorGUILayout.IntPopup(m_GuiContent.text, (int)floatValue, m_Options, m_Values);
}
if (EditorGUI.EndChangeCheck())
{
Parent.m_MaterialEditor.RegisterPropertyChangeUndo(PropertyName);
m_MaterialProperty.floatValue = (float)floatValue;
}
EditorGUI.showMixedValue = false;
}
}
}
public class DiffusionProfileProperty : Property
{
public DiffusionProfileProperty(BaseMaterialGUI parent, string propertyName, string guiText, string toolTip, bool isMandatory = true)
: base(parent, propertyName, guiText, toolTip, isMandatory)
{
}
public override void OnGUI()
{
if (IsValid
&& (IsVisible == null || IsVisible(this)))
{
var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
if (hdPipeline == null)
{
return;
}
var diffusionProfileSettings = hdPipeline.diffusionProfileSettings;
if (hdPipeline.IsInternalDiffusionProfile(diffusionProfileSettings))
{
EditorGUILayout.HelpBox(
"No diffusion profile Settings have been assigned to the render pipeline asset.",
MessageType.Warning);
return;
}
// TODO: Optimize me
var profiles = diffusionProfileSettings.profiles;
var names = new GUIContent[profiles.Length + 1];
names[0] = new GUIContent("None");
var values = new int[names.Length];
values[0] = DiffusionProfileConstants.DIFFUSION_PROFILE_NEUTRAL_ID;
for (int i = 0; i < profiles.Length; i++)
{
names[i + 1] = new GUIContent(profiles[i].name);
values[i + 1] = i + 1;
}
using (var scope = new EditorGUI.ChangeCheckScope())
{
int profileID = (int) FloatValue;
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PrefixLabel(m_GuiContent.text);
using (new EditorGUILayout.HorizontalScope())
{
profileID = EditorGUILayout.IntPopup(profileID, names, values);
if (GUILayout.Button("Goto", EditorStyles.miniButton, GUILayout.Width(50f)))
{
Selection.activeObject = diffusionProfileSettings;
}
}
}
if (scope.changed)
{
FloatValue = profileID;
}
}
}
}
}
public class TextureOneLineProperty : Property
{
public string ExtraPropertyName;
private MaterialProperty m_ExtraProperty;
public TextureOneLineProperty(BaseMaterialGUI parent, string propertyName, string guiText, bool isMandatory = true)
: base(parent, propertyName, guiText, isMandatory)
{
}
public TextureOneLineProperty(BaseMaterialGUI parent, string propertyName, string guiText, string toolTip, bool isMandatory = true)
: base(parent, propertyName, guiText, toolTip, isMandatory)
{
}
public TextureOneLineProperty(BaseMaterialGUI parent, string propertyName, string extraPropertyName, string guiText, string toolTip, bool isMandatory = true)
: base(parent, propertyName, guiText, toolTip, isMandatory)
{
ExtraPropertyName = extraPropertyName;
}
public override void OnFindProperty(MaterialProperty[] props)
{
base.OnFindProperty(props);
if (!string.IsNullOrEmpty(ExtraPropertyName))
{
m_ExtraProperty = ShaderGUI.FindProperty(ExtraPropertyName, props, IsMandatory);
}
}
public override void OnGUI()
{
if (IsValid && (IsVisible == null || IsVisible(this)))
{
Parent.m_MaterialEditor.TexturePropertySingleLine(m_GuiContent, m_MaterialProperty, m_ExtraProperty);
}
}
}
public class TextureProperty : Property
{
public enum Tiling
{
Wrap,
Clamp,
}
public enum Channel
{
R,
G,
B,
A,
}
public enum UVSet
{
UV0,
UV1,
UV2,
UV3,
PlanarXY,
PlanarYZ,
PlanarZX,
Triplanar,
}
public TextureOneLineProperty m_TextureProperty;
public ComboProperty m_ChannelProperty;
public ComboProperty m_TilingProperty;
public ComboProperty m_UvSetProperty;
public Property m_LocalOrWorldProperty;
public Property m_RemapProperty;
public Property m_InvertRemapProperty;
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, string toolTip, bool isMandatory = true, bool isNormalMap = false)
: base(parent, propertyName, guiText, toolTip, isMandatory)
{
m_TextureProperty = new TextureOneLineProperty(parent, propertyName, constantPropertyName, guiText, toolTip, isMandatory);
m_ChannelProperty = new ComboProperty(parent, propertyName + "Channel", "Channel", Enum.GetNames(typeof(Channel)), false);
m_TilingProperty = new ComboProperty(parent, propertyName + "Tiling", "Tiling", Enum.GetNames(typeof(Tiling)), false);
m_UvSetProperty = new ComboProperty(parent, propertyName + "UV", "UV Set", Enum.GetNames(typeof(UVSet)), false);
m_LocalOrWorldProperty = new Property(parent, propertyName + "LocalOrWorld", "Local Space", "Whether Planar or Triplanar is using Local or World space.", 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);
}
public override void OnFindProperty(MaterialProperty[] props)
{
base.OnFindProperty(props);
m_TextureProperty.OnFindProperty(props);
m_TilingProperty.OnFindProperty(props);
m_UvSetProperty.OnFindProperty(props);
m_LocalOrWorldProperty.OnFindProperty(props);
m_RemapProperty.OnFindProperty(props);
m_InvertRemapProperty.OnFindProperty(props);
}
public override void OnGUI()
{
if (m_TextureProperty.IsValid
&& (IsVisible == null || IsVisible(this)))
{
m_TextureProperty.OnGUI();
if (m_TextureProperty.TextureValue != null)
{
EditorGUI.indentLevel++;
m_TilingProperty.OnGUI();
m_UvSetProperty.OnGUI();
m_LocalOrWorldProperty.OnGUI();
if (m_RemapProperty.IsValid)
{
// Display the remap of texture values.
Vector2 remap = m_RemapProperty.VectorValue;
EditorGUI.BeginChangeCheck();
EditorGUILayout.MinMaxSlider(m_RemapProperty.PropertyText, ref remap.x, ref remap.y, 0.0f, 1.0f);
if (EditorGUI.EndChangeCheck())
{
m_RemapProperty.VectorValue = remap;
}
m_InvertRemapProperty.OnGUI();
}
EditorGUI.indentLevel--;
}
}
}
}
#endregion
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs.meta


fileFormatVersion: 2
guid: 2a11a2741c48d9848aa375c84fbcab39
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存