浏览代码

Misc usability fixes for shadergraph:

-cubmap / texture -> convert to / from properties
-Removing properties not creates inline nodes
-Nicer names for newly created properties
-Drag texture to graph now creates 2d sampler node
-Drat normal map to graph sets up 'normal map' state
-Create shader graph now creats a default PBR node
-
/main
Tim Cooper 7 年前
当前提交
4eb8bc6a
共有 18 个文件被更改,包括 100 次插入28 次删除
  1. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderGraph.cs
  2. 19
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  3. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorShaderProperty.cs
  4. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapShaderProperty.cs
  5. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/FloatShaderProperty.cs
  6. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TextureShaderProperty.cs
  7. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2ShaderProperty.cs
  8. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3ShaderProperty.cs
  9. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4ShaderProperty.cs
  10. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/PBRMasterNode.cs
  11. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapAssetNode.cs
  12. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Texture2DAssetNode.cs
  13. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Texture2DNode.cs
  14. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  15. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs
  16. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/GraphDropTarget.cs
  17. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  18. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderGraph.cs


using System.IO;
using UnityEditor.ProjectWindowCallback;
using UnityEditor.ShaderGraph;
namespace UnityEditor.ShaderGraph
{

public override void Action(int instanceId, string pathName, string resourceFile)
{
var graph = new ShaderGraph.MaterialGraph();
//graph.AddNode(new LightweightMetallicMasterNode());
var graph = new MaterialGraph();
graph.AddNode(new PBRMasterNode());
File.WriteAllText(pathName, EditorJsonUtility.ToJson(graph));
AssetDatabase.Refresh();
}

19
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


void RemoveShaderPropertyNoValidate(Guid guid)
{
var propertyNodes = GetNodes<PropertyNode>().Where(x => x.propertyGuid == guid).ToList();
foreach (var propNode in propertyNodes)
ReplacePropertyNodeWithConcreteNode(propNode);
if (m_Properties.RemoveAll(x => x.guid == guid) > 0)
m_RemovedProperties.Add(guid);
}

var createdNode = new ColorNode();
createdNode.color = ((ColorShaderProperty) property).value;
slotId = ColorNode.OutputSlotId;
node = createdNode;
}
else if (property is TextureShaderProperty)
{
var createdNode = new Texture2DAssetNode();
createdNode.texture = ((TextureShaderProperty) property).value.texture;
slotId = Texture2DAssetNode.OutputSlotId;
node = createdNode;
}
else if (property is CubemapShaderProperty)
{
var createdNode = new CubemapAssetNode();
createdNode.cubemap = ((CubemapShaderProperty) property).value.cubemap;
slotId = CubemapAssetNode.OutputSlotId;
node = createdNode;
}

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorShaderProperty.cs


}
}
public ColorShaderProperty()
{
displayName = "Color";
}
public override PropertyType propertyType
{
get { return PropertyType.Color; }

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapShaderProperty.cs


public CubemapShaderProperty()
{
value = new SerializableCubemap();
displayName = "Cubemap";
}
public override PropertyType propertyType

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/FloatShaderProperty.cs


[Serializable]
public class FloatShaderProperty : AbstractShaderProperty<float>
{
public FloatShaderProperty()
{
displayName = "Float";
}
public override PropertyType propertyType
{
get { return PropertyType.Float; }

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TextureShaderProperty.cs


public TextureShaderProperty()
{
value = new SerializableTexture();
displayName = "Texture";
}
public override PropertyType propertyType

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2ShaderProperty.cs


[Serializable]
public class Vector2ShaderProperty : VectorShaderProperty
{
public Vector2ShaderProperty()
{
displayName = "Vector2";
}
public override PropertyType propertyType
{
get { return PropertyType.Vector2; }

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3ShaderProperty.cs


[Serializable]
public class Vector3ShaderProperty : VectorShaderProperty
{
public Vector3ShaderProperty()
{
displayName = "Vector3";
}
public override PropertyType propertyType
{
get { return PropertyType.Vector3; }

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4ShaderProperty.cs


[Serializable]
public class Vector4ShaderProperty : VectorShaderProperty
{
public Vector4ShaderProperty()
{
displayName = "Vector4";
}
public override PropertyType propertyType
{
get { return PropertyType.Vector4; }

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/PBRMasterNode.cs


AddSlot(new Vector3MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, new Vector4(0.5f, 0.5f, 0.5f), ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, new Vector3(0, 0, 1), ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0, ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment));
if (model == Model.Metallic)
AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0, ShaderStage.Fragment));
else
AddSlot(new Vector3MaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, 1f, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1f, ShaderStage.Fragment));

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapAssetNode.cs


namespace UnityEditor.ShaderGraph
{
[Title("Input/Texture/Cubemap Asset")]
public class CubemapAssetNode : AbstractMaterialNode
public class CubemapAssetNode : AbstractMaterialNode, IPropertyFromNode
{
public const int OutputSlotId = 0;

m_Cubemap = cubemap
});
}
public IShaderProperty AsShaderProperty()
{
var prop = new CubemapShaderProperty();
prop.value = m_Cubemap;
if (cubemap != null)
prop.displayName = cubemap.name;
return prop;
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Texture2DAssetNode.cs


namespace UnityEditor.ShaderGraph
{
[Title("Input/Texture/Texture 2D Asset")]
public class Texture2DAssetNode : AbstractMaterialNode
public class Texture2DAssetNode : AbstractMaterialNode, IPropertyFromNode
{
public const int OutputSlotId = 0;

m_Texture = texture
});
}
public IShaderProperty AsShaderProperty()
{
var prop = new TextureShaderProperty();
prop.value = m_Texture;
if (texture != null)
prop.displayName = texture.name;
return prop;
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Texture2DNode.cs


using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs


using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEngine.AI;
namespace UnityEditor.ShaderGraph.Drawing.Inspector
{

PreviewTextureView m_PreviewTextureView;
AbstractMaterialGraph m_Graph;
PreviewManager m_PreviewManager;
MasterNode m_MasterNode;
PreviewRenderData m_PreviewRenderHandle;

persistenceKey = "GraphInspector";
m_Graph = graph;
m_PreviewManager = previewManager;
m_SelectedNodes = new List<INode>();
AddStyleSheetPath("Styles/MaterialGraph");

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs


using System;
using UnityEditor.Experimental.UIElements;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEditor.ShaderGraph;
using Object = UnityEngine.Object;
namespace UnityEditor.ShaderGraph.Drawing.Inspector

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/GraphDropTarget.cs


using System.Linq;
using UnityEngine;
using UnityEngine;
using UnityEditor.ShaderGraph;
namespace UnityEditor.ShaderGraph.Drawing
{

if (texture2D != null)
{
m_Graph.owner.RegisterCompleteObjectUndo("Drag Texture");
var property = new TextureShaderProperty { displayName = texture2D.name, value = { texture = texture2D } };
m_Graph.AddShaderProperty(property);
var node = new PropertyNode();
bool isNormalMap = false;
if (EditorUtility.IsPersistent(texture2D)
&& !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(texture2D)))
{
var importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture2D)) as TextureImporter;
if (importer != null)
isNormalMap = importer.textureType == TextureImporterType.NormalMap;
}
var node = new Texture2DNode();
if (isNormalMap)
node.textureType = TextureType.Normal;
node.propertyGuid = property.guid;
var inputslot = node.FindSlot<Texture2DInputMaterialSlot>(Texture2DNode.TextureInputId);
if (inputslot != null)
inputslot.texture = texture2D;
}
var cubemap = obj as Cubemap;

var property = new CubemapShaderProperty { displayName = cubemap.name, value = { cubemap = cubemap } };
m_Graph.AddShaderProperty(property);
var node = new PropertyNode();
var node = new CubemapNode();
node.propertyGuid = property.guid;
var inputslot = node.FindSlot<CubemapInputMaterialSlot>(CubemapNode.CubemapInputId);
if (inputslot != null)
inputslot.cubemap = cubemap;
}
var subGraphAsset = obj as MaterialSubGraphAsset;

Object draggedObject = null;
foreach (var obj in objects)
{
Debug.Log(obj.GetType().Name);
if (ValidateObject(obj))
{
draggedObject = obj;

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


{
var nodeView = new MaterialNodeView { userData = node };
m_GraphView.AddElement(nodeView);
nodeView.Initialize(m_GraphView, node as AbstractMaterialNode, m_PreviewManager);
nodeView.Initialize(node as AbstractMaterialNode, m_PreviewManager);
node.onModified += OnNodeChanged;
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


VisualElement m_ControlsContainer;
VisualElement m_PreviewContainer;
List<Attacher> m_Attachers;
GraphView m_GraphView;
public void Initialize(GraphView graphView, AbstractMaterialNode inNode, PreviewManager previewManager)
public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManager)
{
AddToClassList("MaterialNode");

m_GraphView = graphView;
node = inNode;
persistenceKey = node.guid.ToString();
UpdateTitle();

正在加载...
取消
保存