浏览代码

[Material Graph]Tidy + small Refactorings. Add more tests.

/main
Tim Cooper 8 年前
当前提交
0e9ee494
共有 49 个文件被更改,包括 1047 次插入472 次删除
  1. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs
  2. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs
  3. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/UnitTests/SerializedGraphTests.cs
  4. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/SerializableGraphAsset.cs
  5. 21
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs
  6. 25
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/AbstractMaterialNodeUI.cs
  7. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/ColorNodeUI.cs
  8. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/CombineNodeUI.cs
  9. 20
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/PixelShaderNodeUI.cs
  10. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphIONodeUI.cs
  11. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphNodeUI.cs
  12. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/TextureNodeUI.cs
  13. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector1NodeUI.cs
  14. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector2NodeUI.cs
  15. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector3NodeUI.cs
  16. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector4NodeUI.cs
  17. 149
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs
  18. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs
  19. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
  20. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ColorNode.cs
  21. 60
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
  22. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PixelShaderNode.cs
  23. 18
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs
  24. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
  25. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs
  26. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector2Node.cs
  27. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector3Node.cs
  28. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector4Node.cs
  29. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ViewDirectionNode.cs
  30. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraph.cs
  31. 209
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
  32. 170
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/FixedSlotTests.cs
  33. 150
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs
  34. 118
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs
  35. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs.meta
  36. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ColorPropertyChunk.cs
  37. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ColorPropertyChunk.cs.meta
  38. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/FloatPropertyChunk.cs
  39. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/FloatPropertyChunk.cs.meta
  40. 27
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyChunk.cs
  41. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyChunk.cs.meta
  42. 58
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs
  43. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs.meta
  44. 58
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TexturePropertyChunk.cs
  45. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TexturePropertyChunk.cs.meta
  46. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TextureType.cs
  47. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TextureType.cs.meta
  48. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/VectorPropertyChunk.cs
  49. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/VectorPropertyChunk.cs.meta

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


try
{
customUI = Activator.CreateInstance(draweruiType) as ICustomNodeUi;
customUI.SetNode(node);
customUI.node = node;
}
catch (Exception e)
{

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


{
float GetNodeUiHeight(float width);
GUIModificationType Render(Rect area);
void SetNode(INode node);
INode node { get; set; }
float GetNodeWidth();
}
}

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


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

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


public class SerializableGraphAsset : ScriptableObject, IGraphAsset, IOnAssetEnabled
{
[SerializeField]
protected SerializableGraph m_Graph = new SerializableGraph();
private SerializableGraph m_Graph = new SerializableGraph();
public IGraph graph
{

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


{
public class SlotConfigurationException : Exception
{
public SlotConfigurationException()
{ }
{ }
public SlotConfigurationException(string message, Exception inner)
: base(message, inner)
{ }
}

// which child nodes it depends on for it's calculation.
// Results are returned depth first so by processing each node in
// order you can generate a valid code block.
public static void DepthFirstCollectNodesFromNode(List<INode> nodeList, INode node, int? slotId = null, bool includeSelf = true)
public enum IncludeSelf
{
Include,
Exclude
}
public static void DepthFirstCollectNodesFromNode(List<INode> nodeList, INode node, int? slotId = null, IncludeSelf includeSelf = IncludeSelf.Include)
{
// no where to start
if (node == null)

}
}
if (includeSelf)
if (includeSelf == IncludeSelf.Include)
public static void CollectNodesNodeFeedsInto(List<INode> nodeList, INode node, bool includeSelf = true)
public static void CollectNodesNodeFeedsInto(List<INode> nodeList, INode node, IncludeSelf includeSelf = IncludeSelf.Include)
{
if (node == null)
return;

CollectNodesNodeFeedsInto(nodeList, inputNode);
}
}
if (includeSelf)
if (includeSelf == IncludeSelf.Include)
nodeList.Add(node);
}
}

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


private Material m_PreviewMaterial;
[NonSerialized]
protected Shader m_PreviewShader;
private Shader m_PreviewShader;
private AbstractMaterialNode m_Node;
protected AbstractMaterialNode m_Node;
protected PreviewMode m_GeneratedShaderMode = PreviewMode.Preview2D;
private PreviewMode m_GeneratedShaderMode = PreviewMode.Preview2D;
public Material previewMaterial
{

if (m_PreviewGenerator == null)
{
m_PreviewGenerator = new MaterialGraphPreviewGenerator();
}
return m_PreviewGenerator;
}

return m_PreviewWidth;
}
public void SetNode(INode node)
public INode node
{
get { return m_Node; }
set
{
var materialNode = value as AbstractMaterialNode;
if (materialNode != null)
m_Node = materialNode;
}
}
public PreviewMode generatedShaderMode
if (node is AbstractMaterialNode)
m_Node = (AbstractMaterialNode)node;
get { return m_GeneratedShaderMode; }
set { m_GeneratedShaderMode = value; }
}
public virtual float GetNodeWidth()

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


return GUIModificationType.None;
}
public void SetNode(INode node)
public INode node
if (node is ColorNode)
m_Node = (ColorNode) node;
get { return m_Node; }
set
{
var materialNode = value as ColorNode;
if (materialNode != null)
m_Node = materialNode;
}
}
public float GetNodeWidth()

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


public override GUIModificationType Render(Rect area)
{
var node = m_Node as CombineNode;
if (node == null)
var localNode = node as CombineNode;
if (localNode == null)
if (m_Node == null)
return GUIModificationType.None;
node.operation = (CombineNode.Operation)EditorGUI.EnumPopup(area, node.operation);
localNode.operation = (CombineNode.Operation)EditorGUI.EnumPopup(area, localNode.operation);
var toReturn = GUIModificationType.None;
if (EditorGUI.EndChangeCheck())

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


public override GUIModificationType Render(Rect area)
{
var node = m_Node as PixelShaderNode;
if (node == null)
var localNode = node as PixelShaderNode;
if (localNode == null)
var lightFunction = node.GetLightFunction();
var lightFunction = localNode.GetLightFunction();
int lightFuncIndex = 0;
if (lightFunction != null)

lightFuncIndex = EditorGUI.Popup(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), lightFuncIndex, lightFunctions.Select(x => x.GetLightFunctionName()).ToArray(), EditorStyles.popup);
node.m_LightFunctionClassName = lightFunctions[lightFuncIndex].GetType().ToString();
localNode.m_LightFunctionClassName = lightFunctions[lightFuncIndex].GetType().ToString();
node.UpdateNodeAfterDeserialization();
localNode.UpdateNodeAfterDeserialization();
toReturn = GUIModificationType.ModelChanged;
}
area.y += EditorGUIUtility.singleLineHeight;

protected override string GetPreviewShaderString()
{
var shaderName = "Hidden/PreviewShader/" + m_Node.GetVariableNameForNode();
var localNode = node as PixelShaderNode;
if (localNode == null)
return string.Empty;
var shaderName = "Hidden/PreviewShader/" + localNode.GetVariableNameForNode();
var resultShader = ShaderGenerator.GenerateSurfaceShader(m_Node as PixelShaderNode, new MaterialOptions(), shaderName, true, out defaultTextures);
m_GeneratedShaderMode = PreviewMode.Preview3D;
var resultShader = ShaderGenerator.GenerateSurfaceShader(localNode, new MaterialOptions(), shaderName, true, out defaultTextures);
generatedShaderMode = PreviewMode.Preview3D;
return resultShader;
}
}

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


return modification;
}
public void SetNode(INode node)
public INode node
if (node is AbstractSubGraphIONode)
m_Node = (AbstractSubGraphIONode) node;
get { return m_Node; }
set
{
var materialNode = value as AbstractSubGraphIONode;
if (materialNode != null)
m_Node = materialNode;
}
public float GetNodeWidth()
{
return 100;

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


public override GUIModificationType Render(Rect area)
{
var node = m_Node as SubGraphNode;
if (node == null)
var localNode = node as SubGraphNode;
if (localNode == null)
node.subGraphAsset = (MaterialSubGraphAsset) EditorGUI.ObjectField(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight),
localNode.subGraphAsset = (MaterialSubGraphAsset) EditorGUI.ObjectField(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight),
node.subGraphAsset,
localNode.subGraphAsset,
typeof(MaterialSubGraphAsset), false);
var toReturn = GUIModificationType.None;

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


public override GUIModificationType Render(Rect area)
{
var node = m_Node as TextureNode;
if (node == null)
var localNode = node as TextureNode;
if (localNode == null)
if (m_Node == null)
if (localNode == null)
node.defaultTexture = EditorGUI.MiniThumbnailObjectField(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), new GUIContent("Texture"), node.defaultTexture, typeof(Texture2D), null) as Texture2D;
localNode.defaultTexture = EditorGUI.MiniThumbnailObjectField(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), new GUIContent("Texture"), localNode.defaultTexture, typeof(Texture2D), null) as Texture2D;
node.textureType = (TextureType)EditorGUI.Popup(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), (int)node.textureType, textureTypeNames, EditorStyles.popup);
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;

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


return GUIModificationType.None;
}
public void SetNode(INode node)
public INode node
if (node is Vector1Node)
m_Node = (Vector1Node) node;
get { return m_Node; }
set
{
var materialNode = value as Vector1Node;
if (materialNode != null)
m_Node = materialNode;
}
}
public float GetNodeWidth()

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


return GUIModificationType.None;
}
public void SetNode(INode node)
public INode node
if (node is Vector2Node)
m_Node = (Vector2Node) node;
get { return m_Node; }
set
{
var materialNode = value as Vector2Node;
if (materialNode != null)
m_Node = materialNode;
}
}
public float GetNodeWidth()

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


return GUIModificationType.None;
}
public void SetNode(INode node)
public INode node
if (node is Vector3Node)
m_Node = (Vector3Node) node;
get { return m_Node; }
set
{
var materialNode = value as Vector3Node;
if (materialNode != null)
m_Node = materialNode;
}
}
public float GetNodeWidth()

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


return GUIModificationType.None;
}
public void SetNode(INode node)
public INode node
if (node is Vector4Node)
m_Node = (Vector4Node) node;
get { return m_Node; }
set
{
var materialNode = value as Vector4Node;
if (materialNode != null)
m_Node = materialNode;
}
public float GetNodeWidth()
{
return 200;

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


using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;

{
private PixelGraph m_Graph;
private TestNode m_NodeA;
private TestNode m_NodeB;
public const int V2Out = 1;
public const int V3Out = 2;
public const int V4Out = 3;
public const int V1In = 4;
public const int V2In = 5;
public const int V3In = 6;
public const int V4In = 7;
public const int V1In = 1;
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(V2In, "V2In", "V2In", SlotType.Input, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot(V3In, "V3In", "V3In", SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(V4In, "V4In", "V4In", SlotType.Input, SlotValueType.Vector4, Vector4.zero));
}
}

{
m_Graph = new PixelGraph();
m_NodeA = new TestNode();
m_NodeB = new TestNode();
m_Graph.AddNode(m_NodeB);
public void ConnectV1ToV1Works()
public void GetVariableNameForSlotThrowsWhenInvalid()
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V1In));
Assert.IsFalse(m_NodeB.hasError);
Assert.Throws<ArgumentException>(() => m_NodeA.GetVariableNameForSlot(666));
public void ConnectV1ToV2Works()
public void AddingNonMaterialSlotToNodeThrows()
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V2In));
Assert.IsFalse(m_NodeB.hasError);
Assert.Throws<ArgumentException>(() => m_NodeA.AddSlot( new SerializableSlot(0, string.Empty, SlotType.Input)));
public void ConnectV1ToV3Works()
public void ReplacingMaterialSlotPreservesTheOldCurrentValue()
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V3In));
Assert.IsFalse(m_NodeB.hasError);
}
m_NodeA.AddSlot(new MaterialSlot(TestNode.V1In, "V1In", "V1In", SlotType.Input, SlotValueType.Vector1, Vector4.one));
Assert.AreEqual(2, m_NodeA.GetSlots<MaterialSlot>().Count());
Assert.AreEqual(1, m_NodeA.GetInputSlots<MaterialSlot>().Count());
[Test]
public void ConnectV1ToV4Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V4In));
Assert.IsFalse(m_NodeB.hasError);
var slot = m_NodeA.GetInputSlots<MaterialSlot>().FirstOrDefault();
Assert.AreEqual(Vector4.one, slot.defaultValue);
Assert.AreEqual(Vector4.zero, slot.currentValue);
public void ConnectV2ToV1Works()
public void CanConvertConcreteSlotValueTypeToOutputChunkProperly()
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V1In));
Assert.IsFalse(m_NodeB.hasError);
Assert.AreEqual(string.Empty, AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector1));
Assert.AreEqual("2", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector2));
Assert.AreEqual("3", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector3));
Assert.AreEqual("4", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector4));
Assert.AreEqual("Error", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Error));
public void ConnectV2ToV2Works()
public void CanGetDefaultInputsFromNodeAsPreviewProperties()
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V2In));
Assert.IsFalse(m_NodeB.hasError);
}
var properties = new List<PreviewProperty>();
m_NodeA.CollectPreviewMaterialProperties(properties);
var slot = m_NodeA.GetInputSlots<MaterialSlot>().FirstOrDefault();
[Test]
public void ConnectV2ToV3Fails()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V3In));
Assert.IsTrue(m_NodeB.hasError);
}
Assert.AreEqual(1, properties.Count);
var pp = properties.FirstOrDefault();
[Test]
public void ConnectV2ToV4Fails()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V4In));
Assert.IsTrue(m_NodeB.hasError);
Assert.AreEqual(m_NodeA.GetVariableNameForSlot(slot.id), pp.m_Name);
Assert.AreEqual(PropertyType.Vector4, pp.m_PropType);
Assert.AreEqual(slot.currentValue, pp.m_Vector4);
public void ConnectV3ToV1Works()
public void CanGetDefaultSlotValueWhenNoEdgesConnected()
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V1In));
Assert.IsFalse(m_NodeB.hasError);
}
string expected = string.Format("{0}", m_NodeA.GetVariableNameForSlot(TestNode.V1In));
[Test]
public void ConnectV3ToV2Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V2In));
Assert.IsFalse(m_NodeB.hasError);
var slot = m_NodeA.GetInputSlots<MaterialSlot>().FirstOrDefault();
var result = m_NodeA.GetSlotValue(slot.id, GenerationMode.Preview2D);
Assert.AreEqual(expected, result);
[Test]
public void ConnectV3ToV3Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V3In));
Assert.IsFalse(m_NodeB.hasError);
}
public void ConnectV3ToV4Fails()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V4In));
Assert.IsTrue(m_NodeB.hasError);
}
[Test]
public void ConnectV4ToV1Works()
public void NodeGenerateCorrectPreviewPropertyUsages()
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V1In));
Assert.IsFalse(m_NodeB.hasError);
}
string expected = string.Format("{0} {1};\r\n", AbstractMaterialNode.OutputPrecision.@fixed, m_NodeA.GetVariableNameForSlot(TestNode.V1In));
var visitor = new ShaderGenerator();
m_NodeA.precision = AbstractMaterialNode.OutputPrecision.@fixed;
m_NodeA.GeneratePropertyUsages(visitor, GenerationMode.Preview2D);
Assert.AreEqual(expected, visitor.GetShaderString(0));
[Test]
public void ConnectV4ToV2Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V2In));
Assert.IsFalse(m_NodeB.hasError);
}
expected = string.Format("{0} {1};\r\n", AbstractMaterialNode.OutputPrecision.@float, m_NodeA.GetVariableNameForSlot(TestNode.V1In));
visitor = new ShaderGenerator();
m_NodeA.precision = AbstractMaterialNode.OutputPrecision.@float;
m_NodeA.GeneratePropertyUsages(visitor, GenerationMode.Preview2D);
Assert.AreEqual(expected, visitor.GetShaderString(0));
[Test]
public void ConnectV4ToV3Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V3In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV4ToV4Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V4In));
Assert.IsFalse(m_NodeB.hasError);
expected = string.Format("{0} {1};\r\n", AbstractMaterialNode.OutputPrecision.half, m_NodeA.GetVariableNameForSlot(TestNode.V1In));
visitor = new ShaderGenerator();
m_NodeA.precision = AbstractMaterialNode.OutputPrecision.half;
m_NodeA.GeneratePropertyUsages(visitor, GenerationMode.Preview2D);
Assert.AreEqual(expected, visitor.GetShaderString(0));
}
}
}

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


Debug.logger.logHandler = new ConsoleLogHandler();
}
[Test]
public void TestTexturePropertyChunkGeneratesValidPropertyStringNotHiddenNotModifiable()
{
var chunk = new TexturePropertyChunk("TexProp", "Description", null, TextureType.White, false, false);
Assert.AreEqual("[NonModifiableTextureData] TexProp(\"Description\", 2D) = \"white\" {}" , chunk.GetPropertyString());
Assert.IsFalse(chunk.modifiable);
Assert.IsFalse(chunk.hidden);
}
[Test]
public void TestTexturePropertyChunkGeneratesValidPropertyStringHiddenNotModifiable()
{
var chunk = new TexturePropertyChunk("TexProp", "Description", null, TextureType.White, true, false);
Assert.AreEqual("[HideInInspector] [NonModifiableTextureData] TexProp(\"Description\", 2D) = \"white\" {}", chunk.GetPropertyString());
Assert.IsFalse(chunk.modifiable);
Assert.IsTrue(chunk.hidden);
}
[Test]
public void TestColorPropertyChunkGeneratesValidPropertyString()
{
var chunk = new ColorPropertyChunk("ColProp", "Description", Color.green, false);
Assert.AreEqual("ColProp(\"Description\", Color) = (0,1,0,1)", chunk.GetPropertyString());
}
[Test]
public void TestFloatPropertyChunkGeneratesValidPropertyString()
{
var chunk = new FloatPropertyChunk("FloatProp", "Description", 0.3f, false);
Assert.AreEqual("FloatProp(\"Description\", Float) = 0.3", chunk.GetPropertyString());
}
[Test]
public void VectorPropertyChunkGeneratesValidPropertyString()
{
var chunk = new VectorPropertyChunk("VectorProp", "Description", new Vector4(0, 0, 1, 0), false);
Assert.AreEqual("VectorProp(\"Description\", Vector) = (0,0,1,0)", chunk.GetPropertyString());
}
class TestNode : AbstractMaterialNode
{
public const int V1Out = 0;

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


if (edges.Any())
continue;
inputSlot.GeneratePropertyUsages(visitor, generationMode, inputSlot.concreteValueType, this);
inputSlot.GeneratePropertyUsages(visitor, generationMode);
}
}

if (inputSlot == null)
return string.Empty;
var edges = owner.GetEdges(inputSlot.slotReference).ToArray();
if (edges.Any())

return ShaderGenerator.AdaptNodeOutput(fromNode, slot.id, slot.concreteValueType);
}
return inputSlot.GetDefaultValue(generationMode, this);
return inputSlot.GetDefaultValue(generationMode);
}
private ConcreteSlotValueType FindCommonChannelType(ConcreteSlotValueType from, ConcreteSlotValueType to)

return from >= to || from == ConcreteSlotValueType.Vector1;
}
protected virtual ConcreteSlotValueType ConvertDynamicInputTypeToConcrete(IEnumerable<ConcreteSlotValueType> inputTypes)
private ConcreteSlotValueType ConvertDynamicInputTypeToConcrete(IEnumerable<ConcreteSlotValueType> inputTypes)
{
var concreteSlotValueTypes = inputTypes as IList<ConcreteSlotValueType> ?? inputTypes.ToList();
if (concreteSlotValueTypes.Any(x => x == ConcreteSlotValueType.Error))

public sealed override void AddSlot(ISlot slot)
{
if (!(slot is MaterialSlot))
{
Debug.LogWarningFormat("Trying to add slot {0} to Material node {1}, but it is not a {2}", slot, this, typeof(MaterialSlot));
return;
}
throw new ArgumentException(string.Format("Trying to add slot {0} to Material node {1}, but it is not a {2}", slot, this, typeof(MaterialSlot)));
var addingSlot = (MaterialSlot) slot;
var foundSlot = FindSlot<MaterialSlot>(slot.id);

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


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

if (exposed || generationMode.IsPreview())
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Color.r + ", " + m_Color.g + ", " + m_Color.b + ", " + m_Color.a + ");", true);

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


private void SharedInitialize(string inShaderOutputName, SlotValueType inValueType, Vector4 inDefaultValue)
{
m_ShaderOutputName = inShaderOutputName;
m_ValueType = inValueType;
valueType = inValueType;
switch (inValueType)
{
case SlotValueType.Vector1:
concreteValueType = ConcreteSlotValueType.Vector1;
break;
case SlotValueType.Vector2:
concreteValueType = ConcreteSlotValueType.Vector2;
break;
case SlotValueType.Vector3:
concreteValueType = ConcreteSlotValueType.Vector3;
break;
default:
concreteValueType = ConcreteSlotValueType.Vector4;
break;
}
}
private static string ConcreteSlotValueTypeAsString(ConcreteSlotValueType type)

public SlotValueType valueType
{
get { return m_ValueType; }
set { m_ValueType = value; }
set
{
switch (value)
{
case SlotValueType.Vector1:
concreteValueType = ConcreteSlotValueType.Vector1;
break;
case SlotValueType.Vector2:
concreteValueType = ConcreteSlotValueType.Vector2;
break;
case SlotValueType.Vector3:
concreteValueType = ConcreteSlotValueType.Vector3;
break;
default:
concreteValueType = ConcreteSlotValueType.Vector4;
break;
}
m_ValueType = value;
}
}
public Vector4 currentValue

set { m_ShaderOutputName = value; }
}
public void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType slotValueType, AbstractMaterialNode owner)
public void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
visitor.AddShaderChunk("float" + AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(slotValueType) + " " + owner.GetVariableNameForSlot(id) + ";", true);
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);
public string GetDefaultValue(GenerationMode generationMode, AbstractMaterialNode owner)
public string GetDefaultValue(GenerationMode generationMode)
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)));
return owner.GetVariableNameForSlot(id);
return matOwner.GetVariableNameForSlot(id);
switch (concreteValueType)
{

return "half2 (" + m_CurrentValue.x + "," + m_CurrentValue.y + ")";
return matOwner.precision + "2 (" + m_CurrentValue.x + "," + m_CurrentValue.y + ")";
return "half3 (" + m_CurrentValue.x + "," + m_CurrentValue.y + "," + m_CurrentValue.z + ")";
return matOwner.precision + "3 (" + m_CurrentValue.x + "," + m_CurrentValue.y + "," + m_CurrentValue.z + ")";
return "half4 (" + m_CurrentValue.x + "," + m_CurrentValue.y + "," + m_CurrentValue.z + "," + m_CurrentValue.w + ")";
return matOwner.precision + "4 (" + m_CurrentValue.x + "," + m_CurrentValue.y + "," + m_CurrentValue.z + "," + m_CurrentValue.w + ")";
default:
return "error";
}

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


// do the normal slot first so that it can be used later in the shader :)
var firstPassSlot = FindInputSlot<MaterialSlot>(firstPassSlotId);
var nodes = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, firstPassSlotId, false);
NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, firstPassSlotId, NodeUtils.IncludeSelf.Exclude);
for (int index = 0; index < nodes.Count; index++)
{

int pass2StartIndex = nodes.Count;
//Get the rest of the nodes for all the other slots
NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, null, false);
NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, null, NodeUtils.IncludeSelf.Exclude);
for (var i = pass2StartIndex; i < nodes.Count; i++)
{
var node = nodes[i];

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


{
public abstract class PropertyNode : AbstractMaterialNode
{
public enum ExposedState
{
Exposed,
NotExposed
}
public string m_PropertyName;
private string m_PropertyName = string.Empty;
public string m_Description;
private string m_Description = string.Empty;
public bool m_Exposed;
private ExposedState m_Exposed = ExposedState.NotExposed;
public bool exposed
public ExposedState exposedState
{
get { return m_Exposed; }
}

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

protected override bool CalculateNodeHasError()
{
if (!exposed)
if (exposedState == ExposedState.NotExposed)
return false;
var propNodes = owner.GetNodes<PropertyNode>();

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


// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(new TexturePropertyChunk(propertyName, description, defaultTexture, m_TextureType, false, exposed));
visitor.AddShaderProperty(
new TexturePropertyChunk(
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)

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


public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposed)
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, m_Value, false));
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
if (exposed || generationMode.IsPreview())
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
if (exposed || generationMode.IsPreview())
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + " " + propertyName + " = " + m_Value + ";", true);

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


public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, false));
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
if (exposed || generationMode.IsPreview())
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
if (exposed || generationMode.IsPreview())
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "2 " + propertyName + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true);

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


public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, false));
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
if (exposed || generationMode.IsPreview())
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
if (exposed || generationMode.IsPreview())
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "3 " + propertyName + " = " + precision + "3 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ");", true);

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


public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, false));
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
if (exposed || generationMode.IsPreview())
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
if (exposed || generationMode.IsPreview())
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);

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


using System.ComponentModel;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

public void GenerateVertexToFragmentBlock(ShaderGenerator visitor, GenerationMode generationMode)
{
if (generationMode == GenerationMode.Preview2D)
Debug.LogError("Trying to generate 2D preview on a node that does not support it!");
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/SubGraph/SubGraph.cs


{
var nodes = new List<INode>();
//Get the rest of the nodes for all the other slots
NodeUtils.DepthFirstCollectNodesFromNode(nodes, outputNode, null, false);
NodeUtils.DepthFirstCollectNodesFromNode(nodes, outputNode, null, NodeUtils.IncludeSelf.Exclude);
return nodes.OfType<AbstractMaterialNode>();
}
}

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


namespace UnityEngine.MaterialGraph
{
public enum TextureType
{
White,
Gray,
Black,
Bump
}
public abstract class PropertyChunk
{
protected string m_PropertyName;
protected string m_PropertyDescription;
protected bool m_Hidden;
protected PropertyChunk(string propertyName, string propertyDescription, bool hidden)
{
m_PropertyName = propertyName;
m_PropertyDescription = propertyDescription;
m_Hidden = hidden;
}
public abstract string GetPropertyString();
public string propertyName { get { return m_PropertyName; } }
public string propertyDescription { get { return m_PropertyDescription; } }
public bool hidden { get { return m_Hidden; } }
}
public class TexturePropertyChunk : PropertyChunk
{
private readonly Texture m_DefaultTexture;
private readonly TextureType m_DefaultTextureType;
private readonly bool m_Modifiable;
public TexturePropertyChunk(string propertyName, string propertyDescription, Texture defaultTexture, TextureType defaultTextureType, bool hidden, bool modifiable)
: base(propertyName, propertyDescription, hidden)
{
m_DefaultTexture = defaultTexture;
m_DefaultTextureType = defaultTextureType;
m_Modifiable = modifiable;
}
public override string GetPropertyString()
{
var result = new StringBuilder();
if (hidden)
result.Append("[HideInInspector] ");
if (!m_Modifiable)
result.Append("[NonModifiableTextureData] ");
result.Append(m_PropertyName);
result.Append("(\"");
result.Append(m_PropertyDescription);
result.Append("\", 2D) = \"");
result.Append(Enum.GetName(typeof(TextureType), m_DefaultTextureType).ToLower());
result.Append("\" {}");
return result.ToString();
}
public Texture defaultTexture
{
get
{
return m_DefaultTexture;
}
}
public bool modifiable
{
get
{
return m_Modifiable;
}
}
}
public class ColorPropertyChunk : PropertyChunk
{
private Color m_DefaultColor;
public ColorPropertyChunk(string propertyName, string propertyDescription, Color defaultColor, bool hidden)
: base(propertyName, propertyDescription, hidden)
{
m_DefaultColor = defaultColor;
}
public override string GetPropertyString()
{
var result = new StringBuilder();
result.Append(m_PropertyName);
result.Append("(\"");
result.Append(m_PropertyDescription);
result.Append("\", Color) = (");
result.Append(m_DefaultColor.r);
result.Append(",");
result.Append(m_DefaultColor.g);
result.Append(",");
result.Append(m_DefaultColor.b);
result.Append(",");
result.Append(m_DefaultColor.a);
result.Append(")");
return result.ToString();
}
}
public class FloatPropertyChunk : PropertyChunk
{
private readonly float m_DefaultValue;
public FloatPropertyChunk(string propertyName, string propertyDescription, float defaultValue, bool hidden)
: base(propertyName, propertyDescription, hidden)
{
m_DefaultValue = defaultValue;
}
public override string GetPropertyString()
{
var result = new StringBuilder();
result.Append(m_PropertyName);
result.Append("(\"");
result.Append(m_PropertyDescription);
result.Append("\", Float) = ");
result.Append(m_DefaultValue);
return result.ToString();
}
}
public class VectorPropertyChunk : PropertyChunk
{
private readonly Vector4 m_DefaultVector;
public VectorPropertyChunk(string propertyName, string propertyDescription, Vector4 defaultVector, bool hidden)
: base(propertyName, propertyDescription, hidden)
{
m_DefaultVector = defaultVector;
}
public override string GetPropertyString()
{
var result = new StringBuilder();
result.Append(m_PropertyName);
result.Append("(\"");
result.Append(m_PropertyDescription);
result.Append("\", Vector) = (");
result.Append(m_DefaultVector.x);
result.Append(",");
result.Append(m_DefaultVector.y);
result.Append(",");
result.Append(m_DefaultVector.z);
result.Append(",");
result.Append(m_DefaultVector.w);
result.Append(")");
return result.ToString();
}
}
public class PropertyGenerator
{
public struct TextureInfo
{
public string name;
public int textureId;
public bool modifiable;
}
private readonly List<PropertyChunk> m_Properties = new List<PropertyChunk>();
public void AddShaderProperty(PropertyChunk chunk)
{
m_Properties.Add(chunk);
}
public string GetShaderString(int baseIndentLevel)
{
var sb = new StringBuilder();
foreach (var prop in m_Properties)
{
for (var i = 0; i < baseIndentLevel; i++)
{
sb.Append("\t");
}
sb.Append(prop.GetPropertyString());
sb.Append("\n");
}
return sb.ToString();
}
public List<TextureInfo> GetConfiguredTexutres()
{
var result = new List<TextureInfo>();
foreach (var prop in m_Properties.OfType<TexturePropertyChunk>())
{
if (prop.propertyName != null)
{
var textureInfo = new TextureInfo
{
name = prop.propertyName,
textureId = prop.defaultTexture != null ? prop.defaultTexture.GetInstanceID() : 0,
modifiable = prop.modifiable
};
result.Add(textureInfo);
}
}
return result;
}
}
public class ShaderGenerator
{
private struct ShaderChunk

return template;
}
public static string GenerateSurfaceShader(PixelShaderNode node, MaterialOptions options, string shaderName, bool isPreview, out List<PropertyGenerator.TextureInfo> configuredTxtures)
public static string GenerateSurfaceShader(PixelShaderNode node, MaterialOptions options, string shaderName, bool isPreview, out List<PropertyGenerator.TextureInfo> configuredTextures)
configuredTxtures = new List<PropertyGenerator.TextureInfo>();
configuredTextures = new List<PropertyGenerator.TextureInfo>();
return string.Empty;
}

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

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


using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.UnitTests
{
[TestFixture]
public class FixedSlotTests
{
private PixelGraph m_Graph;
private TestNode m_NodeA;
private TestNode m_NodeB;
class TestNode : AbstractMaterialNode
{
public const int V1Out = 0;
public const int V2Out = 1;
public const int V3Out = 2;
public const int V4Out = 3;
public const int V1In = 4;
public const int V2In = 5;
public const int V3In = 6;
public const int V4In = 7;
public TestNode()
{
AddSlot(new MaterialSlot(V1Out, "V1Out", "V1Out", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
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));
AddSlot(new MaterialSlot(V4In, "V4In", "V4In", SlotType.Input, SlotValueType.Vector4, Vector4.zero));
}
}
[TestFixtureSetUp]
public void RunBeforeAnyTests()
{
Debug.logger.logHandler = new ConsoleLogHandler();
}
[SetUp]
public void TestSetUp()
{
m_Graph = new PixelGraph();
m_NodeA = new TestNode();
m_NodeB = new TestNode();
m_Graph.AddNode(m_NodeA);
m_Graph.AddNode(m_NodeB);
}
[Test]
public void ConnectV1ToV1Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V1In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV1ToV2Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V2In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV1ToV3Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V3In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV1ToV4Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V4In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV2ToV1Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V1In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV2ToV2Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V2In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV2ToV3Fails()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V3In));
Assert.IsTrue(m_NodeB.hasError);
}
[Test]
public void ConnectV2ToV4Fails()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V4In));
Assert.IsTrue(m_NodeB.hasError);
}
[Test]
public void ConnectV3ToV1Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V1In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV3ToV2Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V2In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV3ToV3Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V3In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV3ToV4Fails()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V4In));
Assert.IsTrue(m_NodeB.hasError);
}
[Test]
public void ConnectV4ToV1Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V1In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV4ToV2Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V2In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV4ToV3Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V3In));
Assert.IsFalse(m_NodeB.hasError);
}
[Test]
public void ConnectV4ToV4Works()
{
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V4In));
Assert.IsFalse(m_NodeB.hasError);
}
}
}

150
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs


using System;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.UnitTests
{
[TestFixture]
public class MaterialSlotTests
{
private PixelGraph m_Graph;
private TestNode m_NodeA;
class TestNode : AbstractMaterialNode
{
public const int V1In = 1;
public readonly MaterialSlot slot;
public TestNode()
{
slot = new MaterialSlot(V1In, "V1In", "V1In", SlotType.Input, SlotValueType.Vector1, Vector4.zero);
AddSlot(slot);
}
}
[TestFixtureSetUp]
public void RunBeforeAnyTests()
{
Debug.logger.logHandler = new ConsoleLogHandler();
}
[SetUp]
public void TestSetUp()
{
m_Graph = new PixelGraph();
m_NodeA = new TestNode();
m_Graph.AddNode(m_NodeA);
}
[Test]
public void CanUpdateMaterialSlotDisplayName()
{
var displayName = "New Display Name";
var slot = m_NodeA.slot;
slot.displayName = displayName;
slot.valueType = SlotValueType.Vector1;
Assert.AreEqual(displayName + "(1)", slot.displayName);
slot.valueType = SlotValueType.Vector2;
Assert.AreEqual(displayName + "(2)", slot.displayName);
slot.valueType = SlotValueType.Vector3;
Assert.AreEqual(displayName + "(3)", slot.displayName);
slot.valueType = SlotValueType.Vector4;
Assert.AreEqual(displayName + "(4)", slot.displayName);
slot.valueType = SlotValueType.Dynamic;
Assert.AreEqual(displayName + "(4)", slot.displayName);
}
[Test]
public void CanUpdateMaterialSlotDefaultValue()
{
var slot = m_NodeA.slot;
slot.defaultValue = Vector4.one;
Assert.AreEqual(Vector4.one, slot.defaultValue);
}
[Test]
public void CanUpdateMaterialSlotCurrentValue()
{
var slot = m_NodeA.slot;
slot.currentValue = Vector4.one;
Assert.AreEqual(Vector4.one, slot.currentValue);
}
[Test]
public void CanUpdateMaterialSlotValueType()
{
var slot = m_NodeA.slot;
slot.valueType = SlotValueType.Vector3;
Assert.AreEqual(SlotValueType.Vector3, slot.valueType);
}
[Test]
public void CanUpdateMaterialShaderOutputName()
{
var shaderName = "NewShaderOutputName";
var slot = m_NodeA.slot;
slot.shaderOutputName = shaderName;
Assert.AreEqual(shaderName, slot.shaderOutputName);
}
[Test]
public void MaterialSlotCanGeneratePropertyUsagesForPreview()
{
string expected = string.Format("{0} {1};\r\n", m_NodeA.precision, m_NodeA.GetVariableNameForSlot(TestNode.V1In));
var slot = m_NodeA.slot;
var visitor = new ShaderGenerator();
slot.GeneratePropertyUsages(visitor, GenerationMode.Preview2D);
Assert.AreEqual(expected, visitor.GetShaderString(0));
}
[Test]
public void MaterialSlotReturnsValidDefaultValue()
{
string expected = string.Format("{0}", m_NodeA.GetVariableNameForSlot(TestNode.V1In));
var slot = m_NodeA.slot;
var result = slot.GetDefaultValue(GenerationMode.Preview2D);
Assert.AreEqual(expected, result);
slot.valueType = SlotValueType.Vector1;
slot.currentValue = new Vector4(6, 6, 6, 1);
result = slot.GetDefaultValue(GenerationMode.SurfaceShader);
Assert.AreEqual("6", result);
slot.valueType = SlotValueType.Vector2;
slot.currentValue = new Vector4(6, 6, 6, 1);
result = slot.GetDefaultValue(GenerationMode.SurfaceShader);
Assert.AreEqual("half2 (6,6)", result);
slot.valueType = SlotValueType.Vector3;
slot.currentValue = new Vector4(6, 6, 6, 1);
result = slot.GetDefaultValue(GenerationMode.SurfaceShader);
Assert.AreEqual("half3 (6,6,6)", result);
slot.valueType = SlotValueType.Vector4;
slot.currentValue = new Vector4(6, 6, 6, 1);
result = slot.GetDefaultValue(GenerationMode.SurfaceShader);
Assert.AreEqual("half4 (6,6,6,1)", result);
}
[Test]
public void MaterialSlotThrowsWhenNoOwner()
{
var slot = new MaterialSlot(0, string.Empty, string.Empty, SlotType.Input, SlotValueType.Vector1, Vector4.zero);
Assert.Throws<Exception>(() => slot.GeneratePropertyUsages(new ShaderGenerator(), GenerationMode.Preview2D));
Assert.Throws<Exception>(() => slot.GetDefaultValue(GenerationMode.Preview2D));
}
}
}

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


using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.UnitTests
{
[TestFixture]
public class PropertyChunkTests
{
class TestPropertyChunch : PropertyChunk
{
public TestPropertyChunch(string propertyName, string propertyDescription, HideState hideState)
: base(propertyName, propertyDescription, hideState)
{}
public override string GetPropertyString()
{
return propertyName;
}
}
[TestFixtureSetUp]
public void RunBeforeAnyTests()
{
Debug.logger.logHandler = new ConsoleLogHandler();
}
[SetUp]
public void TestSetUp()
{
}
private const string kPropertyName = "ThePropertyName";
private const string kPropertyDescription = "ThePropertyDescription";
[Test]
public void TestSimplePropertyChunkIsConstructedProperly()
{
var chunk = new TestPropertyChunch(kPropertyName, kPropertyDescription, PropertyChunk.HideState.Visible);
Assert.AreEqual(kPropertyName, chunk.propertyName);
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription);
Assert.AreEqual(kPropertyName, chunk.GetPropertyString());
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState);
}
[Test]
public void TestColorChunkReturnsValidValues()
{
var expectedPropertyString = "ThePropertyName(\"ThePropertyDescription\", Color) = (1,0,0,1)";
var chunk = new ColorPropertyChunk(kPropertyName, kPropertyDescription, Color.red, PropertyChunk.HideState.Visible);
Assert.AreEqual(kPropertyName, chunk.propertyName);
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription);
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString());
Assert.AreEqual(Color.red, chunk.defaultColor);
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState);
}
[Test]
public void TestFloatChunkReturnsValidValues()
{
var expectedPropertyString = "ThePropertyName(\"ThePropertyDescription\", Float) = 0.5";
var chunk = new FloatPropertyChunk(kPropertyName, kPropertyDescription, 0.5f, PropertyChunk.HideState.Visible);
Assert.AreEqual(kPropertyName, chunk.propertyName);
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription);
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString());
Assert.AreEqual(0.5f, chunk.defaultValue);
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState);
}
[Test]
public void TestVectorChunkReturnsValidValues()
{
var vector = new Vector4(0.2f, 0.4f, 0.66f, 1.0f);
var expectedPropertyString = "ThePropertyName(\"ThePropertyDescription\", Vector) = (0.2,0.4,0.66,1)";
var chunk = new VectorPropertyChunk(kPropertyName, kPropertyDescription, vector, PropertyChunk.HideState.Visible);
Assert.AreEqual(kPropertyName, chunk.propertyName);
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription);
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString());
Assert.AreEqual(vector, chunk.defaultValue);
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState);
}
[Test]
public void TestTextureChunkReturnsValidValues()
{
var expectedPropertyString = "ThePropertyName(\"ThePropertyDescription\", 2D) = \"bump\" {}";
var chunk = new TexturePropertyChunk(kPropertyName, kPropertyDescription, null, TextureType.Bump, PropertyChunk.HideState.Visible, TexturePropertyChunk.ModifiableState.Modifiable);
Assert.AreEqual(kPropertyName, chunk.propertyName);
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription);
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString());
Assert.AreEqual(null, chunk.defaultTexture);
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState);
}
[Test]
public void TestTexturePropertyChunkGeneratesValidPropertyStringVisibleNotModifiable()
{
var expectedPropertyString = "[NonModifiableTextureData] ThePropertyName(\"ThePropertyDescription\", 2D) = \"gray\" {}";
var chunk = new TexturePropertyChunk(kPropertyName, kPropertyDescription, null, TextureType.Gray, PropertyChunk.HideState.Visible, TexturePropertyChunk.ModifiableState.NonModifiable);
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString());
Assert.AreEqual(TexturePropertyChunk.ModifiableState.NonModifiable, chunk.modifiableState);
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState);
}
[Test]
public void TestTexturePropertyChunkGeneratesValidPropertyStringHiddenNotModifiable()
{
var expectedPropertyString = "[HideInInspector] [NonModifiableTextureData] ThePropertyName(\"ThePropertyDescription\", 2D) = \"white\" {}";
var chunk = new TexturePropertyChunk(kPropertyName, kPropertyDescription, null, TextureType.White, PropertyChunk.HideState.Hidden, TexturePropertyChunk.ModifiableState.NonModifiable);
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString());
Assert.AreEqual(TexturePropertyChunk.ModifiableState.NonModifiable, chunk.modifiableState);
Assert.AreEqual(PropertyChunk.HideState.Hidden, chunk.hideState);
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs.meta


fileFormatVersion: 2
guid: 816037e003cccbc4b8a61ec1bf91ab0c
timeCreated: 1469695793
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

38
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ColorPropertyChunk.cs


using System.Text;
namespace UnityEngine.MaterialGraph
{
public class ColorPropertyChunk : PropertyChunk
{
private Color m_DefaultColor;
public ColorPropertyChunk(string propertyName, string propertyDescription, Color defaultColor, HideState hideState)
: base(propertyName, propertyDescription, hideState)
{
m_DefaultColor = defaultColor;
}
public Color defaultColor
{
get { return m_DefaultColor; }
}
public override string GetPropertyString()
{
var result = new StringBuilder();
result.Append(propertyName);
result.Append("(\"");
result.Append(propertyDescription);
result.Append("\", Color) = (");
result.Append(defaultColor.r);
result.Append(",");
result.Append(defaultColor.g);
result.Append(",");
result.Append(defaultColor.b);
result.Append(",");
result.Append(defaultColor.a);
result.Append(")");
return result.ToString();
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ColorPropertyChunk.cs.meta


fileFormatVersion: 2
guid: c55a60f83c47c3940b74e5a1f53d69aa
timeCreated: 1469695793
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

30
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/FloatPropertyChunk.cs


using System.Text;
namespace UnityEngine.MaterialGraph
{
public class FloatPropertyChunk : PropertyChunk
{
private readonly float m_DefaultValue;
public FloatPropertyChunk(string propertyName, string propertyDescription, float defaultValue, HideState hideState)
: base(propertyName, propertyDescription, hideState)
{
m_DefaultValue = defaultValue;
}
public float defaultValue
{
get { return m_DefaultValue; }
}
public override string GetPropertyString()
{
var result = new StringBuilder();
result.Append(propertyName);
result.Append("(\"");
result.Append(propertyDescription);
result.Append("\", Float) = ");
result.Append(defaultValue);
return result.ToString();
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/FloatPropertyChunk.cs.meta


fileFormatVersion: 2
guid: 5165619d6635ec146aa7014ac39356cd
timeCreated: 1469695793
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

27
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyChunk.cs


namespace UnityEngine.MaterialGraph
{
public abstract class PropertyChunk
{
public enum HideState
{
Hidden,
Visible
}
private readonly string m_PropertyName;
private readonly string m_PropertyDescription;
private readonly HideState m_HideState;
protected PropertyChunk(string propertyName, string propertyDescription, HideState hideState)
{
m_PropertyName = propertyName;
m_PropertyDescription = propertyDescription;
m_HideState = hideState;
}
public abstract string GetPropertyString();
public string propertyName { get { return m_PropertyName; } }
public string propertyDescription { get { return m_PropertyDescription; } }
public HideState hideState { get { return m_HideState; } }
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyChunk.cs.meta


fileFormatVersion: 2
guid: e3bc93a0908e88743a7f24757b2a85f4
timeCreated: 1469695793
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

58
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs


using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UnityEngine.MaterialGraph
{
public class PropertyGenerator
{
public struct TextureInfo
{
public string name;
public int textureId;
public TexturePropertyChunk.ModifiableState modifiable;
}
private readonly List<PropertyChunk> m_Properties = new List<PropertyChunk>();
public void AddShaderProperty(PropertyChunk chunk)
{
m_Properties.Add(chunk);
}
public string GetShaderString(int baseIndentLevel)
{
var sb = new StringBuilder();
foreach (var prop in m_Properties)
{
for (var i = 0; i < baseIndentLevel; i++)
{
sb.Append("\t");
}
sb.Append(prop.GetPropertyString());
sb.Append("\n");
}
return sb.ToString();
}
public List<TextureInfo> GetConfiguredTexutres()
{
var result = new List<TextureInfo>();
foreach (var prop in m_Properties.OfType<TexturePropertyChunk>())
{
if (prop.propertyName != null)
{
var textureInfo = new TextureInfo
{
name = prop.propertyName,
textureId = prop.defaultTexture != null ? prop.defaultTexture.GetInstanceID() : 0,
modifiable = prop.modifiableState
};
result.Add(textureInfo);
}
}
return result;
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs.meta


fileFormatVersion: 2
guid: ca768a19c7caa844c83fceae4a411f04
timeCreated: 1469695793
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

58
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TexturePropertyChunk.cs


using System;
using System.Text;
namespace UnityEngine.MaterialGraph
{
public class TexturePropertyChunk : PropertyChunk
{
public enum ModifiableState
{
Modifiable,
NonModifiable
}
private readonly Texture m_DefaultTexture;
private readonly TextureType m_DefaultTextureType;
private readonly ModifiableState m_Modifiable;
public TexturePropertyChunk(string propertyName, string propertyDescription, Texture defaultTexture, TextureType defaultTextureType, HideState hidden, ModifiableState modifiableState)
: base(propertyName, propertyDescription, hidden)
{
m_DefaultTexture = defaultTexture;
m_DefaultTextureType = defaultTextureType;
m_Modifiable = modifiableState;
}
public override string GetPropertyString()
{
var result = new StringBuilder();
if (hideState == HideState.Hidden)
result.Append("[HideInInspector] ");
if (m_Modifiable == ModifiableState.NonModifiable)
result.Append("[NonModifiableTextureData] ");
result.Append(propertyName);
result.Append("(\"");
result.Append(propertyDescription);
result.Append("\", 2D) = \"");
result.Append(Enum.GetName(typeof(TextureType), m_DefaultTextureType).ToLower());
result.Append("\" {}");
return result.ToString();
}
public Texture defaultTexture
{
get
{
return m_DefaultTexture;
}
}
public ModifiableState modifiableState
{
get
{
return m_Modifiable;
}
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TexturePropertyChunk.cs.meta


fileFormatVersion: 2
guid: 2ac615170ebfd804eb0e5dbd753d73e9
timeCreated: 1469695793
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


namespace UnityEngine.MaterialGraph
{
public enum TextureType
{
White,
Gray,
Black,
Bump
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TextureType.cs.meta


fileFormatVersion: 2
guid: 70e84ad0d8e6f4947a8e6aa53984bf2a
timeCreated: 1469695793
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

38
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/VectorPropertyChunk.cs


using System.Text;
namespace UnityEngine.MaterialGraph
{
public class VectorPropertyChunk : PropertyChunk
{
private readonly Vector4 m_DefaultVector;
public VectorPropertyChunk(string propertyName, string propertyDescription, Vector4 defaultVector, HideState hideState)
: base(propertyName, propertyDescription, hideState)
{
m_DefaultVector = defaultVector;
}
public Vector4 defaultValue
{
get { return m_DefaultVector; }
}
public override string GetPropertyString()
{
var result = new StringBuilder();
result.Append(propertyName);
result.Append("(\"");
result.Append(propertyDescription);
result.Append("\", Vector) = (");
result.Append(defaultValue.x);
result.Append(",");
result.Append(defaultValue.y);
result.Append(",");
result.Append(defaultValue.z);
result.Append(",");
result.Append(defaultValue.w);
result.Append(")");
return result.ToString();
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/VectorPropertyChunk.cs.meta


fileFormatVersion: 2
guid: f215325849c67a741994a3bade6cdda6
timeCreated: 1469695793
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存