浏览代码

[Format]Run code formatting

/main
Tim Cooper 8 年前
当前提交
553fedbf
共有 93 个文件被更改,包括 445 次插入471 次删除
  1. 13
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/CopySelected.cs
  2. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs
  3. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs
  4. 19
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs
  5. 17
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
  6. 3
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs
  7. 3
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs
  8. 3
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs
  9. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/GUIModificationType.cs
  10. 40
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/IntegrationTests/SerializationTests.cs
  11. 65
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/UnitTests/SerializedGraphTests.cs
  12. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/SerializableGraphAsset.cs
  13. 10
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs
  14. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
  15. 14
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs
  16. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableSlot.cs
  17. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/DrawingData.cs
  18. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/IGraph.cs
  19. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/INode.cs
  20. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/SlotReference.cs
  21. 29
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/SerializationHelper.cs
  22. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphStyles.cs
  23. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/AbstractMaterialNodeUI.cs
  24. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/ColorNodeUI.cs
  25. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/CombineNodeUI.cs
  26. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/PixelShaderNodeUI.cs
  27. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphIONodeUI.cs
  28. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphNodeUI.cs
  29. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/TextureNodeUI.cs
  30. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector1NodeUI.cs
  31. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector2NodeUI.cs
  32. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector3NodeUI.cs
  33. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector4NodeUI.cs
  34. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/SimpleWidgets.cs
  35. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Editors/MaterialGraphEditor.cs
  36. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs
  37. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/AbstractMaterialGraphTests.cs
  38. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/FixedSlotTests.cs
  39. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs
  40. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs
  41. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs
  42. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialGraphTests.cs
  43. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs
  44. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PixelShaderNodeTests.cs
  45. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs
  46. 28
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs
  47. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs
  48. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraph.cs
  49. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraphAsset.cs
  50. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialSubGraphAsset.cs
  51. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/PixelGraph.cs
  52. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Light/BaseLightFunction.cs
  53. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Light/PBRMetalicLightFunction.cs
  54. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Light/PBRSpecularLightFunction.cs
  55. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbsoluteNode.cs
  56. 26
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
  57. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/BlendNode.cs
  58. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ColorNode.cs
  59. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/CombineNode.cs
  60. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DivNode.cs
  61. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function1Input.cs
  62. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function2Input.cs
  63. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function3Input.cs
  64. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LengthNode.cs
  65. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
  66. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MinNode.cs
  67. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MultiplyNode.cs
  68. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalNode.cs
  69. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalizeNode.cs
  70. 62
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PixelShaderNode.cs
  71. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PowerNode.cs
  72. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs
  73. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ReflectNode.cs
  74. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ScreenPosNode.cs
  75. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SinTimeNode.cs
  76. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SlotValue.cs
  77. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SmoothStepNode.cs
  78. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs
  79. 62
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
  80. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TimeNode.cs
  81. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs
  82. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UnpackNormalNode.cs
  83. 18
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs
  84. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector2Node.cs
  85. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector3Node.cs
  86. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector4Node.cs
  87. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ViewDirectionNode.cs
  88. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/WorldPosNode.cs
  89. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraph.cs
  90. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphInputNode.cs
  91. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs
  92. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphOutputNode.cs
  93. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs

13
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/CopySelected.cs


{
m_Nodes.Add(node);
}
public void AddEdge(IEdge edge)
{
m_Edges.Add(edge);

if (e.commandName != "Copy" && e.commandName != "Paste" && e.commandName != "Duplicate")
return false;
e.Use();
return true;
}

EditorGUIUtility.systemCopyBuffer = SerializeSelectedElements(parent);
}
public static string SerializeSelectedElements(Canvas2D parent)
{
var selectedElements = parent.selection;

return null;
}
}
if (parent.dataSource == null)
return;

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs


if (e.commandName != "Delete" && e.commandName != "SoftDelete")
return false;
if (m_DeletionCallback != null)
{
m_DeletionCallback(parent.selection);

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs


public class DrawableNode : CanvasElement
{
private readonly GraphDataSource m_Data;
private readonly Rect m_CustomUiRect;
public readonly INode m_Node;
private readonly ICustomNodeUi m_Ui;

m_CustomUiRect = new Rect(10, pos.y, width - 20, customUiHeight);
pos.y += customUiHeight;
}
scale = new Vector3(pos.x, pos.y + 10.0f, 0.0f);
OnWidget += InvalidateUIIfNeedsTime;

}
private bool InvalidateUIIfNeedsTime(CanvasElement element, Event e, Canvas2D parent)
{
var childrenNodes = ListPool<INode>.Get();

m_Node.owner.ValidateGraph();
ParentCanvas().Invalidate();
ParentCanvas().ReloadData();
ParentCanvas().Repaint();
ParentCanvas().Repaint();
return;
}

19
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs


[AttributeUsage(AttributeTargets.Class)]
sealed class CustomNodeUI : Attribute
{
private Type m_ModeToDrawFor ;
private Type m_ModeToDrawFor;
public CustomNodeUI(Type nodeToDrawFor)
{

public Type nodeToDrawFor
{
get { return m_ModeToDrawFor; } }
get { return m_ModeToDrawFor; } }
public IGraphAsset graphAsset { get; set; }
public ICollection<DrawableNode> lastGeneratedNodes

var baseNode = drawableMaterialNode.m_Node;
foreach (var slot in baseNode.GetOutputSlots<ISlot>())
{
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == slot);
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor)x).m_Slot == slot);
var edges = baseNode.owner.GetEdges(new SlotReference(baseNode.guid, slot.id));
foreach (var edge in edges)

var targetNode = m_DrawableNodes.FirstOrDefault(x => x.m_Node == toNode);
var targetAnchor = (NodeAnchor)targetNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == toSlot);
var targetAnchor = (NodeAnchor)targetNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor)x).m_Slot == toSlot);
// Add proxy inputs for when edges are not connect
var nullInputSlots = new List<NullInputProxy>();
foreach (var drawableMaterialNode in m_DrawableNodes)

toReturn.AddRange(m_DrawableNodes.Select(x => (CanvasElement)x));
toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x));
toReturn.AddRange(nullInputSlots.Select(x => (CanvasElement)x));
//toReturn.Add(new FloatingPreview(new Rect(Screen.width - 300, Screen.height - 300, 300, 300), pixelGraph.nodes.FirstOrDefault(x => x is PixelShaderNode)));
Debug.LogFormat("Returning {0} nodes", m_DrawableNodes.Count);

foreach (var e in elements.OfType<Edge<NodeAnchor>>())
{
//find the edge
var edge = graph.edges.FirstOrDefault(x => graph.GetNodeFromGuid(x.outputSlot.nodeGuid).FindOutputSlot<ISlot>(x.outputSlot.slotId) == e.Left.m_Slot
&& graph.GetNodeFromGuid(x.inputSlot.nodeGuid).FindInputSlot<ISlot>(x.inputSlot.slotId) == e.Right.m_Slot);
var edge = graph.edges.FirstOrDefault(x => graph.GetNodeFromGuid(x.outputSlot.nodeGuid).FindOutputSlot<ISlot>(x.outputSlot.slotId) == e.Left.m_Slot
&& graph.GetNodeFromGuid(x.inputSlot.nodeGuid).FindInputSlot<ISlot>(x.inputSlot.slotId) == e.Right.m_Slot);
toRemoveEdge.Add(edge);
}

Invalidate();
canvas.Repaint();
}*/
}
}

17
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs


[SerializeField]
private ScriptableObject m_LastSelectedGraphSerialized;
[NonSerialized]
private Canvas2D m_Canvas;
[NonSerialized]

private bool shouldRepaint
{
get

{
if (Selection.activeObject == null || !EditorUtility.IsPersistent(Selection.activeObject))
return;
if (Selection.activeObject is ScriptableObject)
{
var selection = Selection.activeObject as T;

m_Canvas.AddManipulator(new RectangleSelect());
m_Canvas.AddManipulator(new ScreenSpaceGrid());
m_Canvas.AddManipulator(new ContextualMenu(DoContextMenu));
m_Canvas.AddManipulator(new DeleteSelected(m_DataSource.DeleteElements));
m_Canvas.AddManipulator(new CopySelected());
}

}
//gm.AddSeparator("");
// gm.AddItem(new GUIContent("Convert To/SubGraph"), true, ConvertSelectionToSubGraph);
// gm.AddItem(new GUIContent("Convert To/SubGraph"), true, ConvertSelectionToSubGraph);
gm.ShowAsContext();
return true;
}

}
}
// we do a grouping here as the same output can
// we do a grouping here as the same output can
// point to multiple inputs
var uniqueOutputs = outputEdgeNeedsRemap.GroupBy(edge => edge.outputSlot);
var inputsNeedingConnection = new List<KeyValuePair<IEdge, IEdge>>();

GUILayout.Label("No Graph selected");
return;
}
m_Canvas.OnGUI(this, new Rect(0, 0, position.width - 250, position.height));
if (GUI.Button(new Rect(position.width - 250, 0, 250, 50), "Convert to Sub-Graph"))

m_NodeExpanded = MaterialGraphStyles.Header("Selected", m_NodeExpanded);
if (m_NodeExpanded)
DrawableMaterialNode.OnGUI(m_Canvas.selection);
GUILayout.EndScrollView();
if (GUILayout.Button("Export"))
m_DataSource.Export(false);

m_LastSelectedGraphSerialized = null;
}
}
}

3
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs


using UnityEngine;
namespace UnityEditor.Graphing.Drawing
{
{
internal class PortSource<T>
{
}

// run adapt code for vec3 to Color connections
return true;
}
internal static bool Adapt(this NodeAdapter value, PortSource<Vector4> a, PortSource<Vector4> b)
{
// run adapt code for vec3 to Color connections

3
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs


AddManipulator(new EdgeConnector<NodeAnchor>());
m_Direction = direction;
Type genericClass = typeof (PortSource<>);
Type genericClass = typeof(PortSource<>);
Type constructedClass = genericClass.MakeGenericType(type);
m_Source = Activator.CreateInstance(constructedClass);
m_Data = data;

ParentCanvas().ReloadData();
}
};
}

3
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs


translation = position;
AddManipulator(new ImguiContainer());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{

var position = m_NodeAnchor.canvasBoundingRect.min;
position.x -= kWidth;
translation = position;
var rect = new Rect(0, 0, scale.x, scale.y);
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f));

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/GUIModificationType.cs


Repaint = 1 << 0,
// something structurally changed, rebuild the graph from scratch!
ModelChanged = 1 << 1,
// some data internally to the node was modified
// some data internally to the node was modified
// that dependent nodes may use.
DataChanged = 1 << 2
}

40
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/IntegrationTests/SerializationTests.cs


get
{
return new SimpleSerializeClass
{
stringValue = "ABCD",
intValue = 5,
floatValue = 7.7f,
arrayValue = new[] {1, 2, 3, 4}
};
{
stringValue = "ABCD",
intValue = 5,
floatValue = 7.7f,
arrayValue = new[] {1, 2, 3, 4}
};
}
}

get
{
return new ChildClassA
{
stringValue = "qwee",
intValue = 5,
floatValue = 6f,
arrayValue = new[] {5, 6, 7, 8},
childString = "CHILD"
};
{
stringValue = "qwee",
intValue = 5,
floatValue = 6f,
arrayValue = new[] {5, 6, 7, 8},
childString = "CHILD"
};
}
}

get
{
return new ChildClassB
{
stringValue = "qwee",
intValue = 5,
floatValue = 6f,
arrayValue = new[] {5, 6, 7, 8},
childInt = 666
};
{
stringValue = "qwee",
intValue = 5,
floatValue = 6f,
arrayValue = new[] {5, 6, 7, 8},
childInt = 666
};
}
}

65
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/UnitTests/SerializedGraphTests.cs


graph.RemoveNode(graph.GetNodes<INode>().FirstOrDefault());
Assert.AreEqual(0, graph.GetNodes<INode>().Count());
}
[Test]
public void TestCanModifyNodeDrawState()
{

var drawState = node.drawState;
var newPos = new Rect(10,10,10,10);
var newPos = new Rect(10, 10, 10, 10);
drawState.position = newPos;
drawState.expanded = false;
node.drawState = drawState;

{
hasError = true;
}
public void ClearError()
{
hasError = false;

Assert.AreNotEqual(guid, newGuid);
}
public class TestableNode : SerializableNode
{
public const int Input0 = 0;

var node = new OnEnableNode();
node.name = "Test Node";
graph.AddNode(node);
Assert.IsFalse(node.called);
graph.OnEnable();
Assert.IsTrue(node.called);

Assert.AreEqual(3, node.GetInputSlots<ISlot>().Count());
Assert.AreEqual(3, node.GetOutputSlots<ISlot>().Count());
node.RemoveSlotsNameNotMatching(new []{TestableNode.Input1});
node.RemoveSlotsNameNotMatching(new[] {TestableNode.Input1});
Assert.AreEqual(1, node.GetSlots<ISlot>().Count());
Assert.AreEqual(1, node.GetInputSlots<ISlot>().Count());

Assert.AreEqual(5, slot.priority);
}
[Test]
public void TestCanUpdateSlotDisplayName()
{

Assert.AreEqual(0, node.GetInputSlots<ISlot>().Count());
Assert.AreEqual(1, node.GetOutputSlots<ISlot>().Count());
Assert.AreEqual(1, node.GetSlots<ISlot>().Count());

var inputNode = new TestableNode();
graph.AddNode(inputNode);
Assert.AreEqual(3, graph.GetNodes<INode>().Count());
graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), middleNode.GetSlotReference(TestableNode.Input0));

Assert.AreEqual(2, graph.edges.Count());
var edgesOnMiddleNode = NodeUtils.GetAllEdges(middleNode);
Assert.AreEqual(2, edgesOnMiddleNode.Count());

result.Clear();
NodeUtils.DepthFirstCollectNodesFromNode(result, inputNode, TestableNode.Input1, NodeUtils.IncludeSelf.Exclude);
Assert.AreEqual(0, result.Count);
result.Clear();
NodeUtils.DepthFirstCollectNodesFromNode(result, null);
Assert.AreEqual(0, result.Count);

{
var node = new TestableNode();
Assert.DoesNotThrow(
() =>
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(
node,
new[] {TestableNode.Input0, TestableNode.Input1, TestableNode.Input2},
new[] {TestableNode.Output0, TestableNode.Output1, TestableNode.Output2,})
() =>
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(
node,
new[] {TestableNode.Input0, TestableNode.Input1, TestableNode.Input2},
new[] {TestableNode.Output0, TestableNode.Output1, TestableNode.Output2, })
() =>
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(
node,
new[] {666, TestableNode.Input1, TestableNode.Input2},
new[] {TestableNode.Output0, TestableNode.Output1, TestableNode.Output2,})
() =>
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(
node,
new[] {666, TestableNode.Input1, TestableNode.Input2},
new[] {TestableNode.Output0, TestableNode.Output1, TestableNode.Output2, })
() =>
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(
node,
new[] {TestableNode.Input0, TestableNode.Input1, TestableNode.Input2},
new[] {666, TestableNode.Output1, TestableNode.Output2,})
() =>
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(
node,
new[] {TestableNode.Input0, TestableNode.Input1, TestableNode.Input2},
new[] {666, TestableNode.Output1, TestableNode.Output2, })
() =>
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(
node,
new[] {TestableNode.Input0},
new[] {TestableNode.Output0})
() =>
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(
node,
new[] {TestableNode.Input0},
new[] {TestableNode.Output0})
);
}

var slots = inputNode.GetInputsWithNoConnection();
Assert.AreEqual(2, slots.Count());
CollectionAssert.AreEqual(new [] { TestableNode.Input1, TestableNode.Input2 }, slots.Select(x => x.id));
CollectionAssert.AreEqual(new[] { TestableNode.Input1, TestableNode.Input2 }, slots.Select(x => x.id));
}
[Test]

var nodeA = new TestableNode();
Assert.AreEqual(2, graph.GetNodes<INode>().Count());
graph.Connect(nodeA.GetSlotReference(TestableNode.Output0), nodeB.GetSlotReference(TestableNode.Input0));
Assert.AreEqual(1, graph.edges.Count());

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/SerializableGraphAsset.cs


{
[SerializeField]
private SerializableGraph m_Graph = new SerializableGraph();
public IGraph graph
{
get { return m_Graph; }

10
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs


{
public SlotConfigurationException(string message)
: base(message)
{ }
{}
public static void SlotConfigurationExceptionIfBadConfiguration(INode node, IEnumerable<int> expectedInputSlots, IEnumerable<int> expectedOutputSlots )
public static void SlotConfigurationExceptionIfBadConfiguration(INode node, IEnumerable<int> expectedInputSlots, IEnumerable<int> expectedOutputSlots)
{
var missingSlots = new List<int>();

return;
var toPrint = missingSlots.Select(x => x.ToString());
throw new SlotConfigurationException(string.Format("Missing slots {0} on node {1}", string.Join(", ", toPrint.ToArray()), node));
}

// allready added this node
if (nodeList.Contains(node))
return;
// if we have a slot passed in but can not find it on the node abort
if (slotId.HasValue && node.GetInputSlots<ISlot>().All(x => x.id != slotId.Value))
return;

validSlots.Add(slotId.Value);
else
validSlots.AddRange(node.GetInputSlots<ISlot>().Select(x => x.id));
foreach (var slot in validSlots)
{
foreach (var edge in node.owner.GetEdges(node.GetSlotReference(slot)))

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs


m_Nodes.Remove(node);
}
public virtual IEdge Connect(SlotReference fromSlotRef, SlotReference toSlotRef)
{
if (fromSlotRef == null || toSlotRef == null)

ValidateGraph();
return newEdge;
}
public virtual void RemoveEdge(IEdge e)
{
m_Edges.Remove(e);

var outputNode = GetNodeFromGuid(edge.outputSlot.nodeGuid);
var inputNode = GetNodeFromGuid(edge.inputSlot.nodeGuid);
if (outputNode == null
if (outputNode == null
|| outputNode.FindOutputSlot<ISlot>(edge.outputSlot.slotId) == null
|| outputNode.FindOutputSlot<ISlot>(edge.outputSlot.slotId) == null
|| inputNode.FindInputSlot<ISlot>(edge.inputSlot.slotId) == null)
{
//orphaned edge

14
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs


[SerializeField]
private string m_GuidSerialized;
[SerializeField]
private string m_Name;

public Guid RewriteGuid()
{
m_Guid = Guid.NewGuid();
return m_Guid;
return m_Guid;
{ }
{}
public IEnumerable<T> GetInputSlots<T>() where T : ISlot
{

foreach (var edge in edges.ToArray())
owner.RemoveEdge(edge);
//remove slots
m_Slots.RemoveAll(x => x.id == slotId);
}

return new SlotReference(guid, slotId);
}
public T FindSlot<T>(int slotId) where T: ISlot
public T FindSlot<T>(int slotId) where T : ISlot
{
return GetSlots<T>().FirstOrDefault(x => x.id == slotId);
}

m_GuidSerialized = m_Guid.ToString();
m_SerializableSlots = SerializationHelper.Serialize<ISlot>(m_Slots);
}
if (!string.IsNullOrEmpty(m_GuidSerialized))
if (!string.IsNullOrEmpty(m_GuidSerialized))
m_Guid = new Guid(m_GuidSerialized);
else
m_Guid = Guid.NewGuid();

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableSlot.cs


public int id
{
get { return m_Id;}
get { return m_Id; }
}
public virtual string displayName

public int priority
{
get { return m_Priority; }
set { m_Priority = value; }
set { m_Priority = value; }
}
public bool isInputSlot

{
get { return m_SlotType == SlotType.Output; }
}
{ }
{}
public SerializableSlot(int id, string displayName, SlotType slotType, int priority)
{

4
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/DrawingData.cs


{
[SerializeField]
private bool m_Expanded;
public bool expanded
{
get { return m_Expanded; }

4
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/IGraph.cs


{
public interface IGraph : IOnAssetEnabled
{
IEnumerable<T> GetNodes<T>() where T : INode;
IEnumerable<T> GetNodes<T>() where T: INode;
IEnumerable<IEdge> edges { get; }
void AddNode(INode node);
void RemoveNode(INode node);

INode GetNodeFromGuid(Guid guid);
T GetNodeFromGuid<T>(Guid guid) where T : INode;
T GetNodeFromGuid<T>(Guid guid) where T: INode;
IEnumerable<IEdge> GetEdges(SlotReference s);
void ValidateGraph();
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/INode.cs


Guid RewriteGuid();
string name { get; set; }
bool canDeleteNode { get; }
IEnumerable<T> GetInputSlots<T>() where T : ISlot;
IEnumerable<T> GetOutputSlots<T>() where T : ISlot;
IEnumerable<T> GetSlots<T>() where T : ISlot;
IEnumerable<T> GetInputSlots<T>() where T: ISlot;
IEnumerable<T> GetOutputSlots<T>() where T: ISlot;
IEnumerable<T> GetSlots<T>() where T: ISlot;
T FindSlot<T>(int slotId) where T : ISlot;
T FindInputSlot<T>(int slotId) where T : ISlot;
T FindOutputSlot<T>(int slotId) where T : ISlot;
T FindSlot<T>(int slotId) where T: ISlot;
T FindInputSlot<T>(int slotId) where T: ISlot;
T FindOutputSlot<T>(int slotId) where T: ISlot;
IEnumerable<ISlot> GetInputsWithNoConnection();
DrawingData drawState { get; set; }
bool hasError { get; }

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/SlotReference.cs


[SerializeField]
private string m_NodeGUIDSerialized;
public SlotReference(Guid nodeGuid, int slotId)
{
m_NodeGUID = nodeGuid;

29
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/SerializationHelper.cs


private static TypeSerializationInfo GetTypeSerializableAsString(Type type)
{
return new TypeSerializationInfo
{
fullName = type.FullName,
assemblyName = type.Assembly.GetName().Name
};
{
fullName = type.FullName,
assemblyName = type.Assembly.GetName().Name
};
}
private static Type GetTypeFromSerializedString(TypeSerializationInfo typeInfo)

var data = JsonUtility.ToJson(item, true);
if (string.IsNullOrEmpty(data))
throw new ArgumentException(string.Format("Can not serialize {0}", item)); ;
throw new ArgumentException(string.Format("Can not serialize {0}", item));
;
{
typeInfo = typeInfo,
JSONnodeData = data
};
{
typeInfo = typeInfo,
JSONnodeData = data
};
throw new ArgumentException(string.Format("Can not deserialize {0}, it is invalid", item)); ;
throw new ArgumentException(string.Format("Can not deserialize {0}, it is invalid", item));
var type = GetTypeFromSerializedString(item.typeInfo);
if (type == null)

return result;
}
public static List<T> Deserialize<T>(IEnumerable<JSONSerializedElement> list, params object[] constructorArgs) where T : class
public static List<T> Deserialize<T>(IEnumerable<JSONSerializedElement> list, params object[] constructorArgs) where T : class
foreach (var element in list)
foreach (var element in list)
{
try
{

Debug.LogException(e);
}
}
return result;
}
return result;
}
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphStyles.cs


private const float kHeadingSpace = 22.0f;
private readonly GUIStyle m_Header = "ShurikenModuleTitle";
private MaterialGraphStyles()
{
m_Header.font = (new GUIStyle("Label")).font;

{
get { return s_Styles ?? (s_Styles = new MaterialGraphStyles()); }
}
public static bool DoDrawDefaultInspector(SerializedObject obj)
{
EditorGUI.BeginChangeCheck();

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/AbstractMaterialNodeUI.cs


return false;
// workaround for some internal shader compiler weirdness
// if we are in error we sometimes to not properly clean
// if we are in error we sometimes to not properly clean
// out the error flags and will stay in error, even
// if we are now valid
if (m_PreviewShader && ShaderHasError(m_PreviewShader))

{
var hasErrorsCall = typeof(ShaderUtil).GetMethod("GetShaderErrorCount", BindingFlags.Static | BindingFlags.NonPublic);
var result = hasErrorsCall.Invoke(null, new object[] {shader});
return (int) result != 0;
return (int)result != 0;
}
/// <summary>

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/ColorNodeUI.cs


public class ColorNodeUI : ICustomNodeUi
{
private ColorNode m_Node;
public float GetNodeUiHeight(float width)
{
return 2 * EditorGUIUtility.singleLineHeight;

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/CombineNodeUI.cs


{
[CustomNodeUI(typeof(CombineNode))]
public class CombineNodeUI : AbstractMaterialNodeUI
{
{
public override float GetNodeUiHeight(float width)
{
return base.GetNodeUiHeight(width) + EditorGUIUtility.singleLineHeight;

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/PixelShaderNodeUI.cs


namespace UnityEditor.MaterialGraph
{
[CustomNodeUI(typeof(PixelShaderNode))]
public class PixelShaderNodeUI : AbstractMaterialNodeUI
{

return base.Render(area);
var lightFunctions = PixelShaderNode.GetLightFunctions();
var lightFunction = localNode.lightFunction.GetType();
var lightFunction = localNode.lightFunction.GetType();
lightFuncIndex = lightFunctions.Select(x => x.GetType()).ToList().IndexOf(lightFunction);
lightFuncIndex = lightFunctions.Select(x => x.GetType()).ToList().IndexOf(lightFunction);
EditorGUI.BeginChangeCheck();
lightFuncIndex = EditorGUI.Popup(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), lightFuncIndex, lightFunctions.Select(x => x.lightFunctionName).ToArray(), EditorStyles.popup);

{
localNode.UpdateNodeAfterDeserialization();
toReturn = GUIModificationType.ModelChanged;
localNode.UpdateNodeAfterDeserialization();
toReturn = GUIModificationType.ModelChanged;
}
}
protected override string GetPreviewShaderString()
{

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphIONodeUI.cs


public class SubGraphIONodeUI : ICustomNodeUi
{
private AbstractSubGraphIONode m_Node;
public float GetNodeUiHeight(float width)
{
return 2 * EditorGUIUtility.singleLineHeight;

return modification;
}
public INode node
{
get { return m_Node; }

m_Node = materialNode;
}
}
public float GetNodeWidth()
{
return 100;

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphNodeUI.cs


return base.Render(area);
EditorGUI.BeginChangeCheck();
localNode.subGraphAsset = (MaterialSubGraphAsset) EditorGUI.ObjectField(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight),
new GUIContent("SubGraph"),
localNode.subGraphAsset,
typeof(MaterialSubGraphAsset), false);
localNode.subGraphAsset = (MaterialSubGraphAsset)EditorGUI.ObjectField(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight),
new GUIContent("SubGraph"),
localNode.subGraphAsset,
typeof(MaterialSubGraphAsset), false);
var toReturn = GUIModificationType.None;

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/TextureNodeUI.cs


{
[CustomNodeUI(typeof(TextureNode))]
public class TextureNodeUI : AbstractMaterialNodeUI
{
{
public override float GetNodeUiHeight(float width)
{
return base.GetNodeUiHeight(width) + EditorGUIUtility.singleLineHeight * 2;

private string[] textureTypeNames
private string[] textureTypeNames
{
get
{

public override GUIModificationType Render(Rect area)
{
if (localNode == null)
return GUIModificationType.None;

EditorGUI.BeginChangeCheck();
localNode.textureType = (TextureType)EditorGUI.Popup(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), (int)localNode.textureType, textureTypeNames, EditorStyles.popup);
var typeChanged = EditorGUI.EndChangeCheck();
var toReturn = GUIModificationType.None;
if (typeChanged)
{

if (texureChanged)
toReturn |= GUIModificationType.Repaint;
area.y += EditorGUIUtility.singleLineHeight;
area.height -= EditorGUIUtility.singleLineHeight;
toReturn |= base.Render(area);

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector1NodeUI.cs


public class Vector1NodeUI : ICustomNodeUi
{
private Vector1Node m_Node;
public float GetNodeUiHeight(float width)
{
return 2 * EditorGUIUtility.singleLineHeight;

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector2NodeUI.cs


public class Vector2NodeUI : ICustomNodeUi
{
private Vector2Node m_Node;
public float GetNodeUiHeight(float width)
{
return 2 * EditorGUIUtility.singleLineHeight;

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector3NodeUI.cs


public class Vector3NodeUI : ICustomNodeUi
{
private Vector3Node m_Node;
public float GetNodeUiHeight(float width)
{
return 2 * EditorGUIUtility.singleLineHeight;

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector4NodeUI.cs


public class Vector4NodeUI : ICustomNodeUi
{
private Vector4Node m_Node;
public float GetNodeUiHeight(float width)
{
return 2 * EditorGUIUtility.singleLineHeight;

return GUIModificationType.None;
}
public INode node
{
get { return m_Node; }

m_Node = materialNode;
}
}
public float GetNodeWidth()
{
return 200;

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/SimpleWidgets.cs


EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), error ? Color.red : selected ? selectedColor : backgroundColor);
GUI.Label(new Rect(0, 0, scale.x, 26f), GUIContent.none, new GUIStyle("preToolbar"));
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Title, EditorStyles.toolbarTextField);
public class MoveableBox : SimpleBox
{
public MoveableBox(Vector2 position, float width)

m_Text2 = GUI.TextField(new Rect(0, currentY, 80, 20), m_Text2);
currentY += 22;
m_aTexture = EditorGUI.ObjectField(new Rect(0, currentY, 80, 100), m_aTexture, typeof (Texture2D), false) as Texture2D;
m_aTexture = EditorGUI.ObjectField(new Rect(0, currentY, 80, 100), m_aTexture, typeof(Texture2D), false) as Texture2D;
}
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Editors/MaterialGraphEditor.cs


if (s_Meshes[0] == null)
{
var handleGo = (GameObject) EditorGUIUtility.LoadRequired("Previews/PreviewMaterials.fbx");
var handleGo = (GameObject)EditorGUIUtility.LoadRequired("Previews/PreviewMaterials.fbx");
// @TODO: temp workaround to make it not render in the scene
handleGo.SetActive(false);
foreach (Transform t in handleGo.transform)

s_TimeIcons[0] = EditorGUIUtility.IconContent("PlayButton");
s_TimeIcons[1] = EditorGUIUtility.IconContent("PauseButton");
Mesh quadMesh = Resources.GetBuiltinResource(typeof (Mesh), "Quad.fbx") as Mesh;
Mesh quadMesh = Resources.GetBuiltinResource(typeof(Mesh), "Quad.fbx") as Mesh;
s_Meshes[4] = quadMesh;
s_PlaneMesh = quadMesh;
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs


namespace UnityEditor.MaterialGraph.IntegrationTests
{
public class ShaderGenerationTest
{
[Test]

"ShaderGeneration",
"Graphs"
};
var absoluteGraphsPath = path.Aggregate(Application.dataPath, Path.Combine);
var prjRelativeGraphsPath = path.Aggregate("Assets", Path.Combine);

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/AbstractMaterialGraphTests.cs


public void TestCanAddMaterialNodeToMaterialGraph()
{
TestableMGraph graph = new TestableMGraph();
var node = new TestableMNode();
graph.AddNode(node);
Assert.AreEqual(0, graph.edges.Count());

public void TestCanNotAddSerializableNodeToMaterialGraph()
{
TestableMGraph graph = new TestableMGraph();
var node = new SerializableNode();
graph.AddNode(node);
Assert.AreEqual(0, graph.edges.Count());

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/FixedSlotTests.cs


AddSlot(new MaterialSlot(V2Out, "V2Out", "V2Out", SlotType.Output, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot(V3Out, "V3Out", "V3Out", SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(V4Out, "V4Out", "V4Out", SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(V1In, "V1In", "V1In", SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(V2In, "V2In", "V2In", SlotType.Input, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot(V3In, "V3In", "V3In", SlotType.Input, SlotValueType.Vector3, Vector4.zero));

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs


outputString.AddShaderChunk("return arg;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}

m_Graph.AddNode(new PixelShaderNode());
m_InputOne.value = 0.2f;
, m_TestNode.GetVariableNameForSlot(Function1Input.OutputSlotId)
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId)
);
, m_TestNode.GetVariableNameForSlot(Function1Input.OutputSlotId)
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId)
);
ShaderGenerator visitor = new ShaderGenerator();
m_TestNode.GenerateNodeCode(visitor, GenerationMode.SurfaceShader);

string expected =
"inline half unity_test_half (half arg)\r\n"
+ "{\r\n"
+ " return arg;\r\n"
+ "\treturn arg;\r\n"
+ "}";
ShaderGenerator visitor = new ShaderGenerator();

15
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs


outputString.AddShaderChunk("return arg1 + arg2;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}

m_Graph.Connect(m_InputTwo.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function2Input.InputSlot2Id));
m_Graph.Connect(m_TestNode.GetSlotReference(Function2Input.OutputSlotId), m_Graph.pixelMasterNode.GetSlotReference(BaseLightFunction.NormalSlotId));
}
, m_TestNode.GetVariableNameForSlot(Function2Input.OutputSlotId)
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, m_InputTwo.GetVariableNameForSlot(Vector1Node.OutputSlotId)
);
, m_TestNode.GetVariableNameForSlot(Function2Input.OutputSlotId)
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, m_InputTwo.GetVariableNameForSlot(Vector1Node.OutputSlotId)
);
ShaderGenerator visitor = new ShaderGenerator();
m_TestNode.GenerateNodeCode(visitor, GenerationMode.SurfaceShader);

string expected =
"inline half unity_test_half (half arg1, half arg2)\r\n"
+ "{\r\n"
+ " return arg1 + arg2;\r\n"
+ "\treturn arg1 + arg2;\r\n"
+ "}";
ShaderGenerator visitor = new ShaderGenerator();

}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs


outputString.AddShaderChunk("return arg1 + arg2 + arg3;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}

public void TestGenerateNodeCodeGeneratesCorrectCode()
{
string expected = string.Format("half {0} = unity_test_half ({1}, {2}, {3});"
, m_TestNode.GetVariableNameForSlot(Function3Input.OutputSlotId)
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, m_InputTwo.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, m_InputThree.GetVariableNameForSlot(Vector1Node.OutputSlotId));
, m_TestNode.GetVariableNameForSlot(Function3Input.OutputSlotId)
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, m_InputTwo.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, m_InputThree.GetVariableNameForSlot(Vector1Node.OutputSlotId));
ShaderGenerator visitor = new ShaderGenerator();
m_TestNode.GenerateNodeCode(visitor, GenerationMode.SurfaceShader);

string expected =
"inline half unity_test_half (half arg1, half arg2, half arg3)\r\n"
+ "{\r\n"
+ " return arg1 + arg2 + arg3;\r\n"
+ "\treturn arg1 + arg2 + arg3;\r\n"
+ "}";
ShaderGenerator visitor = new ShaderGenerator();

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialGraphTests.cs


Assert.IsNotNull(graph.materialOptions);
graph.PostCreate();
Assert.AreEqual(1, graph.currentGraph.GetNodes<AbstractMaterialNode>().Count());
Assert.IsInstanceOf(typeof(PixelShaderNode), graph.currentGraph.GetNodes<AbstractMaterialNode>().FirstOrDefault());
}

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs


{
Assert.Throws<ArgumentException>(() => m_NodeA.GetVariableNameForSlot(666));
}
Assert.Throws<ArgumentException>(() => m_NodeA.AddSlot( new SerializableSlot(0, string.Empty, SlotType.Input)));
Assert.Throws<ArgumentException>(() => m_NodeA.AddSlot(new SerializableSlot(0, string.Empty, SlotType.Input)));
}
[Test]

var result = m_NodeA.GetSlotValue(slot.id, GenerationMode.Preview2D);
Assert.AreEqual(expected, result);
}
[Test]
public void NodeGenerateCorrectPreviewPropertyUsages()

17
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PixelShaderNodeTests.cs


m_Graph.AddNode(m_Abs);
m_InputOne.value = 0.2f;
m_Graph.Connect(m_InputOne.GetSlotReference(Vector1Node.OutputSlotId), m_PixelNode.GetSlotReference(BaseLightFunction.NormalSlotId));

Assert.AreEqual(string.Empty, generator.GetShaderString(0));
Assert.AreEqual(PBRMetalicLightFunction.LightFunctionName, generator.GetPragmaString());
}

Assert.AreEqual(PBRMetalicLightFunction.SurfaceOutputStructureName, generator.GetPragmaString());
}
+ "o.Normal = {0};\r\n"
+ "half {1} = abs ({0});\r\n"
+ "o.Albedo = {1};\r\n"
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, m_Abs.GetVariableNameForSlot(Function1Input.OutputSlotId));
+ "o.Normal = {0};\r\n"
+ "half {1} = abs ({0});\r\n"
+ "o.Albedo = {1};\r\n"
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, m_Abs.GetVariableNameForSlot(Function1Input.OutputSlotId));
var generator = new ShaderGenerator();
m_PixelNode.GenerateNodeCode(generator, GenerationMode.SurfaceShader);

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs


[TestFixture]
public class PropertyChunkTests
{
public TestPropertyChunch(string propertyName, string propertyDescription, HideState hideState)
public TestPropertyChunch(string propertyName, string propertyDescription, HideState hideState)
: base(propertyName, propertyDescription, hideState)
{}

[SetUp]
public void TestSetUp()
{
}
private const string kPropertyName = "ThePropertyName";

28
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs


public override PropertyType propertyType
{
get { return PropertyType.Float;}
get { return PropertyType.Float; }
{
m_Name = TestPropertyName
};
{
m_Name = TestPropertyName
};
private PixelGraph m_Graph;
private Vector1Node m_Vector1Node;
private Vector2Node m_Vector2Node;

m_Graph.AddNode(m_TextureNode);
m_Graph.AddNode(m_PropertyNode);
}
[Test]
public void TestExposedPropertyReturnsRawName()
{

Assert.AreEqual(string.Empty, generator.GetShaderString(0));
var expected = m_Vector1Node.propertyName
+ "(\""
+ m_Vector1Node.description
+ "\", Float) = "
+ m_Vector1Node.value
+ "\n";
+ "(\""
+ m_Vector1Node.description
+ "\", Float) = "
+ m_Vector1Node.value
+ "\n";
m_Vector1Node.exposedState = PropertyNode.ExposedState.Exposed;
m_Vector1Node.GeneratePropertyBlock(generator, GenerationMode.SurfaceShader);

Assert.AreEqual(string.Empty, generator.GetShaderString(0));
var expected = m_Vector1Node.precision
+ " "
+ m_Vector1Node.propertyName
+ ";\r\n";
+ " "
+ m_Vector1Node.propertyName
+ ";\r\n";
m_Vector1Node.exposedState = PropertyNode.ExposedState.Exposed;
m_Vector1Node.GeneratePropertyUsages(generator, GenerationMode.SurfaceShader);

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs


public void AdaptNodeOutput1To4Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>(TestNode.V1Out);
var result = ShaderGenerator.AdaptNodeOutput(node, TestNode.V1Out, ConcreteSlotValueType.Vector4);
Assert.AreEqual(string.Format("({0})", node.GetVariableNameForSlot(TestNode.V1Out)), result);
}

{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>(TestNode.V2Out);
var result = ShaderGenerator.AdaptNodeOutput(node, TestNode.V2Out, ConcreteSlotValueType.Vector1);
Assert.AreEqual(string.Format("({0}).x", node.GetVariableNameForSlot(TestNode.V2Out)), result);
}

public void AdaptNodeOutput4To3Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>(TestNode.V4Out);
var result = ShaderGenerator.AdaptNodeOutput(node, TestNode.V4Out, ConcreteSlotValueType.Vector3);
Assert.AreEqual(string.Format("({0}.xyz)", node.GetVariableNameForSlot(TestNode.V4Out)), result);
}

var result = ShaderGenerator.AdaptNodeOutput(node, TestNode.V4Out, ConcreteSlotValueType.Vector4);
Assert.AreEqual(string.Format("{0}", node.GetVariableNameForSlot(TestNode.V4Out)), result);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraph.cs


[SerializeField]
private string m_Name;
public string name
{
get { return m_Name; }

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraphAsset.cs


get { return m_MaterialGraph.currentGraph; }
}
public bool shouldRepaint
public bool shouldRepaint
{
get { return graph.GetNodes<AbstractMaterialNode>().OfType<IRequiresTime>().Any(); }
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialSubGraphAsset.cs


get { return m_MaterialSubGraph; }
}
public bool shouldRepaint
public bool shouldRepaint
{
get { return graph.GetNodes<AbstractMaterialNode>().OfType<IRequiresTime>().Any(); }
}

5
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/PixelGraph.cs


return m_PixelMasterNode;
}
}
[NonSerialized]
private List<INode> m_ActiveNodes = new List<INode>();
public IEnumerable<AbstractMaterialNode> activeNodes

}
base.AddNode(node);
}
public static void GenerateSurfaceShader(
PixelShaderNode pixelNode,
ShaderGenerator shaderBody,

pixelNode.GenerateNodeCode(shaderBody, genMode);
}
/*
public Material GetMaterial()
{

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Light/BaseLightFunction.cs


using System;
namespace UnityEngine.MaterialGraph

24
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Light/PBRMetalicLightFunction.cs


node.AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
// clear out slot names that do not match the slots
// clear out slot names that do not match the slots
new[]
{
AlbedoSlotId,
NormalSlotId,
EmissionSlotId,
MetallicSlotId,
SmoothnessSlotId,
OcclusionSlotId,
AlphaSlotId
});
new[]
{
AlbedoSlotId,
NormalSlotId,
EmissionSlotId,
MetallicSlotId,
SmoothnessSlotId,
OcclusionSlotId,
AlphaSlotId
});
}
}
}

24
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Light/PBRSpecularLightFunction.cs


public const string kSmoothnessSlotName = "Smoothness";
public const string kOcclusionSlotName = "Occlusion";
public const string kAlphaSlotName = "Alpha";
public const int kAlbedoSlotId = 0;
public const int kSpecularSlotId = 2;
public const int kEmissionSlotId = 3;

node.AddSlot(new MaterialSlot(kOcclusionSlotId, kOcclusionSlotName, kOcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new MaterialSlot(kAlphaSlotId, kAlphaSlotName, kAlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
// clear out slot names that do not match the slots
// clear out slot names that do not match the slots
new[]
{
kAlbedoSlotId,
NormalSlotId,
kSpecularSlotId,
kEmissionSlotId,
kSmoothnessSlotId,
kOcclusionSlotId,
kAlphaSlotId
});
new[]
{
kAlbedoSlotId,
NormalSlotId,
kSpecularSlotId,
kEmissionSlotId,
kSmoothnessSlotId,
kOcclusionSlotId,
kAlphaSlotId
});
}
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbsoluteNode.cs


namespace UnityEngine.MaterialGraph
{
{
[Title("Math/Absolute Node")]
public class AbsoluteNode : Function1Input
{

}
protected override string GetFunctionName() {return "abs"; }
}
}

26
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs


get { return m_OutputPrecision; }
set { m_OutputPrecision = value; }
}
// Nodes that want to have a preview area can override this and return true
// Nodes that want to have a preview area can override this and return true
public virtual bool hasPreview
{
get { return false; }

{
version = 0;
}
public virtual void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{}

var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(fromSocketRef.nodeGuid);
if (fromNode == null)
return string.Empty;
var slot = fromNode.FindOutputSlot<MaterialSlot>(fromSocketRef.slotId);
if (slot == null)
return string.Empty;

var outputNode = owner.GetNodeFromGuid(fromSocketRef.nodeGuid);
if (outputNode == null)
continue;
var dynamicInputSlotsToCompare = new Dictionary<MaterialSlot, ConcreteSlotValueType>();
var skippedDynamicSlots = new List<MaterialSlot>();

var outputSlot = outputNode.FindOutputSlot<MaterialSlot>(outputSlotRef.slotId);
if (outputSlot == null)
continue;
var outputConcreteType = outputSlot.concreteValueType;
// if we have a standard connection... just check the types work!

}
// we can now figure out the dynamic slotType
// from here set all the
// from here set all the
dynamicKvP.Key.concreteValueType= dynamicType;
dynamicKvP.Key.concreteValueType = dynamicType;
foreach (var skippedSlot in skippedDynamicSlots)
skippedSlot.concreteValueType = dynamicType;

var inputSlotType = inputSlot.concreteValueType;
return inputSlot.OnGUI(rect, inputSlotType);
}
*/
public virtual void CollectPreviewMaterialProperties(List<PreviewProperty> properties)

properties.Add(pp);
}
}
return GetVariableNameForNode() + "_" + slot.shaderOutputName;
}

if (foundSlot == null)
return;
// preserve the old current value.
// preserve the old current value.
addingSlot.currentValue = foundSlot.currentValue;
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/BlendNode.cs


[SerializeField]
private float m_Blend = 0.5f;
private static readonly string[] kOpNames =
private static readonly string[] kOpNames =
{
"normal",
"add"

protected void AddOperationBody(ShaderGenerator visitor, string name, string body)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk("inline " + precision + outputDimension +" unity_blend_" + name + "_" + precision + " (" + precision + outputDimension + " arg1, " + precision + outputDimension + " arg2, " + precision + " blend)", false);
outputString.AddShaderChunk("inline " + precision + outputDimension + " unity_blend_" + name + "_" + precision + " (" + precision + outputDimension + " arg1, " + precision + outputDimension + " arg2, " + precision + " blend)", false);
outputString.AddShaderChunk("{", false); outputString.Indent();
outputString.AddShaderChunk(body, false);
outputString.Deindent();

13
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ColorNode.cs


visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Color.r + ", " + m_Color.g + ", " + m_Color.b + ", " + m_Color.a + ");", true);
}
{
m_Name = propertyName,
m_PropType = PropertyType.Color,
m_Color = m_Color
};
{
m_Name = propertyName,
m_PropType = PropertyType.Color,
m_Color = m_Color
};
}
}

53
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/CombineNode.cs


{
name = "CombineNode";
}
// Based on information from:
// http://photoblogstop.com/photoshop/photoshop-blend-modes-explained
// http://www.venture-ware.com/kevin/coding/lets-learn-math-photoshop-blend-modes/

[SerializeField]
private Operation m_Operation;
private static readonly string[] kOpNames = {
private static readonly string[] kOpNames =
{
"darken", "mul", "cburn", "lburn",
"lighten", "screen", "cdodge", "ldodge",
"overlay", "softl", "hardl", "vividl", "linearl", "pinl", "hardmix",

visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
// Darken group
AddOperationBody(visitor, kOpNames[(int)Operation.Darken], "return min(arg1, arg2);");
AddOperationBody(visitor, kOpNames[(int)Operation.Multiply], "return arg1 * arg2;");
AddOperationBody(visitor, kOpNames[(int)Operation.ColorBurn], "return 1 - (1-arg1)/(arg2+1e-5);");
AddOperationBody(visitor, kOpNames[(int)Operation.LinearBurn], "return arg1 + arg2 - 1;");
// Darken group
AddOperationBody(visitor, kOpNames[(int)Operation.Darken], "return min(arg1, arg2);");
AddOperationBody(visitor, kOpNames[(int)Operation.Multiply], "return arg1 * arg2;");
AddOperationBody(visitor, kOpNames[(int)Operation.ColorBurn], "return 1 - (1-arg1)/(arg2+1e-5);");
AddOperationBody(visitor, kOpNames[(int)Operation.LinearBurn], "return arg1 + arg2 - 1;");
// Lighten group
AddOperationBody(visitor, kOpNames[(int)Operation.Lighten], "return max(arg1, arg2);");
AddOperationBody(visitor, kOpNames[(int)Operation.Screen], "return 1- (1-arg1) * (1-arg2);");
AddOperationBody(visitor, kOpNames[(int)Operation.ColorDodge], "return arg1/(1-arg2+1e-5);");
AddOperationBody(visitor, kOpNames[(int)Operation.LinearDodge], "return arg1 + arg2;");
// Lighten group
AddOperationBody(visitor, kOpNames[(int)Operation.Lighten], "return max(arg1, arg2);");
AddOperationBody(visitor, kOpNames[(int)Operation.Screen], "return 1- (1-arg1) * (1-arg2);");
AddOperationBody(visitor, kOpNames[(int)Operation.ColorDodge], "return arg1/(1-arg2+1e-5);");
AddOperationBody(visitor, kOpNames[(int)Operation.LinearDodge], "return arg1 + arg2;");
// Contrast group
AddOperationBody(visitor, kOpNames[(int)Operation.Overlay], "return (arg1 < 0.5)? arg1*arg2*2: 1-(1-arg1)*(1-arg2)*2;");
AddOperationBody(visitor, kOpNames[(int)Operation.SoftLight],"return (1-arg1)*arg1*arg2 + arg1*(1- (1-arg1)*(1-arg2));");
AddOperationBody(visitor, kOpNames[(int)Operation.HardLight], "return (arg2 < 0.5)? arg1*arg2*2: 1-(1-arg1)*(1-arg2)*2;");
AddOperationBody(visitor, kOpNames[(int)Operation.VividLight],"return (arg2 < 0.5)? 1- (1-arg1)/(2*arg2+1e-5): arg1/(1-2*(arg2-0.5)+1e-5);");
AddOperationBody(visitor, kOpNames[(int)Operation.LinearLight], "return (arg2 < 0.5)? arg1+(2*arg2)-1: arg1+2*(arg2-0.5);");
AddOperationBody(visitor, kOpNames[(int)Operation.PinLight], "return (arg2 < 0.5)? min(arg1, 2*arg2): max(arg1, 2*(arg2-0.5));");
AddOperationBody(visitor, kOpNames[(int)Operation.HardMix], "return (arg2 < 1-arg1)? " + precision + "(0):" + precision + "(1);");
// Contrast group
AddOperationBody(visitor, kOpNames[(int)Operation.Overlay], "return (arg1 < 0.5)? arg1*arg2*2: 1-(1-arg1)*(1-arg2)*2;");
AddOperationBody(visitor, kOpNames[(int)Operation.SoftLight], "return (1-arg1)*arg1*arg2 + arg1*(1- (1-arg1)*(1-arg2));");
AddOperationBody(visitor, kOpNames[(int)Operation.HardLight], "return (arg2 < 0.5)? arg1*arg2*2: 1-(1-arg1)*(1-arg2)*2;");
AddOperationBody(visitor, kOpNames[(int)Operation.VividLight], "return (arg2 < 0.5)? 1- (1-arg1)/(2*arg2+1e-5): arg1/(1-2*(arg2-0.5)+1e-5);");
AddOperationBody(visitor, kOpNames[(int)Operation.LinearLight], "return (arg2 < 0.5)? arg1+(2*arg2)-1: arg1+2*(arg2-0.5);");
AddOperationBody(visitor, kOpNames[(int)Operation.PinLight], "return (arg2 < 0.5)? min(arg1, 2*arg2): max(arg1, 2*(arg2-0.5));");
AddOperationBody(visitor, kOpNames[(int)Operation.HardMix], "return (arg2 < 1-arg1)? " + precision + "(0):" + precision + "(1);");
// Inversion group
AddOperationBody(visitor, kOpNames[(int)Operation.Difference], "return abs(arg2-arg1);");
AddOperationBody(visitor, kOpNames[(int)Operation.Exclusion], "return arg1 + arg2 - arg1*arg2*2;");
AddOperationBody(visitor, kOpNames[(int)Operation.Subtract], "return max(arg2-arg1, 0.0);");
AddOperationBody(visitor, kOpNames[(int)Operation.Divide], "return arg1 / (arg2+1e-5);");
// Inversion group
AddOperationBody(visitor, kOpNames[(int)Operation.Difference], "return abs(arg2-arg1);");
AddOperationBody(visitor, kOpNames[(int)Operation.Exclusion], "return arg1 + arg2 - arg1*arg2*2;");
AddOperationBody(visitor, kOpNames[(int)Operation.Subtract], "return max(arg2-arg1, 0.0);");
AddOperationBody(visitor, kOpNames[(int)Operation.Divide], "return arg1 / (arg2+1e-5);");
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DivNode.cs


{
name = "DivNode";
}
protected override string GetFunctionName() {return "unity_div_" + precision; }
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function1Input.cs


AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputSlotId, OutputSlotId }; }

protected virtual string GetOutputSlotName() {return "Output"; }
protected abstract string GetFunctionName();
+ precision + inputDimension + " " + argName + ")";
+ precision + inputDimension + " " + argName + ")";
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new []{InputSlotId}, new[] {OutputSlotId});
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] {InputSlotId}, new[] {OutputSlotId});
var inputValue = GetSlotValue(InputSlotId, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(inputValue) + ";", true);
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function2Input.cs


protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ")";
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function3Input.cs


{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual string GetInputSlot1Name()
{
return "Input1";

protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ", "
+ precision + input3Dimension + " " + arg3Name + ")";
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ", "
+ precision + input3Dimension + " " + arg3Name + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LengthNode.cs


{
name = "LengthNode";
}
protected override string GetFunctionName() { return "length"; }
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs


[SerializeField]
private Vector4 m_CurrentValue;
[SerializeField]
private ConcreteSlotValueType m_ConcreteValueType;

public MaterialSlot() { }
public MaterialSlot() {}
public MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue, int priority)
: base(slotId, displayName, slotType, priority)

public MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue)
public MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue)
: base(slotId, displayName, slotType)
{
SharedInitialize(shaderOutputName, valueType, defaultValue);

return "(4)";
default:
return "(E)";
}
}

}
public SlotValueType valueType
{
{
get { return m_ValueType; }
set
{

var matOwner = owner as AbstractMaterialNode;
if (matOwner == null)
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
visitor.AddShaderChunk(matOwner.precision + AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(concreteValueType) + " " + matOwner.GetVariableNameForSlot(id) + ";", true);
}

return "error";
}
}
/*
public override bool OnGUI()
{

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MinNode.cs


{
name = "MinimumNode";
}
protected override string GetFunctionName() { return "min"; }
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MultiplyNode.cs


{
name = "MultiplyNode";
}
protected override string GetFunctionName()
{
return "unity_multiply_" + precision;

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalNode.cs


RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override bool hasPreview
{
get { return true; }

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalizeNode.cs


{
name = "NormalizeNode";
}
protected override string GetFunctionName() { return "normalize"; }
}
}

62
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PixelShaderNode.cs


[NonSerialized]
private BaseLightFunction m_LightFunction = new PBRMetalicLightFunction();
private static List<BaseLightFunction> s_LightFunctions;
public BaseLightFunction lightFunction

protected override bool generateDefaultInputs { get { return false; } }
// public override bool canDeleteNode { get { return false; } }
// public override bool canDeleteNode { get { return false; } }
public static List<BaseLightFunction> GetLightFunctions()
{

{
lightFunction.GenerateSurfaceOutputStructureName(visitor);
}
public void GenerateNodeCode(ShaderGenerator shaderBody, GenerationMode generationMode)
{
var firstPassSlotId = lightFunction.GetFirstPassSlotId();

(node as IGeneratesBodyCode).GenerateNodeCode(shaderBody, generationMode);
}
ListPool<INode>.Release(nodes);
ListPool<INode>.Release(nodes);
foreach (var edge in owner.GetEdges(slot.slotReference))
{
var outputRef = edge.outputSlot;

/* public override float GetNodeUIHeight(float width)
{
return EditorGUIUtility.singleLineHeight;
}
/* public override float GetNodeUIHeight(float width)
{
return EditorGUIUtility.singleLineHeight;
}
public override GUIModificationType NodeUI(Rect drawArea)
{
var lightFunctions = GetLightFunctions();
var lightFunction = GetLightFunction();
public override GUIModificationType NodeUI(Rect drawArea)
{
var lightFunctions = GetLightFunctions();
var lightFunction = GetLightFunction();
int lightFuncIndex = 0;
if (lightFunction != null)
lightFuncIndex = lightFunctions.IndexOf(lightFunction);
int lightFuncIndex = 0;
if (lightFunction != null)
lightFuncIndex = lightFunctions.IndexOf(lightFunction);
EditorGUI.BeginChangeCheck();
lightFuncIndex = EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), lightFuncIndex, lightFunctions.Select(x => x.GetLightFunctionName()).ToArray(), EditorStyles.popup);
lightFunctionClassName = lightFunctions[lightFuncIndex].GetType().ToString();
if (EditorGUI.EndChangeCheck())
{
var function = GetLightFunction();
function.DoSlotsForConfiguration(this);
owner.ValidateGraph();
return GUIModificationType.ModelChanged;
}
return GUIModificationType.None;
}*/
EditorGUI.BeginChangeCheck();
lightFuncIndex = EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), lightFuncIndex, lightFunctions.Select(x => x.GetLightFunctionName()).ToArray(), EditorStyles.popup);
lightFunctionClassName = lightFunctions[lightFuncIndex].GetType().ToString();
if (EditorGUI.EndChangeCheck())
{
var function = GetLightFunction();
function.DoSlotsForConfiguration(this);
owner.ValidateGraph();
return GUIModificationType.ModelChanged;
}
return GUIModificationType.None;
}*/
public override IEnumerable<ISlot> GetInputsWithNoConnection()
{

{
get { return true; }
}
public override void OnBeforeSerialize()
{
base.OnBeforeSerialize();

base.OnAfterDeserialize();
}
/*
protected override bool UpdatePreviewShader()
{

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PowerNode.cs


{
name = "PowerNode";
}
protected override string GetFunctionName() { return "pow"; }
}
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs


[SerializeField]
private ExposedState m_Exposed = ExposedState.NotExposed;
public ExposedState exposedState
{
get { return m_Exposed; }

get
{
if (exposedState == ExposedState.NotExposed || string.IsNullOrEmpty(m_PropertyName))
return string.Format("{0}_{1}_Uniform", name, guid.ToString().Replace("-","_"));
return string.Format("{0}_{1}_Uniform", name, guid.ToString().Replace("-", "_"));
return m_PropertyName + "_Uniform";
}

public abstract PropertyType propertyType { get; }
public abstract PreviewProperty GetPreviewProperty();
public override void CollectPreviewMaterialProperties (List<PreviewProperty> properties)
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
protected override bool CalculateNodeHasError()
{
if (exposedState == ExposedState.NotExposed)

foreach (var n in propNodes)
{
if (n == this || n.exposedState == ExposedState.NotExposed)
continue;;
continue;
if (n.propertyName == propertyName)
{

if (m_Exposed)
m_Description = EditorGUILayout.TextField("Description", m_Description);
modified |= base.OnGUI();
return modified;
}*/

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ReflectNode.cs


{
name = "ReflectNode";
}
protected override string GetInputSlot1Name() {return "Normal"; }
protected override string GetInputSlot2Name() {return "Direction"; }
protected override string GetOutputSlotName() {return "Reflection"; }

{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero);
}
protected override string GetFunctionName() {return "unity_reflect_" + precision; }
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ScreenPosNode.cs


AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return "IN.screenPos";

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SinTimeNode.cs


AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.one));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override bool hasPreview
{
get { return true; }

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SlotValue.cs


Vector2,
Vector1
}
public enum ConcreteSlotValueType
{
Vector4 = 4,

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SmoothStepNode.cs


}
protected override string GetFunctionName() {return "smoothstep"; }
}
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs


{
name = "SwizzleNode";
}
/*
public override float GetNodeUIHeight(float width)
{

62
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs


public const int UvSlotId = 0;
public const int OutputSlotRgbaId = 1;
public const int OutputSlotRId =2;
public const int OutputSlotGId =3;
public const int OutputSlotRId = 2;
public const int OutputSlotGId = 3;
public const int OutputSlotBId = 4;
public const int OutputSlotAId = 5;

[SerializeField]
private TextureType m_TextureType;
public override bool hasPreview { get { return true; } }
#if UNITY_EDITOR

var edge = edges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true);
}
string body = "tex2D (" + propertyName + ", " + uvName + ")";

{
visitor.AddShaderProperty(
new TexturePropertyChunk(
propertyName,
description,
defaultTexture, m_TextureType,
PropertyChunk.HideState.Visible,
exposedState == ExposedState.Exposed ?
TexturePropertyChunk.ModifiableState.Modifiable
: TexturePropertyChunk.ModifiableState.NonModifiable));
propertyName,
description,
defaultTexture, m_TextureType,
PropertyChunk.HideState.Visible,
exposedState == ExposedState.Exposed ?
TexturePropertyChunk.ModifiableState.Modifiable
: TexturePropertyChunk.ModifiableState.NonModifiable));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)

/*
public override bool DrawSlotDefaultInput(Rect rect, Slot inputSlot)
{
var uvSlot = FindInputSlot(kUVSlotName);
if (uvSlot != inputSlot)
return base.DrawSlotDefaultInput(rect, inputSlot);
/*
public override bool DrawSlotDefaultInput(Rect rect, Slot inputSlot)
{
var uvSlot = FindInputSlot(kUVSlotName);
if (uvSlot != inputSlot)
return base.DrawSlotDefaultInput(rect, inputSlot);
var rectXmax = rect.xMax;
rect.x = rectXmax - 70;
rect.width = 70;
var rectXmax = rect.xMax;
rect.x = rectXmax - 70;
rect.width = 70;
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f));
GUI.Label(rect, "From Mesh");
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f));
GUI.Label(rect, "From Mesh");
return false;
}
*/
return false;
}
*/
{
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_Texture = defaultTexture
};
{
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_Texture = defaultTexture
};
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TimeNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

3
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public static void StaticGenerateVertexToFragmentBlock(ShaderGenerator visitor, GenerationMode generationMode)
{
string temp = "half4 meshUV0";

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UnpackNormalNode.cs


{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero);
}
protected override string GetInputSlotName() {return "PackedNormal"; }
protected override string GetOutputSlotName() {return "Normal"; }

18
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs


AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public override PropertyType propertyType
{
get { return PropertyType.Float; }

public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + " " + propertyName + ";", true);
visitor.AddShaderChunk(precision + " " + propertyName + ";", true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

{
m_Name = propertyName,
m_PropType = PropertyType.Float,
m_Float = m_Value
};
{
m_Name = propertyName,
m_PropType = PropertyType.Float,
m_Float = m_Value
};
}
}
}

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector2Node.cs


public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector4 = m_Value
};
{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector4 = m_Value
};
}
}
}

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector3Node.cs


public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector3,
m_Vector4 = m_Value
};
{
m_Name = propertyName,
m_PropType = PropertyType.Vector3,
m_Vector4 = m_Value
};
}
}
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector4Node.cs


{
[SerializeField]
private Vector4 m_Value;
public Vector4Node()
{
name = "V4Node";

public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};
{
m_Name = propertyName,
m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ViewDirectionNode.cs


{
if (generationMode == GenerationMode.Preview2D)
throw new InvalidEnumArgumentException(string.Format("Trying to generate 2D preview on {0}. This is not supported!", this));
visitor.AddShaderChunk("float3 viewDir;", true);
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/WorldPosNode.cs


AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector3, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return "IN.worldPos";

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraph.cs


public void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
foreach (var node in usedNodes)
{
if (node is IGenerateProperties)

16
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphInputNode.cs


RemoveSlot(-lastSlotId);
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
foreach (var slot in GetOutputSlots<MaterialSlot>())

foreach (var slot in GetOutputSlots<MaterialSlot>())
{
properties.Add(
new PreviewProperty
{
m_Name = GetVariableNameForSlot(slot.id),
m_PropType = PropertyType.Vector4,
m_Vector4 = slot.defaultValue
}
);
new PreviewProperty
{
m_Name = GetVariableNameForSlot(slot.id),
m_PropType = PropertyType.Vector4,
m_Vector4 = slot.defaultValue
}
);
}
}
}

17
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs


, IGeneratesVertexToFragmentBlock
, IOnAssetEnabled
{
[SerializeField]
private string m_SubGraphAssetGuid;

var outDimension = ConvertConcreteSlotValueTypeToString(slot.concreteValueType);
outputString.AddShaderChunk(
"float"
+ outDimension
+ " "
+ varName
+ " = "
+ varValue
+ outDimension
+ " "
+ varName
+ " = "
+ varValue
// Step 4...
// Using the inputs we can now generate the shader body :)
var bodyGenerator = new ShaderGenerator();

outputString.AddShaderChunk(
GetVariableNameForSlot(slot.id)
+ " = "
+ inputValue
+ inputValue
+ ";", false);
}

subGraph.GeneratePropertyUsages(visitor, GenerationMode.SurfaceShader);
}
public override void CollectPreviewMaterialProperties (List<PreviewProperty> properties)
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphOutputNode.cs


{
name = "SubGraphOutputs";
}
public override int AddSlot()
{
var index = GetInputSlots<ISlot>().Count() + 1;

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs


{
var outputSlot = node.FindOutputSlot<MaterialSlot>(outputSlotId);
if (outputSlot == null)
if (outputSlot == null)
var convertFromType = outputSlot.concreteValueType;
var rawOutput = node.GetVariableNameForSlot(outputSlotId);
if (convertFromType == convertToType)

NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, node);
var generationMode = GenerationMode.Preview2D;
generatedShaderMode = PreviewMode.Preview2D;
if (activeNodeList.OfType<AbstractMaterialNode>().Any(x => x.previewMode == PreviewMode.Preview3D))
{
generationMode = GenerationMode.Preview3D;

var vertexShaderBlock = new ShaderGenerator();
var shaderName = "Hidden/PreviewShader/" + node.GetVariableNameForSlot(node.GetOutputSlots<MaterialSlot>().First().id);
foreach (var activeNode in activeNodeList.OfType<AbstractMaterialNode>())
{
if (activeNode is IGeneratesFunction)

resultShader = resultShader.Replace("${VertexShaderDecl}", "");
resultShader = resultShader.Replace("${VertexShaderBody}", "");
}
configuredTextures = shaderPropertiesVisitor.GetConfiguredTexutres();
return resultShader;
}

正在加载...
取消
保存