Tim Cooper
8 年前
当前提交
8df91eb4
共有 62 个文件被更改,包括 962 次插入 和 1291 次删除
-
22MaterialGraphProject/Assets/Eduardo/ReciprocalSqrtNode.cs
-
4MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
-
1MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/SerializationHelper.cs
-
70MaterialGraphProject/Assets/Matt/TangentToWorldNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/LevelsNodePresenter.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SwizzleNodePresenter.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PixelShaderNodeTests.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/ContrastNode.cs
-
44MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/HueNode.cs
-
158MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/LevelsNode.cs
-
52MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/HSVtoRGBNode.cs
-
50MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/LinearToRGBNode.cs
-
59MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoHSVNode.cs
-
64MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoLinearNode.cs
-
60MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoLuminanceNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SwizzleNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/HLSLNode.cs
-
156MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic/IFNode.cs
-
21MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/AbsoluteNode.cs
-
21MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/LengthNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/LogNode.cs
-
29MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/NegateNode.cs
-
21MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/NormalizeNode.cs
-
29MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/ReciprocalNode.cs
-
40MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Basic/ExponentialNode.cs
-
40MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Basic/SquareRootNode.cs
-
43MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/FractionNode.cs
-
49MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/OneMinus.cs
-
26MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/SaturateNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/CeilNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/FloorNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/RoundNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/SignNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/TruncNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/ArcCosNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/ArcSinNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/ArcTanNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/CosNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/DegreesToRadiansNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/RadiansToDegreesNode.cs
-
26MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/SinCosNode.cs
-
21MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/SinNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/TanNode.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/DDX.cs
-
29MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/DDXY.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/DDY.cs
-
27MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Normal/UnpackNormalNode.cs
-
135MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/NoiseNode.cs
-
48MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/CartesianToPolarNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/SpherizeNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs.meta
-
93MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function4InputTests.cs.meta
-
110MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function4InputTests.cs
-
77MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function1Input.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function1Input.cs.meta
-
145MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function4Input.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function4Input.cs.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Legacy.meta
-
9MaterialGraphProject/Assets/_MingWai/GeneratedTextureDemo/StandardShader.meta
|
|||
using System.Reflection; |
|||
[Title ("Art/Conversion/RGBtoLinear")] |
|||
public class RGBtoLinearNode : Function1Input, IGeneratesFunction |
|||
{ |
|||
public RGBtoLinearNode() |
|||
{ |
|||
name = "RGBtoLinear"; |
|||
} |
|||
|
|||
protected override string GetFunctionName () |
|||
{ |
|||
return "unity_rgbtolinear_" + precision; |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot () |
|||
{ |
|||
return new MaterialSlot (InputSlotId, GetInputSlotName (), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector3, Vector4.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetOutputSlot () |
|||
{ |
|||
return new MaterialSlot (OutputSlotId, GetOutputSlotName (), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero); |
|||
} |
|||
[Title("Art/Conversion/RGBtoLinear")] |
|||
public class RGBtoLinearNode : CodeFunctionNode |
|||
{ |
|||
public RGBtoLinearNode() |
|||
{ |
|||
name = "RGBtoLinear"; |
|||
} |
|||
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator (); |
|||
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false); |
|||
outputString.AddShaderChunk ("{", false); |
|||
outputString.Indent (); |
|||
outputString.AddShaderChunk (precision + "3 linearRGBLo = arg1 / 12.92;", false); |
|||
outputString.AddShaderChunk (precision + "3 linearRGBHi = pow(max(abs((arg1 + 0.055) / 1.055), 1.192092896e-07), "+precision+"3(2.4, 2.4, 2.4));", false); |
|||
outputString.AddShaderChunk ("return " + precision + "3(arg1 <= 0.04045) ? linearRGBLo : linearRGBHi;", false); |
|||
outputString.Deindent (); |
|||
outputString.AddShaderChunk ("}", false); |
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_RGBToLinear", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
visitor.AddShaderChunk (outputString.GetShaderString (0), true); |
|||
} |
|||
} |
|||
static string Unity_RGBToLinear( |
|||
[Slot(0, Binding.None)] Vector3 rgb, |
|||
[Slot(1, Binding.None)] out Vector3 linearColor) |
|||
{ |
|||
linearColor = Vector3.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
//Reference code from:http://www.chilliant.com/rgb2hsv.html
|
|||
{precision}3 linearRGBLo = rgb / 12.92;; |
|||
{precision}3 linearRGBHi = pow(max(abs((rgb + 0.055) / 1.055), 1.192092896e-07), {precision}3(2.4, 2.4, 2.4));; |
|||
linearColor = {precision}3(rgb <= 0.04045) ? linearRGBLo : linearRGBHi; |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine.Graphing; |
|||
using System.Reflection; |
|||
[Title ("Art/Conversion/RGBtoLuminance")] |
|||
public class RGBtoLuminanceNode : Function1Input, IGeneratesFunction |
|||
{ |
|||
public RGBtoLuminanceNode() |
|||
{ |
|||
name = "RGBtoLuminance"; |
|||
} |
|||
|
|||
protected override string GetFunctionName () |
|||
{ |
|||
return "unity_rgbtoluminance_" + precision; |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot () |
|||
{ |
|||
return new MaterialSlot (InputSlotId, GetInputSlotName (), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector3, Vector4.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetOutputSlot () |
|||
{ |
|||
return new MaterialSlot (OutputSlotId, GetOutputSlotName (), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector1, Vector4.zero); |
|||
} |
|||
[Title("Art/Conversion/RGBtoLuminance")] |
|||
public class RGBtoLuminanceNode : CodeFunctionNode |
|||
{ |
|||
public RGBtoLuminanceNode() |
|||
{ |
|||
name = "RGBtoLuminance"; |
|||
} |
|||
// Convert rgb to luminance with rgb in linear space with sRGB primaries and D65 white point (from PostProcessing)
|
|||
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator (); |
|||
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false); |
|||
outputString.AddShaderChunk ("{", false); |
|||
outputString.Indent (); |
|||
outputString.AddShaderChunk ("return dot(arg1, "+precision+outputDimension+"(0.2126729, 0.7151522, 0.0721750));", false); |
|||
outputString.Deindent (); |
|||
outputString.AddShaderChunk ("}", false); |
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_RGBToLuminance", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
visitor.AddShaderChunk (outputString.GetShaderString (0), true); |
|||
} |
|||
} |
|||
static string Unity_RGBToLuminance( |
|||
[Slot(0, Binding.None)] Vector3 rgb, |
|||
[Slot(1, Binding.None)] out Vector1 luminance) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
luminance = dot(rgb, {precision}3(0.2126729, 0.7151522, 0.0721750)); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
namespace UnityEngine.MaterialGraph |
|||
using System.Reflection; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
[Title ("Math/Basic/Exponential")] |
|||
public class ExponentialNode : Function1Input |
|||
{ |
|||
public ExponentialNode () |
|||
{ |
|||
name = "Exponential"; |
|||
} |
|||
[Title("Math/Basic/Exponential")] |
|||
public class ExponentialNode : CodeFunctionNode |
|||
{ |
|||
public ExponentialNode() |
|||
{ |
|||
name = "Exponential"; |
|||
} |
|||
protected override string GetFunctionName () |
|||
{ |
|||
return "exp"; |
|||
} |
|||
} |
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_Exp", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string Unity_Exp( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector argument, |
|||
[Slot(1, Binding.None)] out DynamicDimensionVector result) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
result = exp(argument); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|||
|
|
|||
namespace UnityEngine.MaterialGraph |
|||
using System.Reflection; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
[Title ("Math/Basic/SquareRoot")] |
|||
public class SquareRootNode : Function1Input |
|||
{ |
|||
public SquareRootNode () |
|||
{ |
|||
name = "SquareRoot"; |
|||
} |
|||
[Title("Math/Basic/SquareRoot")] |
|||
public class SquareRootNode : CodeFunctionNode |
|||
{ |
|||
public SquareRootNode() |
|||
{ |
|||
name = "SquareRoot"; |
|||
} |
|||
protected override string GetFunctionName () |
|||
{ |
|||
return "sqrt"; |
|||
} |
|||
} |
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_Sqrt", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string Unity_Sqrt( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector argument, |
|||
[Slot(1, Binding.None)] out DynamicDimensionVector result) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
result = sqrt(argument); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|||
|
|
|||
using System.Reflection; |
|||
|
|||
[Title ("Math/Range/OneMinus")] |
|||
public class OneMinusNode : Function1Input, IGeneratesFunction |
|||
{ |
|||
public OneMinusNode () |
|||
{ |
|||
name = "OneMinus"; |
|||
} |
|||
[Title("Math/Range/OneMinus")] |
|||
public class OneMinusNode : CodeFunctionNode |
|||
{ |
|||
public OneMinusNode() |
|||
{ |
|||
name = "OneMinus"; |
|||
} |
|||
protected override string GetFunctionName () |
|||
{ |
|||
return "unity_oneminus_" + precision; |
|||
} |
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_OneMinus", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator (); |
|||
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false); |
|||
outputString.AddShaderChunk ("{", false); |
|||
outputString.Indent (); |
|||
outputString.AddShaderChunk ("return arg1 * -1 + 1;", false); |
|||
outputString.Deindent (); |
|||
outputString.AddShaderChunk ("}", false); |
|||
|
|||
visitor.AddShaderChunk (outputString.GetShaderString (0), true); |
|||
} |
|||
} |
|||
static string Unity_OneMinus( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector argument, |
|||
[Slot(1, Binding.None)] out DynamicDimensionVector result) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
result = argument * -1 + 1;; |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine.Graphing; |
|||
using System.Reflection; |
|||
public class CartesianToPolarNode : Function1Input, IGeneratesFunction |
|||
public class CartesianToPolarNode : CodeFunctionNode |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_cartesiantopolar_" + precision; |
|||
} |
|||
|
|||
protected override string GetInputSlotName() |
|||
{ |
|||
return "UV"; |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot() |
|||
{ |
|||
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector2, Vector2.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetOutputSlot() |
|||
protected override MethodInfo GetFunctionToConvert() |
|||
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector2, Vector2.zero); |
|||
return GetType().GetMethod("Unity_CartesianToPolar", BindingFlags.Static | BindingFlags.NonPublic); |
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
static string Unity_CartesianToPolar( |
|||
[Slot(0, Binding.MeshUV0)] Vector2 uv, |
|||
[Slot(1, Binding.None)] out Vector3 result) |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype("uv"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("float radius = length(uv);", false); |
|||
outputString.AddShaderChunk("float angle = atan2(uv.x, uv.y);", false); |
|||
outputString.AddShaderChunk("return float2(radius, angle);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
result = Vector3.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
{precision} radius = length(uv); |
|||
{precision} angle = atan2(uv.x, uv.y); |
|||
result = float2(radius, angle); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: de1c9bb0cf32ee84ca8c84f411e1358a |
|||
timeCreated: 1469188769 |
|||
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 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 UnityEngine.MaterialGraph.MaterialGraph m_Graph; |
|||
private Vector1Node m_InputOne; |
|||
private Function1InputTestNode 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_TestNode = new Function1InputTestNode(); |
|||
|
|||
m_Graph.AddNode(m_InputOne); |
|||
m_Graph.AddNode(m_TestNode); |
|||
m_Graph.AddNode(new MetallicMasterNode()); |
|||
|
|||
m_InputOne.value = 0.2f; |
|||
|
|||
m_Graph.Connect(m_InputOne.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function1Input.InputSlotId)); |
|||
m_Graph.Connect(m_TestNode.GetSlotReference(Function1Input.OutputSlotId), m_Graph.masterNode.GetSlotReference(MetallicMasterNode.NormalSlotId)); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestGenerateNodeCodeGeneratesCorrectCode() |
|||
{ |
|||
string expected = string.Format("half {0} = unity_test_half ({1});{2}" |
|||
, m_TestNode.GetVariableNameForSlot(Function1Input.OutputSlotId) |
|||
, m_InputOne.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 arg)" + Environment.NewLine |
|||
+ "{" + Environment.NewLine |
|||
+ "\treturn arg;" + Environment.NewLine |
|||
+ "}" + Environment.NewLine; |
|||
|
|||
ShaderGenerator visitor = new ShaderGenerator(); |
|||
m_TestNode.GenerateNodeFunction(visitor, GenerationMode.ForReals); |
|||
Assert.AreEqual(expected, visitor.GetShaderString(0)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6fc8f3d4460595e44bb2fb21831294a8 |
|||
timeCreated: 1495484604 |
|||
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 Function4InputTests |
|||
{ |
|||
private class Function4InputTestNode : Function4Input, IGeneratesFunction |
|||
{ |
|||
public Function4InputTestNode() |
|||
{ |
|||
name = "Function4InputTestNode"; |
|||
} |
|||
|
|||
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", "arg4"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return arg1 + arg2 + arg3 + arg4;", 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 Vector1Node m_InputFour; |
|||
private Function4InputTestNode 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_InputFour = new Vector1Node(); |
|||
m_TestNode = new Function4InputTestNode(); |
|||
|
|||
m_Graph.AddNode(m_InputOne); |
|||
m_Graph.AddNode(m_InputTwo); |
|||
m_Graph.AddNode(m_InputThree); |
|||
m_Graph.AddNode(m_InputFour); |
|||
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_InputFour.value = 0.6f; |
|||
|
|||
m_Graph.Connect(m_InputOne.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function4Input.InputSlot1Id)); |
|||
m_Graph.Connect(m_InputTwo.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function4Input.InputSlot2Id)); |
|||
m_Graph.Connect(m_InputThree.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function4Input.InputSlot3Id)); |
|||
m_Graph.Connect(m_InputThree.GetSlotReference(Vector1Node.OutputSlotId), m_TestNode.GetSlotReference(Function4Input.InputSlot4Id)); |
|||
m_Graph.Connect(m_TestNode.GetSlotReference(Function4Input.OutputSlotId), m_Graph.masterNode.GetSlotReference(MetallicMasterNode.NormalSlotId)); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestGenerateNodeCodeGeneratesCorrectCode() |
|||
{ |
|||
string expected = string.Format("half {0} = unity_test_half ({1}, {2}, {3}, {4});{5}" |
|||
, m_TestNode.GetVariableNameForSlot(Function4Input.OutputSlotId) |
|||
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId) |
|||
, m_InputTwo.GetVariableNameForSlot(Vector1Node.OutputSlotId) |
|||
, m_InputThree.GetVariableNameForSlot(Vector1Node.OutputSlotId) |
|||
, m_InputFour.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, half arg4)" + Environment.NewLine |
|||
+ "{" + Environment.NewLine |
|||
+ "\treturn arg1 + arg2 + arg3 + arg4;" + 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 Function1Input : AbstractMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
protected const string kInputSlotShaderName = "Input"; |
|||
protected const string kOutputSlotShaderName = "Output"; |
|||
|
|||
public const int InputSlotId = 0; |
|||
public const int OutputSlotId = 1; |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
protected Function1Input() |
|||
{ |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(GetInputSlot()); |
|||
AddSlot(GetOutputSlot()); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { InputSlotId, OutputSlotId }; } |
|||
} |
|||
|
|||
protected virtual MaterialSlot GetInputSlot() |
|||
{ |
|||
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, 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 GetInputSlotName() {return "Input"; } |
|||
protected virtual string GetOutputSlotName() {return "Output"; } |
|||
|
|||
protected abstract string GetFunctionName(); |
|||
|
|||
protected virtual string GetFunctionPrototype(string argName) |
|||
{ |
|||
return "inline " + precision + outputDimension + " " + GetFunctionName() + " (" |
|||
+ precision + inputDimension + " " + argName + ")"; |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] {InputSlotId}, new[] {OutputSlotId}); |
|||
var inputValue = GetSlotValue(InputSlotId, generationMode); |
|||
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(inputValue) + ";", true); |
|||
} |
|||
|
|||
protected virtual string GetFunctionCallBody(string inputValue) |
|||
{ |
|||
return GetFunctionName() + " (" + inputValue + ")"; |
|||
} |
|||
|
|||
public string outputDimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); } |
|||
} |
|||
public string inputDimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType); } |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9e8ba3e80e4d9e947a9377e9e73fdca9 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public abstract class Function4Input : AbstractMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
protected const string kInputSlot1ShaderName = "Input1"; |
|||
protected const string kInputSlot2ShaderName = "Input2"; |
|||
protected const string kInputSlot3ShaderName = "Input3"; |
|||
protected const string kInputSlot4ShaderName = "Input4"; |
|||
protected const string kOutputSlotShaderName = "Output"; |
|||
|
|||
public const int InputSlot1Id = 0; |
|||
public const int InputSlot2Id = 1; |
|||
public const int InputSlot3Id = 2; |
|||
public const int InputSlot4Id = 3; |
|||
public const int OutputSlotId = 4; |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
protected Function4Input() |
|||
{ |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(GetInputSlot1()); |
|||
AddSlot(GetInputSlot2()); |
|||
AddSlot(GetInputSlot3()); |
|||
AddSlot(GetInputSlot4()); |
|||
AddSlot(GetOutputSlot()); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { InputSlot1Id, InputSlot2Id, InputSlot3Id, InputSlot4Id, 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 GetInputSlot4() |
|||
{ |
|||
return new MaterialSlot(InputSlot4Id, GetInputSlot4Name(), kInputSlot4ShaderName, 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 GetInputSlot4Name() |
|||
{ |
|||
return "Input4"; |
|||
} |
|||
|
|||
protected virtual string GetOutputSlotName() |
|||
{ |
|||
return "Output"; |
|||
} |
|||
|
|||
protected abstract string GetFunctionName(); |
|||
|
|||
protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name, string arg4Name) |
|||
{ |
|||
return "inline " + precision + outputDimension + " " + GetFunctionName() + " (" |
|||
+ precision + input1Dimension + " " + arg1Name + ", " |
|||
+ precision + input2Dimension + " " + arg2Name + ", " |
|||
+ precision + input3Dimension + " " + arg3Name + ", " |
|||
+ precision + input4Dimension + " " + arg4Name + ")"; |
|||
} |
|||
|
|||
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); |
|||
string input4Value = GetSlotValue(InputSlot4Id, generationMode); |
|||
|
|||
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value, input3Value, input4Value) + ";", true); |
|||
} |
|||
|
|||
protected virtual string GetFunctionCallBody(string inputValue1, string inputValue2, string inputValue3, string inputValue4) |
|||
{ |
|||
return GetFunctionName() + " (" + inputValue1 + ", " + inputValue2 + ", " + inputValue3 + ", " + inputValue4 + ")"; |
|||
} |
|||
|
|||
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); } |
|||
} |
|||
|
|||
public string input4Dimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot4Id).concreteValueType); } |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a4d44a805d21cc34d81319e66c9c70a4 |
|||
timeCreated: 1495481765 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: eb0cb153896a18c4ebb6d116283dfda4 |
|||
folderAsset: yes |
|||
timeCreated: 1495532221 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0255be381ce130c4ea649efcaaa61c0a |
|||
folderAsset: yes |
|||
timeCreated: 1495751822 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue