浏览代码

Remove Function2Input node as it is no longer needed.

/main
Tim Cooper 8 年前
当前提交
3198bd43
共有 8 个文件被更改,包括 5 次插入243 次删除
  1. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ConvolutionFilterNodePresenter.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  3. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters/ConvolutionFilterNode.cs
  4. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs.meta
  5. 113
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs
  6. 105
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function2Input.cs
  7. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function2Input.cs.meta

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ConvolutionFilterNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class ConvolutionFilterControlPresenter : GraphControlPresenter
/*class ConvolutionFilterControlPresenter : GraphControlPresenter
{
enum KernelPresets
{

instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}*/
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


typeMapper[typeof(Matrix4Node)] = typeof(Matrix4NodePresenter);
typeMapper[typeof(MatrixCommonNode)] = typeof(MatrixCommonNodePresenter);
typeMapper[typeof(TransformNode)] = typeof(TransformNodePresenter);
typeMapper[typeof(ConvolutionFilterNode)] = typeof(ConvolutionFilterNodePresenter);
// typeMapper[typeof(ConvolutionFilterNode)] = typeof(ConvolutionFilterNodePresenter);
}
public override List<NodeAnchorPresenter> GetCompatibleAnchors(NodeAnchorPresenter startAnchor, NodeAdapter nodeAdapter)

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters/ConvolutionFilterNode.cs


using System.Linq;
using System;
namespace UnityEngine.MaterialGraph
/*namespace UnityEngine.MaterialGraph
{
[Title("Art/Filters/Convolution")]
public class ConvolutionFilterNode : Function2Input, IGeneratesFunction, IGeneratesBodyCode, IMayRequireMeshUV

return edges.Count == 0;
}
}
}
}*/

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


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

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


using System;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.UnitTests
{
[TestFixture]
public class Function2InputTests
{
private class Function2InputTestNode : Function2Input, IGeneratesFunction
{
public Function2InputTestNode()
{
name = "Function2InputTestNode";
}
protected override string GetFunctionName()
{
return "unity_test_" + precision;
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg1 + arg2;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
private UnityEngine.MaterialGraph.MaterialGraph m_Graph;
private Vector1Node m_InputOne;
private Vector1Node m_InputTwo;
private Function2InputTestNode m_TestNode;
[TestFixtureSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();
}
[SetUp]
public void TestSetUp()
{
m_Graph = new UnityEngine.MaterialGraph.MaterialGraph();
m_InputOne = new Vector1Node();
m_InputTwo = new Vector1Node();
m_TestNode = new Function2InputTestNode();
m_Graph.AddNode(m_InputOne);
m_Graph.AddNode(m_InputTwo);
m_Graph.AddNode(m_TestNode);
m_Graph.AddNode(new MetallicMasterNode());
m_InputOne.value = 0.2f;
m_InputTwo.value = 0.3f;
m_Graph.Connect(m_InputOne.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function2Input.InputSlot1Id));
m_Graph.Connect(m_InputTwo.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function2Input.InputSlot2Id));
m_Graph.Connect(m_TestNode.GetSlotReference(Function2Input.OutputSlotId), m_Graph.masterNode.GetSlotReference(MetallicMasterNode.NormalSlotId));
}
[Test]
public void TestGenerateNodeCodeGeneratesCorrectCode()
{
string expected = string.Format("half {0} = unity_test_half ({1}, {2});{3}"
, m_TestNode.GetVariableNameForSlot(Function2Input.OutputSlotId)
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, m_InputTwo.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, Environment.NewLine
);
ShaderGenerator visitor = new ShaderGenerator();
m_TestNode.GenerateNodeCode(visitor, GenerationMode.ForReals);
Assert.AreEqual(expected, visitor.GetShaderString(0));
}
[Test]
public void TestGenerateNodeFunctionGeneratesCorrectCodeIndent0()
{
string expected =
"inline half unity_test_half (half arg1, half arg2)" + Environment.NewLine
+ "{" + Environment.NewLine
+ "\treturn arg1 + arg2;" + Environment.NewLine
+ "}" + Environment.NewLine;
ShaderGenerator visitor = new ShaderGenerator();
m_TestNode.GenerateNodeFunction(visitor, GenerationMode.ForReals);
Assert.AreEqual(expected, visitor.GetShaderString(0));
}
[Test]
public void TestGenerateNodeFunctionGeneratesCorrectCodeIndent1()
{
string expected =
"\tinline half unity_test_half (half arg1, half arg2)" + Environment.NewLine
+ "\t{" + Environment.NewLine
+ "\t\treturn arg1 + arg2;" + Environment.NewLine
+ "\t}" + Environment.NewLine;
ShaderGenerator visitor = new ShaderGenerator();
m_TestNode.GenerateNodeFunction(visitor, GenerationMode.ForReals);
Assert.AreEqual(expected, visitor.GetShaderString(1));
}
}
}

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


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
public abstract class Function2Input : AbstractMaterialNode, IGeneratesBodyCode
{
protected const string kInputSlot1ShaderName = "Input1";
protected const string kInputSlot2ShaderName = "Input2";
protected const string kOutputSlotShaderName = "Output";
public const int InputSlot1Id = 0;
public const int InputSlot2Id = 1;
public const int OutputSlotId = 2;
public override bool hasPreview
{
get { return true; }
}
protected Function2Input()
{
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputSlot1());
AddSlot(GetInputSlot2());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] {InputSlot1Id, InputSlot2Id, OutputSlotId}; }
}
protected virtual MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual string GetInputSlot1Name()
{
return "Input1";
}
protected virtual string GetInputSlot2Name()
{
return "Input2";
}
protected virtual string GetOutputSlotName()
{
return "Output";
}
protected abstract string GetFunctionName();
protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ")";
}
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id }, new[] { OutputSlotId });
string input1Value = GetSlotValue(InputSlot1Id, generationMode);
string input2Value = GetSlotValue(InputSlot2Id, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value) + ";", true);
}
protected virtual string GetFunctionCallBody(string input1Value, string input2Value)
{
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ")";
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); }
}
protected string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); }
}
protected string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function2Input.cs.meta


fileFormatVersion: 2
guid: 892d91fa7ade87541bac6c322a97b1bb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
正在加载...
取消
保存