浏览代码

Update UI for decal material based on artists feedback + add upgrader script

/main
sebastienlagarde 7 年前
当前提交
49764db8
共有 4 个文件被更改,包括 82 次插入45 次删除
  1. 84
      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. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/HDRPVersion.cs
  4. 35
      com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/UpgradeMenuItem.cs

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


{
public static string InputsText = "Inputs";
public static GUIContent baseColorText = new GUIContent("Albedo (RGB) and Blend Factor (A)", "Albedo (RGB) and Blend Factor (A)");
public static GUIContent baseColorText2 = new GUIContent("Blend Factor (A)", "Blend Factor (A)");
public static GUIContent baseColorText = new GUIContent("BaseColor (RGB) and Opacity (A)", "BaseColor (RGB) and Opacity (A)");
public static GUIContent baseColorText2 = new GUIContent("Opacity(A)", "Opacity (A)");
public static GUIContent maskMapText = new GUIContent("Mask Map - M(R), AO(G), D(B), S(A)", "Mask map");
public static GUIContent decalBlendText = new GUIContent("Decal Blend", "Whole decal blend");
public static GUIContent BlendText = new GUIContent("Decal Blend", "Whole decal blend");
public static GUIContent AlbedoModeText = new GUIContent("Albedo contribution", "Base color + Blend, Blend only");
public static GUIContent decalBlendText = new GUIContent("Global Opacity", "Whole decal Opacity");
public static GUIContent AlbedoModeText = new GUIContent("Affect BaseColor", "Base color + Opacity, Opacity only");
public static GUIContent[] maskMapText =
{
new GUIContent("Error", "Mask map"), // Not possible
new GUIContent("Mask Map - M(R), Opacity(B)", "Mask map - Metal(R), Opacity(B)"), // Decal.MaskBlendFlags.Metal:
new GUIContent("Mask Map - AO(G), Opacity(B)", "Mask map - Ambient Occlusion(G), Opacity(B)"), // Decal.MaskBlendFlags.AO:
new GUIContent("Mask Map - M(R), AO(G), Opacity(B)", "Mask map - Metal(R), Ambient Occlusion(G), Opacity(B)"), // Decal.MaskBlendFlags.Metal | Decal.MaskBlendFlags.AO:
new GUIContent("Mask Map - Opacity(B), S(A)", "Mask map - Opacity(B), Smoothness(A)"), // Decal.MaskBlendFlags.Smoothness:
new GUIContent("Mask Map - M(R), Opacity(B), S(A)", "Mask map - Metal(R), Opacity(B), Smoothness(A)"), // Decal.MaskBlendFlags.Metal | Decal.MaskBlendFlags.Smoothness:
new GUIContent("Mask Map - AO(G), Opacity(B), S(A)", "Mask map - Ambient Occlusion(G), Opacity(B), Smoothness(A)"), // Decal.MaskBlendFlags.AO | Decal.MaskBlendFlags.Smoothness:
new GUIContent("Mask Map - M(R), AO(G), Opacity(B), S(A)", "Mask map - Metal(R), Ambient Occlusion(G), Opacity(B), Smoothness(A)") // Decal.MaskBlendFlags.Metal | Decal.MaskBlendFlags.AO | Decal.MaskBlendFlags.Smoothness:
};
AlbedoMapAlpha,
BaseColorMapAlpha,
MaskMapBlue
}
protected string[] blendSourceNames = Enum.GetNames(typeof(BlendSource));

EditorGUILayout.LabelField(Styles.InputsText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(albedoMode, Styles.AlbedoModeText);
if (material.GetFloat(kAlbedoMode) == 1.0f)
m_MaterialEditor.TexturePropertySingleLine((material.GetFloat(kAlbedoMode) == 1.0f) ? Styles.baseColorText : Styles.baseColorText2, baseColorMap, baseColor);
if (material.GetTexture(kBaseColorMap))
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap, baseColor);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(albedoMode, Styles.AlbedoModeText);
EditorGUI.indentLevel--;
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText2, baseColorMap, baseColor);
}
normalBlendSrcValue = EditorGUILayout.Popup( "Normal blend source", (int)normalBlendSrcValue, blendSourceNames);
EditorGUI.indentLevel++;
normalBlendSrcValue = EditorGUILayout.Popup("Normal Opacity channel", (int)normalBlendSrcValue, blendSourceNames);
EditorGUI.indentLevel--;
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText[(int)maskBlendFlags], maskMap);
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);
}
EditorGUI.indentLevel++;
maskBlendSrcValue = EditorGUILayout.Popup("Mask Opacity channel", (int) maskBlendSrcValue, blendSourceNames);
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))
{
// Following condition force users to always have at least one attribute enabled
m_MaterialEditor.ShaderProperty(maskmapMetal, "Affect Metal");
if ((maskmapMetal.floatValue == 0.0f) && (maskmapAO.floatValue == 0.0f) && (maskmapSmoothness.floatValue == 0.0f))
maskmapMetal.floatValue = 1.0f;
m_MaterialEditor.ShaderProperty(maskmapAO, "Affect AO");
if ((maskmapMetal.floatValue == 0.0f) && (maskmapAO.floatValue == 0.0f) && (maskmapSmoothness.floatValue == 0.0f))
maskmapAO.floatValue = 1.0f;
m_MaterialEditor.ShaderProperty(maskmapSmoothness, "Affect Smoothness");
if ((maskmapMetal.floatValue == 0.0f) && (maskmapAO.floatValue == 0.0f) && (maskmapSmoothness.floatValue == 0.0f))
}
if (maskmapMetal.floatValue == 1.0f)
maskBlendFlags |= Decal.MaskBlendFlags.Metal;

maskBlendFlags |= Decal.MaskBlendFlags.Smoothness;
}
EditorGUI.indentLevel--;
EditorGUILayout.HelpBox(
"Control of AO and Metal is based on option 'Enable Metal and AO properties' in HDRP Asset.\nThere is a performance cost of enabling this option.",
MessageType.Info);
}
if (EditorGUI.EndChangeCheck())

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("Mask map channel selection"));
EditorGUILayout.PropertyField(d.perChannelMask, _.GetContent("Enable Metal and AO properties"));
--EditorGUI.indentLevel;
}
}

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/HDRPVersion.cs


[InitializeOnLoad]
public class HDRPVersion
{
static public int hdrpVersion = 1;
// 1 changed emissive color
// 2 add decal mode in decal material
static public int hdrpVersion = 2;
static public int GetCurrentHDRPProjectVersion()
{

static HDRPVersion()
{
// Compare project version with current version - Trigger an upgrade if user ask for it
if (GetCurrentHDRPProjectVersion() < hdrpVersion)
if (false) //GetCurrentHDRPProjectVersion() < hdrpVersion) // TODO: Disable for now as it doesn't work correctly
{
if (EditorUtility.DisplayDialog("A newer version of HDRP has been detected",
"Do you want to upgrade your materials to newer version?\n You can also upgrade manually materials in 'Edit -> Render Pipeline' submenu", "Yes", "No"))

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


return;
}
// Update decal material after we added AO and metal selection. It was default to 0 and need to default to 4 now.
static bool UpdateMaterial_DecalBlendMode(string path, Material mat)
{
if (mat.shader.name == "HDRenderPipeline/Decal")
{
float maskBlendMode = mat.GetFloat("_MaskBlendMode");
if (maskBlendMode == 0.0f)
{
mat.SetFloat("_MaskBlendMode", 4.0f);
return true;
}
}
return false;
}
delegate bool UpdateMaterial(string path, Material mat);
delegate void UpdateMaterialFile(string path);

mat.shader.name == "HDRenderPipeline/LayeredLit" ||
mat.shader.name == "HDRenderPipeline/LayeredLitTessellation" ||
mat.shader.name == "HDRenderPipeline/StackLit" ||
mat.shader.name == "HDRenderPipeline/Unlit"
mat.shader.name == "HDRenderPipeline/Unlit" ||
mat.shader.name == "HDRenderPipeline/Decal"
)
{
// Need to be processed in order - All function here should be re-entrant (i.e after upgrade it can be recall)

UpdateMaterialToNewerVersion("(EmissiveColor)", UpdateMaterial_EmissiveColor, UpdateMaterialFile_EmissiveColor);
}
[MenuItem("Edit/Render Pipeline/Single step upgrade script/Upgrade all DecalMaterial MaskBlendMode", priority = CoreUtils.editMenuPriority3)]
static public void UpdateMaterialToNewerVersionDecalMaterialMaskBlendMode()
{
UpdateMaterialToNewerVersion("(DecalMaterial)", UpdateMaterial_DecalBlendMode);
}
[MenuItem("Edit/Render Pipeline/Upgrade all Materials to latest version", priority = CoreUtils.editMenuPriority3)]
static public void UpdateMaterialToNewerVersion()
{

float currentVersion = HDRPVersion.GetCurrentHDRPProjectVersion();
if (currentVersion < 1.0)
int currentVersion = HDRPVersion.GetCurrentHDRPProjectVersion();
if (currentVersion < 1)
}
if (currentVersion < 2)
{
// Appear in hdrp version 2.0
UpdateMaterialToNewerVersion("(DecalMaterial)", UpdateMaterial_DecalBlendMode);
}
}
}
正在加载...
取消
保存