|
|
|
|
|
|
using System; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Experimental.Rendering; |
|
|
|
using UnityEngine.Experimental.Rendering.HDPipeline; |
|
|
|
|
|
|
|
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|
|
|
{ |
|
|
|
|
|
|
public static GUIContent anisotropyMapText = new GUIContent("Anisotropy Map (R)", "Anisotropy"); |
|
|
|
|
|
|
|
public static GUIContent UVBaseMappingText = new GUIContent("Base UV mapping", ""); |
|
|
|
public static GUIContent texWorldScaleText = new GUIContent("World scale", "Tiling factor applied to Planar/Trilinear mapping"); |
|
|
|
|
|
|
|
// Details
|
|
|
|
public static string detailText = "Detail Inputs"; |
|
|
|
|
|
|
|
|
|
|
protected MaterialProperty UVBase = null; |
|
|
|
protected const string kUVBase = "_UVBase"; |
|
|
|
protected MaterialProperty InvTilingScale = null; |
|
|
|
protected const string kInvTilingScale = "_InvTilingScale"; |
|
|
|
protected MaterialProperty UVMappingMask = null; |
|
|
|
protected const string kUVMappingMask = "_UVMappingMask"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected MaterialProperty fuzzTint = null; |
|
|
|
protected const string kFuzzTint = "_FuzzTint"; |
|
|
|
protected MaterialProperty clothType = null; |
|
|
|
protected const string kClothType = "_ClothType"; |
|
|
|
|
|
|
|
protected MaterialProperty diffusionProfileID = null; |
|
|
|
protected const string kDiffusionProfileID = "_DiffusionProfile"; |
|
|
|
|
|
|
protected const string kUVDetail = "_UVDetail"; |
|
|
|
protected MaterialProperty UVDetailsMappingMask = null; |
|
|
|
protected const string kUVDetailsMappingMask = "_UVDetailsMappingMask"; |
|
|
|
|
|
|
|
protected MaterialProperty detailMask = null; |
|
|
|
protected const string kDetailMask = "_DetailMask"; |
|
|
|
protected const string kLinkDetailsWithBase = "_LinkDetailsWithBase"; |
|
|
|
protected const string kLinkDetailsWithBase = "_LinkDetailsWithBase"; |
|
|
|
|
|
|
|
protected MaterialProperty detailFuzz1 = null; |
|
|
|
protected const string kDetailFuzz1 = "_DetailFuzz1"; |
|
|
|
protected MaterialProperty detailAOScale = null; |
|
|
|
protected const string kDetailAOScale = "_DetailAOScale"; |
|
|
|
protected MaterialProperty detailNormalScale = null; |
|
|
|
|
|
|
protected MaterialProperty enableSpecularOcclusion = null; |
|
|
|
protected const string kEnableSpecularOcclusion = "_EnableSpecularOcclusion"; |
|
|
|
|
|
|
|
protected MaterialProperty enableSubsurfaceScattering = null; |
|
|
|
protected const string kEnableSubsurfaceScattering = "_EnableSubsurfaceScattering"; |
|
|
|
protected MaterialProperty enableTransmission = null; |
|
|
|
protected const string kEnableTransmission = "_EnableTransmission"; |
|
|
|
TexWorldScale = FindProperty(kTexWorldScale, props); |
|
|
|
InvTilingScale = FindProperty(kInvTilingScale, props); |
|
|
|
UVMappingMask = FindProperty(kUVMappingMask, props); |
|
|
|
|
|
|
|
baseColor = FindProperty(kBaseColor, props); |
|
|
|
|
|
|
bentNormalMap = FindProperty(kBentNormalMap, props); |
|
|
|
|
|
|
|
fuzzTint = FindProperty(kFuzzTint, props); |
|
|
|
clothType = FindProperty(kClothType, props); |
|
|
|
|
|
|
|
// Sub surface
|
|
|
|
diffusionProfileID = FindProperty(kDiffusionProfileID, props); |
|
|
|
|
|
|
UVDetail = FindProperty(kUVDetail, props); |
|
|
|
UVDetailsMappingMask = FindProperty(kUVDetailsMappingMask, props); |
|
|
|
linkDetailsWithBase = FindProperty(kLinkDetailsWithBase, props); |
|
|
|
|
|
|
|
detailMask = FindProperty(kDetailMask, props); |
|
|
|
detailFuzz1 = FindProperty(kDetailFuzz1, props); |
|
|
|
detailAOScale = FindProperty(kDetailAOScale, props); |
|
|
|
detailNormalScale = FindProperty(kDetailNormalScale, props); |
|
|
|
detailSmoothnessScale = FindProperty(kDetailSmoothnessScale, props); |
|
|
|
|
|
|
anisotropy = FindProperty(kAnisotropy, props); |
|
|
|
anisotropyMap = FindProperty(kAnisotropyMap, props); |
|
|
|
|
|
|
|
// toggle
|
|
|
|
enableSubsurfaceScattering = FindProperty(kEnableSubsurfaceScattering, props); |
|
|
|
enableTransmission = FindProperty(kEnableTransmission, props); |
|
|
|
protected void ShaderSSSAndTransmissionInputGUI(Material material, int layerIndex) |
|
|
|
protected void ShaderSSSAndTransmissionInputGUI(Material material) |
|
|
|
{ |
|
|
|
var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var scope = new EditorGUI.ChangeCheckScope()) |
|
|
|
{ |
|
|
|
int profileID = (int)diffusionProfileID[layerIndex].floatValue; |
|
|
|
int profileID = (int)diffusionProfileID.floatValue; |
|
|
|
|
|
|
|
using (new EditorGUILayout.HorizontalScope()) |
|
|
|
{ |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (scope.changed) |
|
|
|
diffusionProfileID[layerIndex].floatValue = profileID; |
|
|
|
diffusionProfileID.floatValue = profileID; |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
|
|
|
protected override void MaterialPropertiesGUI(Material material) |
|
|
|
{ |
|
|
|
GUILayout.Label("Fabric Options", EditorStyles.boldLabel); |
|
|
|
GUILayout.Label("Cloth Options", EditorStyles.boldLabel); |
|
|
|
m_MaterialEditor.ShaderProperty(fabricType, Styles.fabricTypeText); |
|
|
|
m_MaterialEditor.ShaderProperty(clothType, Styles.clothTypeText); |
|
|
|
EditorGUI.indentLevel--; |
|
|
|
m_MaterialEditor.ShaderProperty(fuzzTint, Styles.fuzzTintText); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapSpecularText, maskMap); |
|
|
|
|
|
|
|
m_MaterialEditor.ShaderProperty(normalMapSpace, Styles.normalMapSpaceText); |
|
|
|
|
|
|
|
ShaderSSSAndTransmissionInputGUI(material, layerIndex); |
|
|
|
ShaderSSSAndTransmissionInputGUI(material); |
|
|
|
ShaderAnisoInputGUI(); |
|
|
|
|
|
|
|
EditorGUILayout.Space(); |
|
|
|
|
|
|
|
|
|
|
UVMappingMask.colorValue = new Color(X, Y, Z, W); |
|
|
|
|
|
|
|
if ((uvBaseMapping == UVBaseMapping.Planar) || (uvBaseMapping == UVBaseMapping.Triplanar)) |
|
|
|
{ |
|
|
|
m_MaterialEditor.ShaderProperty(TexWorldScale, Styles.texWorldScaleText); |
|
|
|
} |
|
|
|
if (EditorGUI.EndChangeCheck()) |
|
|
|
{ |
|
|
|
// Precompute.
|
|
|
|
InvTilingScale.floatValue = 2.0f / (Mathf.Abs(baseColorMap.textureScaleAndOffset.x) + Mathf.Abs(baseColorMap.textureScaleAndOffset.y)); |
|
|
|
if ((uvBaseMapping == UVBaseMapping.Planar) || (uvBaseMapping == UVBaseMapping.Triplanar)) |
|
|
|
{ |
|
|
|
InvTilingScale.floatValue = InvTilingScale.floatValue / TexWorldScale.floatValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
EditorGUI.indentLevel--; |
|
|
|
EditorGUILayout.Space(); |
|
|
|
|
|
|
m_MaterialEditor.TexturePropertySingleLine(Styles.detailMaskText, detailMask); |
|
|
|
m_MaterialEditor.TexturePropertySingleLine(Styles.detailMapNormalText, detailMap); |
|
|
|
|
|
|
|
if (material.GetTexture(kDetailMap)) |
|
|
|
|
|
|
SetupBaseLitKeywords(material); |
|
|
|
SetupBaseLitMaterialPass(material); |
|
|
|
|
|
|
|
ClothType clothType = (ClothType)material.GetFloat(kClothType); |
|
|
|
CoreUtils.SetKeyword(material, "_FABRIC_SILK", clothType == ClothType.Silk); |
|
|
|
|
|
|
|
NormalMapSpace normalMapSpace = (NormalMapSpace)material.GetFloat(kNormalMapSpace); |
|
|
|
|
|
|
|
// With details map, we always use a normal map and Unity provide a default (0, 0, 1) normal map for it
|
|
|
|
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap) || material.GetTexture(kDetailMap)); |
|
|
|
CoreUtils.SetKeyword(material, "_TANGENTMAP", material.GetTexture(kTangentMap)); |
|
|
|
|
|
|
material.DisableKeyword("_REQUIRE_UV3"); |
|
|
|
} |
|
|
|
|
|
|
|
BaseLitGUI.MaterialId materialId = (BaseLitGUI.MaterialId)material.GetFloat(kMaterialID); |
|
|
|
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", materialId == BaseLitGUI.MaterialId.LitSSS); |
|
|
|
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", materialId == BaseLitGUI.MaterialId.LitTranslucent || (materialId == BaseLitGUI.MaterialId.LitSSS && material.GetFloat(kTransmissionEnable) > 0.0f)); |
|
|
|
|
|
|
|
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_ANISOTROPY", materialId == BaseLitGUI.MaterialId.LitAniso); |
|
|
|
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", material.GetFloat(kEnableSubsurfaceScattering) > 0.0f); |
|
|
|
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_TRANSMISSION", material.GetFloat(kEnableTransmission) > 0.0f); |
|
|
|
ClothType clothType = (ClothType)material.GetFloat(kClothType); |
|
|
|
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_ANISOTROPY", clothType == ClothType.Silk); |
|
|
|
} |
|
|
|
} |
|
|
|
} // namespace UnityEditor
|