浏览代码

[Material Graph]Write tests / fix issues as encountered

/main
Tim Cooper 9 年前
当前提交
addd6c34
共有 10 个文件被更改,包括 514 次插入8 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
  2. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
  4. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
  5. 222
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/DynamicSlotTests.cs
  6. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/DynamicSlotTests.cs.meta
  7. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs
  8. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs.meta
  9. 208
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs
  10. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs.meta

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


if (slot == null)
return string.Empty;
return ShaderGenerator.AdaptNodeOutput(fromNode, slot, generationMode, inputSlot.concreteValueType);
return ShaderGenerator.AdaptNodeOutput(fromNode, slot, inputSlot.concreteValueType);
}
return inputSlot.GetDefaultValue(generationMode, inputSlot.concreteValueType, this);

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


m_ValueType = valueType;
m_DefaultValue = defaultValue;
m_CurrentValue = defaultValue;
switch (valueType)
{
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;
}
}
public Vector4 defaultValue

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


var edge = edges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
var slot = fromNode.FindOutputSlot<MaterialSlot>(edge.outputSlot.slotName);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, slot, generationMode, ConcreteSlotValueType.Vector2, true);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, slot, ConcreteSlotValueType.Vector2, true);
}

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


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

public override string GetPropertyString()
{
var result = new StringBuilder();
if (m_Hidden)
if (hidden)
result.Append("[HideInInspector] ");
if (!m_Modifiable)
result.Append("[NonModifiableTextureData] ");

}
private const string kErrorString = @"ERROR!";
public static string AdaptNodeOutput(AbstractMaterialNode node, MaterialSlot outputSlot, GenerationMode mode, ConcreteSlotValueType convertToType, bool textureSampleUVHack = false)
public static string AdaptNodeOutput(AbstractMaterialNode node, MaterialSlot outputSlot, ConcreteSlotValueType convertToType, bool textureSampleUVHack = false)
{
if (outputSlot == null)
return kErrorString;

}
}
private static string AdaptNodeOutputForPreview(AbstractMaterialNode node, MaterialSlot outputSlot, GenerationMode mode, ConcreteSlotValueType convertToType)
private static string AdaptNodeOutputForPreview(AbstractMaterialNode node, MaterialSlot outputSlot, ConcreteSlotValueType convertToType)
{
if (outputSlot == null)
return kErrorString;

// if we are in a normal situation, just convert!
if (convertFromType >= convertToType || convertFromType == ConcreteSlotValueType.Vector1)
return AdaptNodeOutput(node, outputSlot, mode, convertToType);
return AdaptNodeOutput(node, outputSlot, convertToType);
var rawOutput = node.GetOutputVariableNameForSlot(outputSlot);

}
if (generationMode == GenerationMode.Preview2D)
shaderBodyVisitor.AddShaderChunk("return " + AdaptNodeOutputForPreview(node, node.GetOutputSlots<MaterialSlot>().First(), generationMode, ConcreteSlotValueType.Vector4) + ";", true);
shaderBodyVisitor.AddShaderChunk("return " + AdaptNodeOutputForPreview(node, node.GetOutputSlots<MaterialSlot>().First(), ConcreteSlotValueType.Vector4) + ";", true);
shaderBodyVisitor.AddShaderChunk("o.Emission = " + AdaptNodeOutputForPreview(node, node.GetOutputSlots<MaterialSlot>().First(), generationMode, ConcreteSlotValueType.Vector3) + ";", true);
shaderBodyVisitor.AddShaderChunk("o.Emission = " + AdaptNodeOutputForPreview(node, node.GetOutputSlots<MaterialSlot>().First(), ConcreteSlotValueType.Vector3) + ";", true);
template = template.Replace("${ShaderName}", shaderName);
template = template.Replace("${ShaderPropertiesHeader}", shaderPropertiesVisitor.GetShaderString(2));

222
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/DynamicSlotTests.cs


