Assert.AreEqual(3, result.Count);
result.Clear();
NodeUtils.DepthFirstCollectNodesFromNode(result, inputNode);
Assert.AreEqual(1, result.Count);
NodeUtils.DepthFirstCollectNodesFromNode(result, inputNode, NodeUtils.IncludeSelf.Exclude);
Assert.AreEqual(0, result.Count);
NodeUtils.DepthFirstCollectNodesFromNode(result, null);
public void RemoveSlot(int slotId)
{
//Remove edges that use this slot
var edges = owner.GetEdges(GetSlotReference(slotId));
// Remove edges that use this slot
// no owner can happen after creation
// but before added to graph
if (owner != null)
foreach (var edge in edges.ToArray())
owner.RemoveEdge(edge);
}
//remove slots
m_Slots.RemoveAll(x => x.id == slotId);
var slotTexture2D = FindOutputSlot<MaterialSlot>(0);
if (slotTexture2D != null)
var edgesTexture2D = owner.GetEdges(slotTexture2D.slotReference).ToList();
if (edgesTexture2D.Count > 0)
visitor.AddShaderChunk("UNITY_DECLARE_TEX2D(" + propertyName + ");", true);
m_TextureNode.exposedState = PropertyNode.ExposedState.NotExposed;
var generator = new ShaderGenerator();
m_TextureNode.GeneratePropertyUsages(generator, GenerationMode.ForReals);
var expected = "sampler2D "
var expected = "UNITY_DECLARE_TEX2D("
+ ";"
+ ");"
+ Environment.NewLine;
Assert.AreEqual(expected, generator.GetShaderString(0));
Assert.AreEqual("2", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector2));
Assert.AreEqual("3", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector3));
Assert.AreEqual("4", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector4));
Assert.AreEqual("5", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Error));
Assert.AreEqual("Texture2D", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Texture2D));
Assert.AreEqual("2x2", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Matrix2));
Assert.AreEqual("3x3", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Matrix3));
Assert.AreEqual("4x4", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Matrix4));
Assert.AreEqual("SamplerState", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.SamplerState));
Assert.AreEqual("Error", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Error));
var pp = properties.FirstOrDefault();
Assert.AreEqual(m_NodeA.GetVariableNameForSlot(slot.id), pp.m_Name);
Assert.AreEqual(PropertyType.Vector4, pp.m_PropType);
Assert.AreEqual(PropertyType.Float, pp.m_PropType);
Assert.AreEqual(slot.currentValue, pp.m_Vector4);
m_Graph = new UnityEngine.MaterialGraph.MaterialGraph();
m_NodeA = new TestNode();
m_NodeA.precision = AbstractMaterialNode.OutputPrecision.half;
m_Graph.AddNode(m_NodeA);
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutput(node, TestNode.V1Out, ConcreteSlotValueType.Vector2);
Assert.AreEqual(string.Format("({0})", node.GetVariableNameForSlot(TestNode.V1Out)), result);
Assert.AreEqual(string.Format("({0}.xx)", node.GetVariableNameForSlot(TestNode.V1Out)), result);
[Test]
var result = ShaderGenerator.AdaptNodeOutput(node, TestNode.V1Out, ConcreteSlotValueType.Vector3);
Assert.AreEqual(string.Format("({0}.xxx)", node.GetVariableNameForSlot(TestNode.V1Out)), result);
var result = ShaderGenerator.AdaptNodeOutput(node, TestNode.V1Out, ConcreteSlotValueType.Vector4);
Assert.AreEqual(string.Format("({0}.xxxx)", node.GetVariableNameForSlot(TestNode.V1Out)), result);
var result = ShaderGenerator.AdaptNodeOutput(node, TestNode.V4Out, ConcreteSlotValueType.Vector4);
Assert.AreEqual(string.Format("{0}", node.GetVariableNameForSlot(TestNode.V4Out)), result);
public void AdaptNodeOutput1To4PreviewWorks()
public void AdaptNodeOutput2To4PreviewWorks()
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V3Out);
Assert.AreEqual(expected, result);
public void AdaptNodeOutput4To4PreviewWorks()
if (toCount <= fromCount)
return true;
return from >= to || from == ConcreteSlotValueType.Vector1;
return false;
private ConcreteSlotValueType ConvertDynamicInputTypeToConcrete(IEnumerable<ConcreteSlotValueType> inputTypes)
default:
// find the 'minumum' channel width excluding 1 as it can promote
inputTypesDistinct.RemoveAll(x => x == ConcreteSlotValueType.Vector1);
var ordered = inputTypesDistinct.OrderBy(x => x);
var ordered = inputTypesDistinct.OrderByDescending(x => x);
if (ordered.Any())
return ordered.FirstOrDefault();
break;