浏览代码
[Material Graph]Adding property node tests + pixel node tests + tidy API as I go (light functions specifically)
/main
[Material Graph]Adding property node tests + pixel node tests + tidy API as I go (light functions specifically)
/main
Tim Cooper
8 年前
当前提交
cc192491
共有 25 个文件被更改,包括 534 次插入 和 105 次删除
-
4MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/CopySelected.cs
-
10MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/IntegrationTests/SerializationTests.cs
-
4MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
-
14MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs
-
97MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/SerializationHelper.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/PixelShaderNodeUI.cs
-
51MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Light/BaseLightFunction.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbsoluteNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ColorNode.cs
-
71MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PixelShaderNode.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UnpackNormalNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector2Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector3Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector4Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/FixedSlotTests.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs.meta
-
94MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PixelShaderNodeTests.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PixelShaderNodeTests.cs.meta
-
209MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 3fe1a12f346cde14f8ec5d42b2e4b70f |
|||
timeCreated: 1469709562 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a55bb4eb9ba26c846902a616c2ea29ff |
|||
timeCreated: 1469709562 |
|||
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 PixelShaderNodeTests |
|||
{ |
|||
private PixelGraph m_Graph; |
|||
private Vector1Node m_InputOne; |
|||
private AbsoluteNode m_Abs; |
|||
private PixelShaderNode m_PixelNode; |
|||
|
|||
[TestFixtureSetUp] |
|||
public void RunBeforeAnyTests() |
|||
{ |
|||
Debug.logger.logHandler = new ConsoleLogHandler(); |
|||
} |
|||
|
|||
[SetUp] |
|||
public void TestSetUp() |
|||
{ |
|||
m_Graph = new PixelGraph(); |
|||
m_InputOne = new Vector1Node(); |
|||
m_Abs = new AbsoluteNode(); |
|||
m_PixelNode = new PixelShaderNode(); |
|||
m_PixelNode.lightFunction = new PBRMetalicLightFunction(); |
|||
|
|||
m_Graph.AddNode(m_InputOne); |
|||
m_Graph.AddNode(m_PixelNode); |
|||
m_Graph.AddNode(m_Abs); |
|||
|
|||
m_InputOne.value = 0.2f; |
|||
|
|||
m_Graph.Connect(m_InputOne.GetSlotReference(Vector1Node.OutputSlotId), m_PixelNode.GetSlotReference(BaseLightFunction.NormalSlotId)); |
|||
|
|||
|
|||
m_Graph.Connect(m_InputOne.GetSlotReference(Vector1Node.OutputSlotId), m_Abs.GetSlotReference(Function1Input.InputSlotId)); |
|||
m_Graph.Connect(m_Abs.GetSlotReference(Function1Input.OutputSlotId), m_PixelNode.GetSlotReference(PBRMetalicLightFunction.AlbedoSlotId)); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestNodeGeneratesLightFuntionProperly() |
|||
{ |
|||
var generator = new ShaderGenerator(); |
|||
m_PixelNode.GenerateLightFunction(generator); |
|||
|
|||
Assert.AreEqual(string.Empty, generator.GetShaderString(0)); |
|||
Assert.AreEqual(PBRMetalicLightFunction.LightFunctionName, generator.GetPragmaString()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestNodeGenerateSurfaceOutputProperly() |
|||
{ |
|||
var generator = new ShaderGenerator(); |
|||
m_PixelNode.GenerateSurfaceOutput(generator); |
|||
|
|||
Assert.AreEqual(string.Empty, generator.GetShaderString(0)); |
|||
Assert.AreEqual(PBRMetalicLightFunction.SurfaceOutputStructureName, generator.GetPragmaString()); |
|||
} |
|||
|
|||
|
|||
[Test] |
|||
public void TestNodeGeneratesCorrectNodeCode() |
|||
{ |
|||
string expected = string.Format("half {0} = 0.2;\r\n" |
|||
+ "o.Normal = {0};\r\n" |
|||
+ "half {1} = abs ({0});\r\n" |
|||
+ "o.Albedo = {1};\r\n" |
|||
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId) |
|||
, m_Abs.GetVariableNameForSlot(Function1Input.OutputSlotId)); |
|||
|
|||
var generator = new ShaderGenerator(); |
|||
m_PixelNode.GenerateNodeCode(generator, GenerationMode.SurfaceShader); |
|||
|
|||
Console.WriteLine(generator.GetShaderString(0)); |
|||
|
|||
Assert.AreEqual(expected, generator.GetShaderString(0)); |
|||
Assert.AreEqual(string.Empty, generator.GetPragmaString()); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestPixelShaderNodeReturnsBuiltinPBRLights() |
|||
{ |
|||
var lightingFuncs = PixelShaderNode.GetLightFunctions(); |
|||
Assert.AreEqual(1, lightingFuncs.OfType<PBRMetalicLightFunction>().Count()); |
|||
Assert.AreEqual(1, lightingFuncs.OfType<PBRSpecularLightFunction>().Count()); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: caaa2ea3bc3f57c429e630f9324ac930 |
|||
timeCreated: 1469792183 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.UnitTests |
|||
{ |
|||
[TestFixture] |
|||
public class PropertyNodeTests |
|||
{ |
|||
private class TestPropertyNode : PropertyNode |
|||
{ |
|||
public const string TestPropertyName = "TestName"; |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Float;} |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty() |
|||
{ |
|||
m_Name = TestPropertyName |
|||
}; |
|||
} |
|||
} |
|||
|
|||
private PixelGraph m_Graph; |
|||
private Vector1Node m_Vector1Node; |
|||
private Vector2Node m_Vector2Node; |
|||
private Vector3Node m_Vector3Node; |
|||
private Vector4Node m_Vector4Node; |
|||
private ColorNode m_ColorNode; |
|||
private TextureNode m_TextureNode; |
|||
private TestPropertyNode m_PropertyNode; |
|||
|
|||
private const string kPropertyName = "PropertyName"; |
|||
public const string kDescription = "NewDescription"; |
|||
|
|||
[TestFixtureSetUp] |
|||
public void RunBeforeAnyTests() |
|||
{ |
|||
Debug.logger.logHandler = new ConsoleLogHandler(); |
|||
} |
|||
|
|||
[SetUp] |
|||
public void TestSetUp() |
|||
{ |
|||
m_Graph = new PixelGraph(); |
|||
m_Vector1Node = new Vector1Node(); |
|||
m_Vector2Node = new Vector2Node(); |
|||
m_Vector3Node = new Vector3Node(); |
|||
m_Vector4Node = new Vector4Node(); |
|||
m_ColorNode = new ColorNode(); |
|||
m_TextureNode = new TextureNode(); |
|||
m_PropertyNode = new TestPropertyNode(); |
|||
|
|||
m_Graph.AddNode(m_Vector1Node); |
|||
m_Graph.AddNode(m_Vector2Node); |
|||
m_Graph.AddNode(m_Vector3Node); |
|||
m_Graph.AddNode(m_Vector4Node); |
|||
m_Graph.AddNode(m_ColorNode); |
|||
m_Graph.AddNode(m_TextureNode); |
|||
m_Graph.AddNode(m_PropertyNode); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestExposedPropertyReturnsRawName() |
|||
{ |
|||
m_PropertyNode.exposedState = PropertyNode.ExposedState.Exposed; |
|||
m_PropertyNode.propertyName = kPropertyName; |
|||
Assert.AreEqual(kPropertyName + "_Uniform", m_PropertyNode.propertyName); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestNonExposedPropertyReturnsGeneratedName() |
|||
{ |
|||
var expected = string.Format("{0}_{1}_Uniform", m_PropertyNode.name, m_PropertyNode.guid.ToString().Replace("-", "_")); |
|||
m_PropertyNode.exposedState = PropertyNode.ExposedState.NotExposed; |
|||
m_PropertyNode.propertyName = kPropertyName; |
|||
|
|||
Assert.AreEqual(expected, m_PropertyNode.propertyName); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestPropertyNodeDescriptionWorks() |
|||
{ |
|||
m_PropertyNode.propertyName = kPropertyName; |
|||
m_PropertyNode.description = kDescription; |
|||
Assert.AreEqual(kDescription, m_PropertyNode.description); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestPropertyNodeDescriptionReturnsPropertyNameWhenNoDescriptionSet() |
|||
{ |
|||
m_PropertyNode.propertyName = kPropertyName; |
|||
m_PropertyNode.description = string.Empty; |
|||
Assert.AreEqual(kPropertyName, m_PropertyNode.description); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestPropertyNodeReturnsPreviewProperty() |
|||
{ |
|||
var props = new List<PreviewProperty>(); |
|||
m_PropertyNode.CollectPreviewMaterialProperties(props); |
|||
Assert.AreEqual(props.Count, 1); |
|||
Assert.AreEqual(TestPropertyNode.TestPropertyName, props[0].m_Name); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestDuplicatedPropertyNameGeneratesErrorWhenExposed() |
|||
{ |
|||
const string failName = "SameName"; |
|||
|
|||
m_Vector1Node.exposedState = PropertyNode.ExposedState.Exposed; |
|||
m_Vector1Node.propertyName = failName; |
|||
m_Vector2Node.exposedState = PropertyNode.ExposedState.Exposed; |
|||
m_Vector2Node.propertyName = failName; |
|||
|
|||
m_Vector1Node.ValidateNode(); |
|||
m_Vector2Node.ValidateNode(); |
|||
Assert.IsTrue(m_Vector1Node.hasError); |
|||
Assert.IsTrue(m_Vector2Node.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestDuplicatedPropertyNameGeneratesNoErrorWhenNotExposed() |
|||
{ |
|||
const string failName = "SameName"; |
|||
|
|||
m_Vector1Node.exposedState = PropertyNode.ExposedState.NotExposed; |
|||
m_Vector1Node.propertyName = failName; |
|||
m_Vector2Node.exposedState = PropertyNode.ExposedState.Exposed; |
|||
m_Vector2Node.propertyName = failName; |
|||
|
|||
m_Vector1Node.ValidateNode(); |
|||
m_Vector2Node.ValidateNode(); |
|||
Assert.IsFalse(m_Vector1Node.hasError); |
|||
Assert.IsFalse(m_Vector2Node.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestVector1NodeTypeIsCorrect() |
|||
{ |
|||
Assert.AreEqual(PropertyType.Float, m_Vector1Node.propertyType); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestVector1NodeReturnsCorrectValue() |
|||
{ |
|||
m_Vector1Node.value = 0.6f; |
|||
Assert.AreEqual(0.6f, m_Vector1Node.value); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestVector1NodeReturnsPreviewProperty() |
|||
{ |
|||
var props = new List<PreviewProperty>(); |
|||
m_Vector1Node.value = 0.6f; |
|||
m_Vector1Node.CollectPreviewMaterialProperties(props); |
|||
Assert.AreEqual(props.Count, 1); |
|||
Assert.AreEqual(m_Vector1Node.propertyName, props[0].m_Name); |
|||
Assert.AreEqual(m_Vector1Node.propertyType, props[0].m_PropType); |
|||
Assert.AreEqual(0.6f, props[0].m_Float); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestVector1NodeGeneratesCorrectPropertyBlock() |
|||
{ |
|||
m_Vector1Node.value = 0.6f; |
|||
m_Vector1Node.exposedState = PropertyNode.ExposedState.NotExposed; |
|||
var generator = new PropertyGenerator(); |
|||
m_Vector1Node.GeneratePropertyBlock(generator, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(string.Empty, generator.GetShaderString(0)); |
|||
|
|||
var expected = m_Vector1Node.propertyName |
|||
+ "(\"" |
|||
+ m_Vector1Node.description |
|||
+ "\", Float) = " |
|||
+ m_Vector1Node.value |
|||
+ "\n"; |
|||
|
|||
m_Vector1Node.exposedState = PropertyNode.ExposedState.Exposed; |
|||
m_Vector1Node.GeneratePropertyBlock(generator, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(expected, generator.GetShaderString(0)); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestVector1NodeGeneratesCorrectPropertyUsages() |
|||
{ |
|||
m_Vector1Node.value = 0.6f; |
|||
m_Vector1Node.exposedState = PropertyNode.ExposedState.NotExposed; |
|||
var generator = new ShaderGenerator(); |
|||
m_Vector1Node.GeneratePropertyUsages(generator, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(string.Empty, generator.GetShaderString(0)); |
|||
|
|||
var expected = m_Vector1Node.precision |
|||
+ " " |
|||
+ m_Vector1Node.propertyName |
|||
+ ";\r\n"; |
|||
|
|||
m_Vector1Node.exposedState = PropertyNode.ExposedState.Exposed; |
|||
m_Vector1Node.GeneratePropertyUsages(generator, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(expected, generator.GetShaderString(0)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fc814c257422bf1449688696b94fae44 |
|||
timeCreated: 1469792183 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue