浏览代码

More work on cloth UI

/main
Anis Benyoub 6 年前
当前提交
949ce831
共有 8 个文件被更改,包括 148 次插入45 次删除
  1. 70
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Cloth/ClothUI.cs
  2. 5
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/BaseLitUI.cs
  3. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Unlit/BaseUnlitUI.cs
  4. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDEditorUtils.cs
  5. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/UpgradeMenuItem.cs
  6. 60
      com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/Cloth.shader
  7. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ClothData.hlsl
  8. 48
      com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ClothProperties.hlsl

70
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Cloth/ClothUI.cs


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

5
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/BaseLitUI.cs


EditorGUI.showMixedValue = false;
}
protected abstract void UpdateDisplacement();
protected virtual void UpdateDisplacement() {}
protected override void BaseMaterialPropertiesGUI()
{

{
SetupBaseUnlitKeywords(material);
if (material.HasProperty(kDoubleSidedEnable) && material.GetFloat(kDoubleSidedEnable) > 0.0f)
bool doubleSidedEnable = material.HasProperty(kDoubleSidedEnable) ? material.GetFloat(kDoubleSidedEnable) > 0.0f : false;
if (doubleSidedEnable)
{
DoubleSidedNormalMode doubleSidedNormalMode = (DoubleSidedNormalMode)material.GetFloat(kDoubleSidedNormalMode);
switch (doubleSidedNormalMode)

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Unlit/BaseUnlitUI.cs


protected abstract void FindMaterialProperties(MaterialProperty[] props);
protected abstract void SetupMaterialKeywordsAndPassInternal(Material material);
protected abstract void MaterialPropertiesGUI(Material material);
protected abstract void MaterialPropertiesAdvanceGUI(Material material);
protected virtual void MaterialPropertiesAdvanceGUI(Material material) {}
protected abstract bool ShouldEmissionBeEnabled(Material material);
protected virtual bool ShouldEmissionBeEnabled(Material material) { return false; }
protected virtual void FindBaseMaterialProperties(MaterialProperty[] props)
{

1
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDEditorUtils.cs


delegate void MaterialResetter(Material material);
static Dictionary<string, MaterialResetter> k_MaterialResetters = new Dictionary<string, MaterialResetter>()
{
{ "HDRenderPipeline/Cloth", ClothGUI.SetupMaterialKeywordsAndPass },
{ "HDRenderPipeline/LayeredLit", LayeredLitGUI.SetupMaterialKeywordsAndPass },
{ "HDRenderPipeline/LayeredLitTessellation", LayeredLitGUI.SetupMaterialKeywordsAndPass },
{ "HDRenderPipeline/Lit", LitGUI.SetupMaterialKeywordsAndPass },

1
com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/UpgradeMenuItem.cs


mat.shader.name == "HDRenderPipeline/LayeredLitTessellation" ||
mat.shader.name == "HDRenderPipeline/StackLit" ||
mat.shader.name == "HDRenderPipeline/Unlit" ||
mat.shader.name == "HDRenderPipeline/Cloth" ||
mat.shader.name == "HDRenderPipeline/Decal"
)
{

60
com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/Cloth.shader


_BaseColor("BaseColor", Color) = (1,1,1,1)
_BaseColorMap("BaseColorMap", 2D) = "white" {}
_Smoothness("Smoothness", Range(0.0, 1.0)) = 1.0
_MaskMap("MaskMap", 2D) = "white" {}
_SmoothnessRemapMin("SmoothnessRemapMin", Float) = 0.0
_SmoothnessRemapMax("SmoothnessRemapMax", Float) = 1.0
_AORemapMin("AORemapMin", Float) = 0.0
_AORemapMax("AORemapMax", Float) = 1.0
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_NormalScale("_NormalScale", Range(0.0, 2.0)) = 1
_BentNormalMap("_BentNormalMap", 2D) = "bump" {}
_FuzzTint("FuzzTint", Color) = (1.0, 1.0, 1.0)
[Enum(Silk, 0, CottonWool, 1)] _ClothType("Cloth Type", Float) = 0
_DetailMap("DetailMap", 2D) = "black" {}
_DetailMask("DetailMask", 2D) = "white" {}
_DetailFuzz1("_DetailFuzz1", Range(0.0, 1.0)) = 1
_DetailNormalScale("_DetailNormalScale", Range(0.0, 2.0)) = 1
_DetailSmoothnessScale("_DetailSmoothnessScale", Range(0.0, 2.0)) = 1
_TangentMap("TangentMap", 2D) = "bump" {}
_Anisotropy("Anisotropy", Range(-1.0, 1.0)) = 0
_AnisotropyMap("AnisotropyMap", 2D) = "white" {}
_DiffusionProfile("Diffusion Profile", Int) = 0
_SubsurfaceMask("Subsurface Radius", Range(0.0, 1.0)) = 1.0
_SubsurfaceMaskMap("Subsurface Radius Map", 2D) = "white" {}
_Thickness("Thickness", Range(0.0, 1.0)) = 1.0
_ThicknessMap("Thickness Map", 2D) = "white" {}
_ThicknessRemap("Thickness Remap", Vector) = (0, 1, 0, 0)
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _UVBase("UV Set for base", Float) = 0
[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0)
[ToggleUI] _EnableSpecularOcclusion("Enable specular occlusion", Float) = 0.0
[ToggleUI] _EnableSubsurfaceScattering("_EnableSubsurfaceScattering", Float) = 0.0
[ToggleUI] _EnableTransmission("_EnableTransmission", Float) = 0.0
// Transparency
[ToggleUI] _PreRefractionPass("PreRefractionPass", Float) = 0.0

#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _CLOTH_SILK
#pragma shader_feature _NORMALMAP
#pragma shader_feature _MASKMAP
#pragma shader_feature _BENTNORMALMAP
#pragma shader_feature _ENABLESPECULAROCCLUSION
#pragma shader_feature _TANGENTMAP
#pragma shader_feature _ANISOTROPYMAP
#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _SUBSURFACE_MASK_MAP
#pragma shader_feature _THICKNESSMAP
#pragma shader_feature _BLENDMODE_PRESERVE_SPECULAR_LIGHTING // easily handled in material.hlsl, so adding this already.
#pragma shader_feature _BLENDMODE_PRESERVE_SPECULAR_LIGHTING
// MaterialFeature are used as shader feature to allow compiler to optimize properly
#pragma shader_feature _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
#pragma shader_feature _MATERIAL_FEATURE_TRANSMISSION
#pragma shader_feature _MATERIAL_FEATURE_ANISOTROPY // Anisotropy is for Silk
//enable GPU instancing support
#pragma multi_compile_instancing

}
//CustomEditor "Experimental.Rendering.HDPipeline.ClothGUI"
CustomEditor "Experimental.Rendering.HDPipeline.ClothGUI"
}

4
com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ClothData.hlsl


// Builtin Data
builtinData.opacity = alpha;
builtinData.bakeDiffuseLighting = SampleBakedGI(input.positionWS, surfaceData.normalWS, input.texCoord1, input.texCoord2);
builtinData.bakeDiffuseLighting = SampleBakedGI(input.positionRWS, surfaceData.normalWS, input.texCoord1, input.texCoord2);
float4 shadowMask = SampleShadowMask(input.positionWS, input.texCoord1);
float4 shadowMask = SampleShadowMask(input.positionRWS, input.texCoord1);
builtinData.shadowMask0 = shadowMask.x;
builtinData.shadowMask1 = shadowMask.y;
builtinData.shadowMask2 = shadowMask.z;

48
com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ClothProperties.hlsl


TEXTURE2D(_BaseColorMap);
SAMPLER(sampler_BaseColorMap);
TEXTURE2D(_MaskMap);
SAMPLER(sampler_MaskMap);
TEXTURE2D(_BentNormalMap); // Reuse sampler from normal map
SAMPLER(sampler_BentNormalMap);
TEXTURE2D(_NormalMap);
SAMPLER(sampler_NormalMap);
TEXTURE2D(_DetailMask);
SAMPLER(sampler_DetailMask);
TEXTURE2D(_DetailMap);
SAMPLER(sampler_DetailMap);
TEXTURE2D(_TangentMap);
SAMPLER(sampler_TangentMap);
TEXTURE2D(_TangentMapOS);
SAMPLER(sampler_TangentMapOS);
TEXTURE2D(_AnisotropyMap);
SAMPLER(sampler_AnisotropyMap);
TEXTURE2D(_SubsurfaceMaskMap);
SAMPLER(sampler_SubsurfaceMaskMap);
TEXTURE2D(_ThicknessMap);
SAMPLER(sampler_ThicknessMap);
CBUFFER_START(UnityPerMaterial)
float4 _BaseColor;

float _AlphaCutoff;
float _EnableSpecularOcclusion;
float _Smoothness;
float _SmoothnessRemapMin;
float _SmoothnessRemapMax;
float _AORemapMin;
float _AORemapMax;
float _NormalScale;
float4 _DetailMap_ST;
float _DetailFuzz1;
float _DetailNormalScale;
float _DetailSmoothnessScale;
float _Anisotropy;
int _DiffusionProfile;
float _SubsurfaceMask;
float _Thickness;
float4 _ThicknessRemap;
CBUFFER_END
正在加载...
取消
保存