From b08c5f3e6c71b6d8cfb14f4c7f1903747f7e2ca2 Mon Sep 17 00:00:00 2001 From: Reach Platform Support Date: Tue, 10 Sep 2024 19:50:57 +0000 Subject: [PATCH] [Port] [2021.3] Fixed the BlockNode to display the name using DisplayName. Jira: https://jira.unity3d.com/browse/UUM-76081 Added a displayName to AbstractMaterialNode to use when displaying it in the Graph Inspector. displayName defaults to name, and is overridden by BlockNode to create it using shaderStage and displayName. ![image](https://media.github.cds.internal.unity3d.com/user/761/files/74c417ea-4dc5-43e9-8637-65ecb678eb63) The changed name looks like this:
BeforeAfter
VertexDescription.Position NodeVertex Position Node
VertexDescription.Normal NodeVertex Normal Node
VertexDescription.Tangent NodeVertex Tangent Node
SurfaceDescription.BaseColor NodeFragment Base Color Node
SurfaceDescription.NormalTS NodeFragment Normal (Tangent Space) Node
SurfaceDescription.Metalilc NodeFragment Metallic Node
SurfaceDescription.Smoothness NodeFragment Smoothness Node
SurfaceDescription.Emission NodeFragment Emissiton Node
SurfaceDescription.Occlusion NodeFragment Ambient Occlusion Node
--- .../Editor/Data/Nodes/AbstractMaterialNode.cs | 2 ++ .../Editor/Data/Nodes/BlockNode.cs | 18 +++++++++++++++++- .../AbstractMaterialNodePropertyDrawer.cs | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Packages/com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs b/Packages/com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs index 3fcb143beae..afb4a1ec6cf 100644 --- a/Packages/com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs +++ b/Packages/com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs @@ -80,6 +80,8 @@ public string name set { m_Name = value; } } + public virtual string displayName => name; + public string[] synonyms; protected virtual string documentationPage => name; diff --git a/Packages/com.unity.shadergraph/Editor/Data/Nodes/BlockNode.cs b/Packages/com.unity.shadergraph/Editor/Data/Nodes/BlockNode.cs index de869fd7531..9898068ed2f 100644 --- a/Packages/com.unity.shadergraph/Editor/Data/Nodes/BlockNode.cs +++ b/Packages/com.unity.shadergraph/Editor/Data/Nodes/BlockNode.cs @@ -28,6 +28,23 @@ class BlockNode : AbstractMaterialNode [NonSerialized] BlockFieldDescriptor m_Descriptor; + public override string displayName + { + get + { + string displayName = ""; + if (m_Descriptor != null) + { + displayName = m_Descriptor.shaderStage.ToString(); + if (!string.IsNullOrEmpty(displayName)) + displayName += " "; + displayName += m_Descriptor.displayName; + } + + return displayName; + } + } + public override bool canCutNode => false; public override bool canCopyNode => false; @@ -78,7 +95,6 @@ public void Init(BlockFieldDescriptor fieldDescriptor) ? $"{fieldDescriptor.tag}.{fieldDescriptor.name}" : $"{BlockFields.VertexDescription.name}.{k_CustomBlockDefaultName}"; - // TODO: This exposes the MaterialSlot API // TODO: This needs to be removed but is currently required by HDRP for DiffusionProfileInputMaterialSlot if (m_Descriptor is CustomSlotBlockFieldDescriptor customSlotDescriptor) diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/AbstractMaterialNodePropertyDrawer.cs b/Packages/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/AbstractMaterialNodePropertyDrawer.cs index fd57efc6d23..aa9625c81cf 100644 --- a/Packages/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/AbstractMaterialNodePropertyDrawer.cs +++ b/Packages/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/AbstractMaterialNodePropertyDrawer.cs @@ -38,7 +38,7 @@ internal virtual void AddCustomNodeProperties(VisualElement parentElement, Abstr VisualElement CreateGUI(AbstractMaterialNode node, InspectableAttribute attribute, out VisualElement propertyVisualElement) { VisualElement nodeSettings = new VisualElement(); - var nameLabel = PropertyDrawerUtils.CreateLabel($"{node.name} Node", 0, FontStyle.Bold); + var nameLabel = PropertyDrawerUtils.CreateLabel($"{node.displayName} Node", 0, FontStyle.Bold); nodeSettings.Add(nameLabel); if (node.sgVersion < node.latestVersion) {