Tim Cooper
8 年前
当前提交
4b1458e8
共有 16 个文件被更改,包括 208 次插入 和 705 次删除
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function4InputTests.cs
-
73MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/ContrastNode.cs
-
51MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Interpolation/InverseLerpNode.cs
-
35MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Interpolation/LerpNode.cs
-
35MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Interpolation/SmoothStepNode.cs
-
35MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/ClampNode.cs
-
71MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/BoxNode.cs
-
64MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/CheckerboardNode.cs
-
77MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/LineNode.cs
-
82MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/SpherizeNode.cs
-
70MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/UVPannerNode.cs
-
69MaterialGraphProject/Assets/_MingWai/RandomRangeNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs.meta
-
104MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs
-
125MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function3Input.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function3Input.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 319ea7b69d18d06478a0589a5a95a32c |
|||
timeCreated: 1469189950 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.UnitTests |
|||
{ |
|||
[TestFixture] |
|||
public class Function3InputTests |
|||
{ |
|||
private class Function3InputTestNode : Function3Input, IGeneratesFunction |
|||
{ |
|||
public Function3InputTestNode() |
|||
{ |
|||
name = "Function3InputTestNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_test_" + precision; |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2", "arg3"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return arg1 + arg2 + arg3;", 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 Vector1Node m_InputThree; |
|||
private Function3InputTestNode 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_InputThree = new Vector1Node(); |
|||
m_TestNode = new Function3InputTestNode(); |
|||
|
|||
m_Graph.AddNode(m_InputOne); |
|||
m_Graph.AddNode(m_InputTwo); |
|||
m_Graph.AddNode(m_InputThree); |
|||
m_Graph.AddNode(m_TestNode); |
|||
m_Graph.AddNode(new MetallicMasterNode()); |
|||
|
|||
m_InputOne.value = 0.2f; |
|||
m_InputTwo.value = 0.3f; |
|||
m_InputThree.value = 0.6f; |
|||
|
|||
m_Graph.Connect(m_InputOne.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function3Input.InputSlot1Id)); |
|||
m_Graph.Connect(m_InputTwo.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function3Input.InputSlot2Id)); |
|||
m_Graph.Connect(m_InputThree.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function3Input.InputSlot3Id)); |
|||
m_Graph.Connect(m_TestNode.GetSlotReference(Function3Input.OutputSlotId), m_Graph.masterNode.GetSlotReference(MetallicMasterNode.NormalSlotId)); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestGenerateNodeCodeGeneratesCorrectCode() |
|||
{ |
|||
string expected = string.Format("half {0} = unity_test_half ({1}, {2}, {3});{4}" |
|||
, m_TestNode.GetVariableNameForSlot(Function3Input.OutputSlotId) |
|||
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId) |
|||
, m_InputTwo.GetVariableNameForSlot(Vector1Node.OutputSlotId) |
|||
, m_InputThree.GetVariableNameForSlot(Vector1Node.OutputSlotId) |
|||
, Environment.NewLine); |
|||
|
|||
ShaderGenerator visitor = new ShaderGenerator(); |
|||
m_TestNode.GenerateNodeCode(visitor, GenerationMode.ForReals); |
|||
Assert.AreEqual(expected, visitor.GetShaderString(0)); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestGenerateNodeFunctionGeneratesCorrectCode() |
|||
{ |
|||
string expected = |
|||
"inline half unity_test_half (half arg1, half arg2, half arg3)" + Environment.NewLine |
|||
+ "{" + Environment.NewLine |
|||
+ "\treturn arg1 + arg2 + arg3;" + Environment.NewLine |
|||
+ "}" + Environment.NewLine; |
|||
|
|||
ShaderGenerator visitor = new ShaderGenerator(); |
|||
m_TestNode.GenerateNodeFunction(visitor, GenerationMode.ForReals); |
|||
Assert.AreEqual(expected, visitor.GetShaderString(0)); |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public abstract class Function3Input : AbstractMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
protected const string kInputSlot1ShaderName = "Input1"; |
|||
protected const string kInputSlot2ShaderName = "Input2"; |
|||
protected const string kInputSlot3ShaderName = "Input3"; |
|||
protected const string kOutputSlotShaderName = "Output"; |
|||
|
|||
public const int InputSlot1Id = 0; |
|||
public const int InputSlot2Id = 1; |
|||
public const int InputSlot3Id = 2; |
|||
public const int OutputSlotId = 3; |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
protected Function3Input() |
|||
{ |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(GetInputSlot1()); |
|||
AddSlot(GetInputSlot2()); |
|||
AddSlot(GetInputSlot3()); |
|||
AddSlot(GetOutputSlot()); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] {InputSlot1Id, InputSlot2Id, InputSlot3Id, 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 GetInputSlot3() |
|||
{ |
|||
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, 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 GetInputSlot3Name() |
|||
{ |
|||
return "Input3"; |
|||
} |
|||
|
|||
protected virtual string GetOutputSlotName() |
|||
{ |
|||
return "Output"; |
|||
} |
|||
|
|||
protected abstract string GetFunctionName(); |
|||
|
|||
protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name) |
|||
{ |
|||
return "inline " + precision + outputDimension + " " + GetFunctionName() + " (" |
|||
+ precision + input1Dimension + " " + arg1Name + ", " |
|||
+ precision + input2Dimension + " " + arg2Name + ", " |
|||
+ precision + input3Dimension + " " + arg3Name + ")"; |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id, InputSlot3Id }, new[] { OutputSlotId }); |
|||
string input1Value = GetSlotValue(InputSlot1Id, generationMode); |
|||
string input2Value = GetSlotValue(InputSlot2Id, generationMode); |
|||
string input3Value = GetSlotValue(InputSlot3Id, generationMode); |
|||
|
|||
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value, input3Value) + ";", true); |
|||
} |
|||
|
|||
protected virtual string GetFunctionCallBody(string inputValue1, string inputValue2, string inputValue3) |
|||
{ |
|||
return GetFunctionName() + " (" + inputValue1 + ", " + inputValue2 + ", " + inputValue3 + ")"; |
|||
} |
|||
|
|||
public string outputDimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); } |
|||
} |
|||
private string input1Dimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); } |
|||
} |
|||
|
|||
private string input2Dimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); } |
|||
} |
|||
|
|||
public string input3Dimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot3Id).concreteValueType); } |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e7d8fb926f570fb48b10d7d068d54123 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
撰写
预览
正在加载...
取消
保存
Reference in new issue