浏览代码

Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017

/main
bfogerty 8 年前
当前提交
30bac3ab
共有 26 个文件被更改,包括 1712 次插入121 次删除
  1. 181
      MaterialGraphProject/Assets/Matt&Andre/RemapNode.cs
  2. 8
      MaterialGraphProject/Assets/Rinaldo/BlendModeNode.cs
  3. 2
      MaterialGraphProject/Assets/Rinaldo/BlendModesEnum.cs
  4. 2
      MaterialGraphProject/Assets/TestAssets/Sky1.jpg.meta
  5. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs
  6. 12
      MaterialGraphProject/Assets/Andre/CubemapNode.cs
  7. 9
      MaterialGraphProject/Assets/Andre.meta
  8. 43
      MaterialGraphProject/Assets/Matt/LinearToRGB.cs
  9. 12
      MaterialGraphProject/Assets/Matt/LinearToRGB.cs.meta
  10. 43
      MaterialGraphProject/Assets/Matt/RGBtoLinear.cs
  11. 12
      MaterialGraphProject/Assets/Matt/RGBtoLinear.cs.meta
  12. 110
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function4InputTests.cs
  13. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function4InputTests.cs.meta
  14. 145
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function4Input.cs
  15. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function4Input.cs.meta
  16. 12
      MaterialGraphProject/Assets/Andre/CubemapNode.cs.meta
  17. 1
      MaterialGraphProject/Assets/Andre/New Shader Graph.ShaderGraph
  18. 9
      MaterialGraphProject/Assets/Andre/New Shader Graph.ShaderGraph.meta
  19. 25
      MaterialGraphProject/obj/Debug/Assembly-CSharp.csproj.FilesWrittenAbsolute.txt
  20. 1001
      MaterialGraphProject/obj/Debug/Assembly-CSharp.dll
  21. 171
      MaterialGraphProject/obj/Debug/Assembly-CSharp.dll.mdb
  22. 8
      MaterialGraphProject/Assets/Matt&Andre/CubemapNode.cs.meta
  23. 0
      /MaterialGraphProject/Assets/Andre/CubemapNode.cs

181
MaterialGraphProject/Assets/Matt&Andre/RemapNode.cs


namespace UnityEngine.MaterialGraph
{
[Title ("Math/Range/Remap")]
public class RemapNode : Function2Input, IGeneratesFunction
public class RemapNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction
/*protected const string kInputSlot1ShaderName = "Input1";
protected const string kInputSlot2ShaderName = "Input2";
protected const string kInputSlot1ShaderName = "Input1";
protected const string kInputSlot2ShaderName = "InMin";
protected const string kInputSlot3ShaderName = "InMax";
public const int OutputSlotId = 2;
public const int InputSlot3Id = 2;
public const int OutputSlotId = 3;
*/
public override bool hasPreview
{
get { return true; }
}
name = "RemapNode";
name = "Remap";
protected override string GetFunctionName ()
public string GetFunctionName ()
//need to override the type of slot two somehow///////////////////////////////////////////////////
/*override MaterialSlot GetInputSlot2 ()
public sealed override void UpdateNodeAfterDeserialization()
return new MaterialSlot (InputSlot2Id, GetInputSlot2Name (), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Vector4, Vector4.zero);
}*/
AddSlot(GetInputSlot1());
AddSlot(GetInputSlot2());
AddSlot(GetInputSlot3());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode)
protected int[] validSlots
var outputString = new ShaderGenerator ();
outputString.AddShaderChunk (GetFunctionPrototype ("arg1", "arg2"), false);
outputString.AddShaderChunk ("{", false);
outputString.Indent ();
outputString.AddShaderChunk ("return ((arg1 * (arg2.y - arg2.x)) * (arg2.w - arg2.z))+arg2.z;", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
get { return new[] {InputSlot1Id, InputSlot2Id, InputSlot3Id, OutputSlotId}; }
/*
public sealed override void UpdateNodeAfterDeserialization ()
protected virtual MaterialSlot GetInputSlot1()
AddSlot (GetInputSlot1 ());
AddSlot (GetInputSlot2 ());
AddSlot (GetOutputSlot ());
RemoveSlotsNameNotMatching (validSlots);
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
protected int[] validSlots {
get { return new[] { InputSlot1Id, InputSlot2Id, OutputSlotId }; }
protected virtual MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Vector2, Vector2.zero);
protected virtual MaterialSlot GetInputSlot1 ()
protected virtual MaterialSlot GetInputSlot3()
return new MaterialSlot (InputSlot1Id, GetInputSlot1Name (), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, SlotType.Input, SlotValueType.Vector2, Vector2.zero);
protected virtual MaterialSlot GetInputSlot2 ()
protected virtual MaterialSlot GetOutputSlot()
return new MaterialSlot (InputSlot2Id, GetInputSlot2Name (), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Vector4, Vector4.zero);
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
protected virtual MaterialSlot GetOutputSlot ()
protected virtual string GetInputSlot1Name()
return new MaterialSlot (OutputSlotId, GetOutputSlotName (), kOutputSlotShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
return "Input";
protected virtual string GetInputSlot1Name ()
protected virtual string GetInputSlot2Name()
return "Input1";
return "InMin/Max";
protected virtual string GetInputSlot2Name ()
protected virtual string GetInputSlot3Name()
return "RemapVector";
return "OutMin/Max";
protected virtual string GetOutputSlotName ()
protected virtual string GetOutputSlotName()
//protected abstract string GetFunctionName ();
/*protected virtual string GetFunctionPrototype (string arg1Name, string arg2Name)
protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name)
return "inline " + precision + outputDimension + " " + GetFunctionName () + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ")";
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ", "
+ precision + input3Dimension + " " + arg3Name + ")";
public void GenerateNodeCode (ShaderGenerator visitor, GenerationMode generationMode)
public 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);
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 input1Value, string input2Value)
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
return GetFunctionName () + " (" + input1Value + ", " + input2Value + ")";
}*/
var outputString = new ShaderGenerator ();
outputString.AddShaderChunk (GetFunctionPrototype ("arg1", "arg2", "arg3"), false);
outputString.AddShaderChunk ("{", false);
outputString.Indent ();
outputString.AddShaderChunk ("return arg1 * ((arg3.y - arg3.x) / (arg2.y - arg2.x)) + arg3.x;", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
/*public string outputDimension {
get { return ConvertConcreteSlotValueTypeToString (FindOutputSlot<MaterialSlot> (OutputSlotId).concreteValueType); }
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
private string input1Dimension {
get { return ConvertConcreteSlotValueTypeToString (FindInputSlot<MaterialSlot> (InputSlot1Id).concreteValueType); }
}
private string input2Dimension {
get { return ConvertConcreteSlotValueTypeToString (FindInputSlot<MaterialSlot> (InputSlot2Id).concreteValueType); }
}*/
/// <summary>
/// Gets the type of the property.*/
/// </summary>
/// <value>The type of the property.</value>
/*public override PropertyType propertyType {
get { return PropertyType.Vector4; }
}
public Vector4 value {
get { return m_Value; }
set {
if (m_Value == value)
return;
m_Value = value;
if (onModified != null)
onModified (this, ModificationScope.Node);
}
}*/
/*public override void GeneratePropertyBlock (PropertyGenerator visitor, GenerationMode generationMode)
protected virtual string GetFunctionCallBody(string inputValue1, string inputValue2, string inputValue3)
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty (new VectorPropertyChunk (propertyName, description, m_Value, PropertyChunk.HideState.Visible));
return GetFunctionName() + " (" + inputValue1 + ", " + inputValue2 + ", " + inputValue3 + ")";
public override void GeneratePropertyUsages (ShaderGenerator visitor, GenerationMode generationMode)
public string outputDimension
if (exposedState == ExposedState.Exposed || generationMode.IsPreview ())
visitor.AddShaderChunk (precision + "3 " + propertyName + ";", false);
}*/
/*public void GenerateNodeCode (ShaderGenerator visitor, GenerationMode generationMode)
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); }
}
private string input1Dimension
if (exposedState == ExposedState.Exposed || generationMode.IsPreview ())
return;
var input1Value = GetSlotValue (InputSlot1Id, generationMode);
var input2Value = GetSlotValue (InputSlot2Id, generationMode);
visitor.AddShaderChunk (precision + "4 " + propertyName + " = " + input1Value + " * ((" + input2Value + ".w - " + input2Value + ".z) + " + input2Value + ".z);", false);
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); }
public override bool hasPreview {
get { return true; }
private string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
public override PreviewProperty GetPreviewProperty ()
public string input3Dimension
return new PreviewProperty {
m_Name = propertyName,
m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};
}*/
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot3Id).concreteValueType); }
}
}
}

8
MaterialGraphProject/Assets/Rinaldo/BlendModeNode.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
case BlendModesEnum.Substract:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg1 - arg2;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
}
visitor.AddShaderChunk(outputString.GetShaderString(0), true);

2
MaterialGraphProject/Assets/Rinaldo/BlendModesEnum.cs


// PinLight,
Screen,
SoftLight,
// Substract,
Substract,
// VividLight

2
MaterialGraphProject/Assets/TestAssets/Sky1.jpg.meta


isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
cubemapConvolution: 1
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs


case PropertyType.Texture2D:
mat.SetTexture(previewProperty.m_Name, previewProperty.m_Texture);
break;
case PropertyType.Cubemap:
mat.SetTexture(previewProperty.m_Name, previewProperty.m_Cubemap);
break;
case PropertyType.Color:
mat.SetColor(previewProperty.m_Name, previewProperty.m_Color);
break;

12
MaterialGraphProject/Assets/Andre/CubemapNode.cs


protected const string kOutputSlotGName = "G";
protected const string kOutputSlotBName = "B";
protected const string kOutputSlotAName = "A";
protected const string kInputSlotLodName = "MipLevel";
public const int InputSlotLod = 6;
public const int OutputSlotRgbaId = 1;
public const int OutputSlotRId = 2;
public const int OutputSlotGId = 3;

AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector3, Vector3.zero, false));
AddSlot (new MaterialSlot(InputSlotLod, kInputSlotLodName, kInputSlotLodName, SlotType.Input, SlotValueType.Vector1, Vector2.zero));
RemoveSlotsNameNotMatching(validSlots);
}

protected int[] validSlots
{
get { return new[] {OutputSlotRgbaId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, UvSlotId}; }
get { return new[] {OutputSlotRgbaId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, UvSlotId, InputSlotLod}; }
}
// Node generations

if (uvSlot == null)
return;
var lodID = FindInputSlot<MaterialSlot>(InputSlotLod);
if (lodID == null)
return;
//var lodValue = string.Format ("{0}", )
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
if (edges.Count > 0)

uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector3, true);
}
string body = "texCUBE (" + propertyName + ", " + uvName + ")";
string body = "texCUBElod (" + propertyName + ", " + precision + "4(" + uvName + "," + lodID.currentValue.x + "))";
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true);
}

9
MaterialGraphProject/Assets/Andre.meta


fileFormatVersion: 2
guid: cd5688ca09d4248698f2b43253441000
folderAsset: yes
timeCreated: 1495479128
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

43
MaterialGraphProject/Assets/Matt/LinearToRGB.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title ("Math/Color/LineartoRGB")]
public class LineartoRGBNode : Function1Input, IGeneratesFunction
{
public LineartoRGBNode()
{
name = "RGBtoLinear";
}
protected override string GetFunctionName ()
{
return "unity_lineartorgb_" + 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);
}
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 sRGBLo = arg1 * 12.92;", false);
outputString.AddShaderChunk (precision + "3 sRGBHi = (pow(max(abs(arg1), 1.192092896e-07), "+precision+ "3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4)) * 1.055) - 0.055;", false);
outputString.AddShaderChunk ("return " + precision + "3(arg1 <= 0.0031308) ? sRGBLo : sRGBHi;", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
}
}

12
MaterialGraphProject/Assets/Matt/LinearToRGB.cs.meta


fileFormatVersion: 2
guid: 667e5671fc459344c889207ff866ab08
timeCreated: 1444218016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

43
MaterialGraphProject/Assets/Matt/RGBtoLinear.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title ("Math/Color/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);
}
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);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
}
}

12
MaterialGraphProject/Assets/Matt/RGBtoLinear.cs.meta


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

110
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function4InputTests.cs


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(Function3Input.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));
}
}
}

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


fileFormatVersion: 2
guid: 6fc8f3d4460595e44bb2fb21831294a8
timeCreated: 1495484604
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

145
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function4Input.cs


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); }
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function4Input.cs.meta


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

12
MaterialGraphProject/Assets/Andre/CubemapNode.cs.meta


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

1
MaterialGraphProject/Assets/Andre/New Shader Graph.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/Andre/New Shader Graph.ShaderGraph.meta


fileFormatVersion: 2
guid: 8c255d11f15384beb834142327f24126
timeCreated: 1495482510
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

25
MaterialGraphProject/obj/Debug/Assembly-CSharp.csproj.FilesWrittenAbsolute.txt


/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Assembly-CSharp.dll.mdb
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Assembly-CSharp.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/obj/Debug/Assembly-CSharp.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/obj/Debug/Assembly-CSharp.dll.mdb
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/UnityEngine.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/UnityEditor.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/UnityEngine.UI.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/UnityEngine.Networking.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/UnityEngine.PerformanceTesting.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/UnityEngine.TestRunner.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/nunit.framework.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/UnityEngine.Timeline.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/UnityEngine.UIAutomation.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/UnityEngine.Analytics.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/UnityEngine.HoloLens.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Mono.Cecil.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Unity.SerializationLogic.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Unity.DataContract.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/ExCSS.Unity.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Unity.Legacy.NRefactory.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Unity.UNetWeaver.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Unity.UNetWeaver.dll.mdb
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Unity.CecilTools.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Mono.Cecil.Pdb.dll
/Users/andremcgrail/Documents/UnityProjects/External Projects/MaterialGraph/MaterialGraphProject/Temp/bin/Debug/Mono.Cecil.Mdb.dll

1001
MaterialGraphProject/obj/Debug/Assembly-CSharp.dll
文件差异内容过多而无法显示
查看文件

171
MaterialGraphProject/obj/Debug/Assembly-CSharp.dll.mdb
文件差异内容过多而无法显示
查看文件

8
MaterialGraphProject/Assets/Matt&Andre/CubemapNode.cs.meta


fileFormatVersion: 2
guid: c184bca342bb146daa708a7ecda424fc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

/MaterialGraphProject/Assets/Matt&Andre/CubemapNode.cs → /MaterialGraphProject/Assets/Andre/CubemapNode.cs

正在加载...
取消
保存