using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Tests
{
[TestFixture]
public class DynamicSlotTests
{
private PixelGraph m_Graph;
private DynamicNode m_DynamicNode;
private TestNode m_StaticNode;
class DynamicNode : AbstractMaterialNode
{
public DynamicNode()
{
AddSlot(new MaterialSlot("DynIn1", "DynIn1", SlotType.Input, 0, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot("DynIn2", "DynIn2", SlotType.Input, 1, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot("DynOut", "DynOut", SlotType.Output, 0, SlotValueType.Dynamic, Vector4.zero));
}
}
class TestNode : AbstractMaterialNode
{
public TestNode()
{
AddSlot(new MaterialSlot("V1Out", "V1Out", SlotType.Output, 0, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot("V2Out", "V2Out", SlotType.Output, 1, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot("V3Out", "V3Out", SlotType.Output, 2, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot("V4Out", "V4Out", SlotType.Output, 3, SlotValueType.Vector4, Vector4.zero));
}
}
[SetUp]
public void TestSetUp()
{
m_Graph = new PixelGraph();
m_DynamicNode = new DynamicNode();
m_Graph.AddNode(m_DynamicNode);
m_StaticNode = new TestNode();
m_Graph.AddNode(m_StaticNode);
}
[Test]
public void DynamicInputsV1NoneWorks()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V1Out"), m_DynamicNode.GetSlotReference("DynIn1"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector1, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV1V1Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V1Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V1Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector1, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV1V2Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V1Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V2Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector2, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV1V3Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V1Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V3Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector3, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV1V4Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V1Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V4Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector4, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV2NoneWorks()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V2Out"), m_DynamicNode.GetSlotReference("DynIn1"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector2, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV2V1Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V2Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V1Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector2, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV2V2Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V2Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V2Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector2, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV2V3Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V2Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V3Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector2, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV2V4Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V2Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V4Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector2, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV3NoneWorks()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V3Out"), m_DynamicNode.GetSlotReference("DynIn1"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector3, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV3V1Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V3Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V1Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector3, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV3V2Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V3Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V2Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector2, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV3V3Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V3Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V3Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector3, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV3V4Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V3Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V4Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector3, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV4NoneWorks()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V4Out"), m_DynamicNode.GetSlotReference("DynIn1"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector4, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV4V1Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V4Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V1Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector4, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV4V2Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V4Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V2Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector2, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV4V3Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V4Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V3Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector3, dynOut1.concreteValueType);
}
[Test]
public void DynamicInputsV4V4Works()
{
m_Graph.Connect(m_StaticNode.GetSlotReference("V4Out"), m_DynamicNode.GetSlotReference("DynIn1"));
m_Graph.Connect(m_StaticNode.GetSlotReference("V4Out"), m_DynamicNode.GetSlotReference("DynIn2"));
var dynOut1 = m_DynamicNode.FindOutputSlot<MaterialSlot>("DynOut");
Assert.AreEqual(ConcreteSlotValueType.Vector4, dynOut1.concreteValueType);
}
}
}

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


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

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


using System.Linq;
using NUnit.Framework;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Tests
{
[TestFixture]
public class MaterialNodeTests
{
[Test]
public void TestCanAddMaterialNodeToMaterialGraph()
{
/*var graph = new PixelGraph();
graph.AddNode(new PixelShaderNode());
var node = new AbstractMaterialGraphTests.TestableMNode();
graph.AddNode(node);
Assert.AreEqual(0, graph.edges.Count());
Assert.AreEqual(1, graph.GetNodes<AbstractMaterialNode>().Count());*/
}
}
}

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


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

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


using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Tests
{
[TestFixture]
public class ShaderGeneratorTests
{
[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 TestNode()
{
AddSlot(new MaterialSlot("V1Out", "V1Out", SlotType.Output, 0, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot("V2Out", "V2Out", SlotType.Output, 1, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot("V3Out", "V3Out", SlotType.Output, 2, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot("V4Out", "V4Out", SlotType.Output, 3, SlotValueType.Vector4, Vector4.zero));
}
}
[Test]
public void AdaptNodeOutput1To1Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V1Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector1);
Assert.AreEqual(string.Format("{0}", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput1To2Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V1Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector2);
Assert.AreEqual(string.Format("({0})", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput1To3Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V1Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector3);
Assert.AreEqual(string.Format("({0})", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput1To4Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V1Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector4);
Assert.AreEqual(string.Format("({0})", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput2To1Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V2Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector1);
Assert.AreEqual(string.Format("({0}).x", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput2To2Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V2Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector2);
Assert.AreEqual(string.Format("{0}", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput2To3CausesError()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V2Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector3);
Assert.AreEqual("ERROR!", result);
}
[Test]
public void AdaptNodeOutput2To4CausesError()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V2Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector4);
Assert.AreEqual("ERROR!", result);
}
[Test]
public void AdaptNodeOutput3To1Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V3Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector1);
Assert.AreEqual(string.Format("({0}).x", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput3To2Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V3Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector2);
Assert.AreEqual(string.Format("({0}.xy)", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput3To3Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V3Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector3);
Assert.AreEqual(string.Format("{0}", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput3To4CausesError()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V3Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector4);
Assert.AreEqual("ERROR!", result);
}
[Test]
public void AdaptNodeOutput4To1Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V4Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector1);
Assert.AreEqual(string.Format("({0}).x", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput4To2Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V4Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector2);
Assert.AreEqual(string.Format("({0}.xy)", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput4To3Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V4Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector3);
Assert.AreEqual(string.Format("({0}.xyz)", node.GetOutputVariableNameForSlot(slot)), result);
}
[Test]
public void AdaptNodeOutput4To4Works()
{
var node = new TestNode();
var slot = node.FindOutputSlot<MaterialSlot>("V4Out");
var result = ShaderGenerator.AdaptNodeOutput(node, slot, ConcreteSlotValueType.Vector4);
Assert.AreEqual(string.Format("{0}", node.GetOutputVariableNameForSlot(slot)), result);
}
}
}

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


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