浏览代码

Change mask map channel selection to use check boxes

/main
Paul Melamed 7 年前
当前提交
40459f78
共有 3 个文件被更改,包括 60 次插入15 次删除
  1. 70
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs
  2. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/GlobalDecalSettingsUI.cs
  3. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader

70
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs


protected MaterialProperty maskBlendMode = new MaterialProperty();
protected const string kMaskBlendMode = "_MaskBlendMode";
protected MaterialProperty maskmapMetal = new MaterialProperty();
protected const string kMaskmapMetal = "_MaskmapMetal";
protected MaterialProperty maskmapAO = new MaterialProperty();
protected const string kMaskmapAO = "_MaskmapAO";
protected MaterialProperty maskmapSmoothness = new MaterialProperty();
protected const string kMaskmapSmoothness = "_MaskmapSmoothness";
protected MaterialEditor m_MaterialEditor;
// This is call by the inspector

normalBlendSrc = FindProperty(kNormalBlendSrc, props);
maskBlendSrc = FindProperty(kMaskBlendSrc, props);
maskBlendMode = FindProperty(kMaskBlendMode, props);
maskmapMetal = FindProperty(kMaskmapMetal, props);
maskmapAO = FindProperty(kMaskmapAO, props);
maskmapSmoothness = FindProperty(kMaskmapSmoothness, props);
// always instanced
SerializedProperty instancing = m_MaterialEditor.serializedObject.FindProperty("m_EnableInstancingVariants");

EditorGUIUtility.labelWidth = 0f;
float normalBlendSrcValue = normalBlendSrc.floatValue;
float maskBlendSrcValue = maskBlendSrc.floatValue;
float maskBlendModeValue = maskBlendMode.floatValue;
Decal.MaskBlendFlags maskBlendFlags = (Decal.MaskBlendFlags) maskBlendModeValue;
//float maskBlendModeValue = maskBlendMode.floatValue;
Decal.MaskBlendFlags maskBlendFlags = 0; //(Decal.MaskBlendFlags) maskBlendModeValue;
HDRenderPipelineAsset hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
bool perChannelMask = hdrp.renderPipelineSettings.decalSettings.perChannelMask;

{
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText2, baseColorMap, baseColor);
}
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
normalBlendSrcValue = EditorGUILayout.Popup( "Normal blend source", (int)normalBlendSrcValue, blendSourceNames);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
if (material.GetTexture(kNormalMap))
{
normalBlendSrcValue = EditorGUILayout.Popup( "Normal blend source", (int)normalBlendSrcValue, blendSourceNames);
}
maskBlendSrcValue = EditorGUILayout.Popup( "Mask blend source", (int)maskBlendSrcValue, blendSourceNames);
EditorGUILayout.HelpBox("Individual mask map channel blending mode can be enabled/disabled in pipeline asset.\nEnabling this feature incurs a performance cost.", MessageType.Info);
if(perChannelMask)
{
maskBlendFlags = (Decal.MaskBlendFlags)EditorGUILayout.EnumFlagsField( "Mask blend mode", maskBlendFlags);
if (maskBlendFlags == 0)
maskBlendFlags = Decal.MaskBlendFlags.Smoothness; // can not have nothing, to achieve this effect remove the mask map from shader
if (maskBlendFlags == (Decal.MaskBlendFlags)(-1)) // everything
maskBlendFlags = Decal.MaskBlendFlags.Metal | Decal.MaskBlendFlags.AO | Decal.MaskBlendFlags.Smoothness;
if (material.GetTexture(kMaskMap))
{
maskBlendSrcValue = EditorGUILayout.Popup("Mask blend source", (int) maskBlendSrcValue, blendSourceNames);
if (perChannelMask)
{
EditorGUILayout.HelpBox(
"Disabling all mask map channels defaults to smoothness only.\n" +
"To disable all channels remove the mask map from the shader.\n" +
"Mask map channel selection mode can be disabled in pipeline asset, when disabled only smoothness is active.\n" +
"Disabling mask map channel selection mode will improve performance.",
MessageType.Info);
}
else
{
EditorGUILayout.HelpBox(
"For better control of mask map channels enable mask map channel selection mode in pipeline asset.\nEnabling this feature incurs a performance cost.",
MessageType.Info);
}
if (perChannelMask)
{
m_MaterialEditor.ShaderProperty(maskmapMetal, "Metal");
m_MaterialEditor.ShaderProperty(maskmapAO, "AO");
m_MaterialEditor.ShaderProperty(maskmapSmoothness, "Smoothness");
if ((maskmapMetal.floatValue == 0.0f) && (maskmapAO.floatValue == 0.0f) &&
(maskmapSmoothness.floatValue == 0.0f))
{
maskmapSmoothness.floatValue = 1.0f;
}
if (maskmapMetal.floatValue == 1.0f)
maskBlendFlags |= Decal.MaskBlendFlags.Metal;
if (maskmapAO.floatValue == 1.0f)
maskBlendFlags |= Decal.MaskBlendFlags.AO;
if (maskmapSmoothness.floatValue == 1.0f)
maskBlendFlags |= Decal.MaskBlendFlags.Smoothness;
}
}
m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText);
EditorGUI.indentLevel--;

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/GlobalDecalSettingsUI.cs


EditorGUILayout.PropertyField(d.drawDistance, _.GetContent("Draw Distance"));
EditorGUILayout.PropertyField(d.atlasWidth, _.GetContent("Atlas Width"));
EditorGUILayout.PropertyField(d.atlasHeight, _.GetContent("Atlas Height"));
EditorGUILayout.PropertyField(d.perChannelMask, _.GetContent("Per Channel Mask"));
EditorGUILayout.PropertyField(d.perChannelMask, _.GetContent("Mask map channel selection"));
--EditorGUI.indentLevel;
}
}

3
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader


[HideInInspector] _NormalBlendSrc("_NormalBlendSrc", Float) = 0.0
[HideInInspector] _MaskBlendSrc("_MaskBlendSrc", Float) = 1.0
[HideInInspector] _MaskBlendMode("_MaskBlendMode", Float) = 4.0 // smoothness 3RT default
[ToggleUI] _MaskmapMetal("_MaskmapMetal", Range(0.0, 1.0)) = 0.0
[ToggleUI] _MaskmapAO("_MaskmapAO", Range(0.0, 1.0)) = 0.0
[ToggleUI] _MaskmapSmoothness("_MaskmapSmoothness", Range(0.0, 1.0)) = 1.0
}
HLSLINCLUDE

正在加载...
取消
保存