Tim Cooper
9 年前
当前提交
a9673209
共有 6 个文件被更改,包括 334 次插入 和 0 次删除
-
93MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs.meta
-
100MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs.meta
-
105MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs.meta
|
|||
using System; |
|||
using System.Linq; |
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.UnitTests |
|||
{ |
|||
[TestFixture] |
|||
public class Function1InputTests |
|||
{ |
|||
private class Function1InputTestNode : Function1Input, IGeneratesFunction |
|||
{ |
|||
public Function1InputTestNode() |
|||
{ |
|||
name = "Function1InputTestNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_test_" + precision; |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return arg;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
|
|||
private PixelGraph m_Graph; |
|||
private Vector1Node m_InputOne; |
|||
private Function1InputTestNode m_TestNode; |
|||
|
|||
[TestFixtureSetUp] |
|||
public void RunBeforeAnyTests() |
|||
{ |
|||
Debug.logger.logHandler = new ConsoleLogHandler(); |
|||
} |
|||
|
|||
[SetUp] |
|||
public void TestSetUp() |
|||
{ |
|||
m_Graph = new PixelGraph(); |
|||
m_InputOne = new Vector1Node(); |
|||
m_TestNode = new Function1InputTestNode(); |
|||
|
|||
m_Graph.AddNode(m_InputOne); |
|||
m_Graph.AddNode(m_TestNode); |
|||
m_Graph.AddNode(new PixelShaderNode()); |
|||
|
|||
m_InputOne.value = 0.2f; |
|||
|
|||
m_Graph.Connect(m_InputOne.GetSlotReference("Value"), m_TestNode.GetSlotReference("Input")); |
|||
m_Graph.Connect(m_TestNode.GetSlotReference("Output"), m_Graph.pixelMasterNode.GetSlotReference("Emission")); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestGenerateNodeCodeGeneratesCorrectCode() |
|||
{ |
|||
string expected = string.Format("half {0} = unity_test_half ({1});" |
|||
, m_TestNode.GetVariableNameForSlot(m_TestNode.GetOutputSlots<MaterialSlot>().FirstOrDefault()) |
|||
, m_InputOne.GetVariableNameForSlot(m_InputOne.GetOutputSlots<MaterialSlot>().FirstOrDefault()) |
|||
); |
|||
|
|||
ShaderGenerator visitor = new ShaderGenerator(); |
|||
m_TestNode.GenerateNodeCode(visitor, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestGenerateNodeFunctionGeneratesCorrectCode() |
|||
{ |
|||
string expected = |
|||
"inline half unity_test_half (half arg)\r\n" |
|||
+ "{\r\n" |
|||
+ " return arg;\r\n" |
|||
+ "}"; |
|||
|
|||
ShaderGenerator visitor = new ShaderGenerator(); |
|||
m_TestNode.GenerateNodeFunction(visitor, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim()); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: de1c9bb0cf32ee84ca8c84f411e1358a |
|||
timeCreated: 1469188769 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Linq; |
|||
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 PixelGraph m_Graph; |
|||
private Vector1Node m_InputOne; |
|||
private Vector1Node m_InputTwo; |
|||
private Function2InputTestNode m_TestNode; |
|||
|
|||
[TestFixtureSetUp] |
|||
public void RunBeforeAnyTests() |
|||
{ |
|||
Debug.logger.logHandler = new ConsoleLogHandler(); |
|||
} |
|||
|
|||
[SetUp] |
|||
public void TestSetUp() |
|||
{ |
|||
m_Graph = new PixelGraph(); |
|||
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 PixelShaderNode()); |
|||
|
|||
m_InputOne.value = 0.2f; |
|||
m_InputTwo.value = 0.3f; |
|||
|
|||
m_Graph.Connect(m_InputOne.GetSlotReference("Value"), m_TestNode.GetSlotReference("Input1")); |
|||
m_Graph.Connect(m_InputTwo.GetSlotReference("Value"), m_TestNode.GetSlotReference("Input2")); |
|||
m_Graph.Connect(m_TestNode.GetSlotReference("Output"), m_Graph.pixelMasterNode.GetSlotReference("Emission")); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestGenerateNodeCodeGeneratesCorrectCode() |
|||
{ |
|||
string expected = string.Format("half {0} = unity_test_half ({1}, {2});" |
|||
, m_TestNode.GetVariableNameForSlot(m_TestNode.GetOutputSlots<MaterialSlot>().FirstOrDefault()) |
|||
, m_InputOne.GetVariableNameForSlot(m_InputOne.GetOutputSlots<MaterialSlot>().FirstOrDefault()) |
|||
, m_InputTwo.GetVariableNameForSlot(m_InputTwo.GetOutputSlots<MaterialSlot>().FirstOrDefault()) |
|||
); |
|||
|
|||
ShaderGenerator visitor = new ShaderGenerator(); |
|||
m_TestNode.GenerateNodeCode(visitor, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestGenerateNodeFunctionGeneratesCorrectCode() |
|||
{ |
|||
string expected = |
|||
"inline half unity_test_half (half arg1, half arg2)\r\n" |
|||
+ "{\r\n" |
|||
+ " return arg1 + arg2;\r\n" |
|||
+ "}"; |
|||
|
|||
ShaderGenerator visitor = new ShaderGenerator(); |
|||
m_TestNode.GenerateNodeFunction(visitor, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim()); |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 05783a40a9e3fe24ea0f2c17c95629b1 |
|||
timeCreated: 1466414003 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Linq; |
|||
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 PixelGraph m_Graph; |
|||
private Vector1Node m_InputOne; |
|||
private Vector1Node m_InputTwo; |
|||
private Vector1Node m_InputThree; |
|||
private Function3InputTestNode m_TestNode; |
|||
|
|||
[TestFixtureSetUp] |
|||
public void RunBeforeAnyTests() |
|||
{ |
|||
Debug.logger.logHandler = new ConsoleLogHandler(); |
|||
} |
|||
|
|||
[SetUp] |
|||
public void TestSetUp() |
|||
{ |
|||
m_Graph = new PixelGraph(); |
|||
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 PixelShaderNode()); |
|||
|
|||
m_InputOne.value = 0.2f; |
|||
m_InputTwo.value = 0.3f; |
|||
m_InputThree.value = 0.6f; |
|||
|
|||
m_Graph.Connect(m_InputOne.GetSlotReference("Value"), m_TestNode.GetSlotReference("Input1")); |
|||
m_Graph.Connect(m_InputTwo.GetSlotReference("Value"), m_TestNode.GetSlotReference("Input2")); |
|||
m_Graph.Connect(m_InputThree.GetSlotReference("Value"), m_TestNode.GetSlotReference("Input3")); |
|||
m_Graph.Connect(m_TestNode.GetSlotReference("Output"), m_Graph.pixelMasterNode.GetSlotReference("Emission")); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestGenerateNodeCodeGeneratesCorrectCode() |
|||
{ |
|||
string expected = string.Format("half {0} = unity_test_half ({1}, {2}, {3});" |
|||
, m_TestNode.GetVariableNameForSlot(m_TestNode.GetOutputSlots<MaterialSlot>().FirstOrDefault()) |
|||
, m_InputOne.GetVariableNameForSlot(m_InputOne.GetOutputSlots<MaterialSlot>().FirstOrDefault()) |
|||
, m_InputTwo.GetVariableNameForSlot(m_InputTwo.GetOutputSlots<MaterialSlot>().FirstOrDefault()) |
|||
, m_InputThree.GetVariableNameForSlot(m_InputThree.GetOutputSlots<MaterialSlot>().FirstOrDefault()) |
|||
); |
|||
|
|||
ShaderGenerator visitor = new ShaderGenerator(); |
|||
m_TestNode.GenerateNodeCode(visitor, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestGenerateNodeFunctionGeneratesCorrectCode() |
|||
{ |
|||
string expected = |
|||
"inline half unity_test_half (half arg1, half arg2, half arg3)\r\n" |
|||
+ "{\r\n" |
|||
+ " return arg1 + arg2 + arg3;\r\n" |
|||
+ "}"; |
|||
|
|||
ShaderGenerator visitor = new ShaderGenerator(); |
|||
m_TestNode.GenerateNodeFunction(visitor, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim()); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 319ea7b69d18d06478a0589a5a95a32c |
|||
timeCreated: 1469189950 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue