浏览代码

Remove function 1 input and function 4 input

/main
Tim Cooper 8 年前
当前提交
8df91eb4
共有 62 个文件被更改,包括 962 次插入1291 次删除
  1. 22
      MaterialGraphProject/Assets/Eduardo/ReciprocalSqrtNode.cs
  2. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
  3. 1
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/SerializationHelper.cs
  4. 70
      MaterialGraphProject/Assets/Matt/TangentToWorldNode.cs
  5. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/LevelsNodePresenter.cs
  6. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  7. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SwizzleNodePresenter.cs
  8. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PixelShaderNodeTests.cs
  9. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/ContrastNode.cs
  10. 44
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/HueNode.cs
  11. 158
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/LevelsNode.cs
  12. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/HSVtoRGBNode.cs
  13. 50
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/LinearToRGBNode.cs
  14. 59
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoHSVNode.cs
  15. 64
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoLinearNode.cs
  16. 60
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoLuminanceNode.cs
  17. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SwizzleNode.cs
  18. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/HLSLNode.cs
  19. 156
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic/IFNode.cs
  20. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/AbsoluteNode.cs
  21. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/LengthNode.cs
  22. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/LogNode.cs
  23. 29
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/NegateNode.cs
  24. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/NormalizeNode.cs
  25. 29
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/ReciprocalNode.cs
  26. 40
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Basic/ExponentialNode.cs
  27. 40
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Basic/SquareRootNode.cs
  28. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs
  29. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/FractionNode.cs
  30. 49
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/OneMinus.cs
  31. 26
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/SaturateNode.cs
  32. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/CeilNode.cs
  33. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/FloorNode.cs
  34. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/RoundNode.cs
  35. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/SignNode.cs
  36. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/TruncNode.cs
  37. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/ArcCosNode.cs
  38. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/ArcSinNode.cs
  39. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/ArcTanNode.cs
  40. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/CosNode.cs
  41. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/DegreesToRadiansNode.cs
  42. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/RadiansToDegreesNode.cs
  43. 26
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/SinCosNode.cs
  44. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/SinNode.cs
  45. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/TanNode.cs
  46. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/DDX.cs
  47. 29
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/DDXY.cs
  48. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/DDY.cs
  49. 27
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Normal/UnpackNormalNode.cs
  50. 135
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/NoiseNode.cs
  51. 48
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/CartesianToPolarNode.cs
  52. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/SpherizeNode.cs
  53. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs.meta
  54. 93
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs
  55. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function4InputTests.cs.meta
  56. 110
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function4InputTests.cs
  57. 77
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function1Input.cs
  58. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function1Input.cs.meta
  59. 145
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function4Input.cs
  60. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function4Input.cs.meta
  61. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Legacy.meta
  62. 9
      MaterialGraphProject/Assets/_MingWai/GeneratedTextureDemo/StandardShader.meta

22
MaterialGraphProject/Assets/Eduardo/ReciprocalSqrtNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class ReciprocalSqrtNode : Function1Input
public class ReciprocalSqrtNode : CodeFunctionNode
{
public ReciprocalSqrtNode()
{

public override bool hasPreview
protected override MethodInfo GetFunctionToConvert()
get { return false; }
return GetType().GetMethod("Unity_Rsqrt", BindingFlags.Static | BindingFlags.NonPublic);
protected override string GetFunctionName() { return "rsqrt"; }
static string Unity_Rsqrt(
[Slot(0, Binding.None)] DynamicDimensionVector first,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = rsqrt(argument);
}
";
}
}
}

4
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs


public virtual void OnAfterDeserialize()
{
m_Nodes = SerializationHelper.Deserialize<INode>(m_SerializableNodes, GetLegacyTypeRemapping());
foreach (var node in m_Nodes)
foreach (var node in m_Nodes)
{
node.owner = this;
node.UpdateNodeAfterDeserialization ();

m_Edges = SerializationHelper.Deserialize<IEdge>(m_SerializableEdges, null);
m_SerializableEdges = null;
ValidateGraph();
}

1
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/SerializationHelper.cs


catch (Exception e)
{
Debug.LogException(e);
Debug.LogError(element.JSONnodeData);
}
}
return result;

70
MaterialGraphProject/Assets/Matt/TangentToWorldNode.cs


using UnityEngine.Graphing;
using System.Reflection;
public class TangentToWorldNode : Function1Input, IGeneratesFunction, IMayRequireNormal, IMayRequireTangent, IMayRequireBitangent
public class TangentToWorldNode : CodeFunctionNode
{
public TangentToWorldNode()
{

protected override string GetFunctionName()
{
return "unity_tangenttoworld_" + 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);
}
protected override string GetFunctionPrototype(string argName)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + inputDimension + " " + argName + ", float3 tangent, float3 bitangent, float3 normal )";
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
//outputString.AddShaderChunk("float3x3 tangentToWorld = transpose(float3x3(" + ShaderGeneratorNames.WorldSpaceTangent + ", " + ShaderGeneratorNames.WorldSpaceBitangent + ", " + ShaderGeneratorNames.WorldSpaceNormal + "));", false);
outputString.AddShaderChunk("float3x3 tangentToWorld = transpose(float3x3(tangent, bitangent, normal));", false);
outputString.AddShaderChunk("return saturate(mul(tangentToWorld, normalize(arg1)));", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
protected override string GetFunctionCallBody(string inputValue)
protected override MethodInfo GetFunctionToConvert()
return GetFunctionName() + " (" + inputValue + ", "+ShaderGeneratorNames.WorldSpaceTangent + ", " + ShaderGeneratorNames.WorldSpaceBitangent + ", " + ShaderGeneratorNames.WorldSpaceNormal +")";
return GetType().GetMethod("Unity_TangentToWorld", BindingFlags.Static | BindingFlags.NonPublic);
public bool RequiresNormal()
static string Unity_TangentToWorld(
[Slot(0, Binding.None)] Vector3 inVector,
[Slot(1, Binding.None)] out Vector3 result,
[Slot(2, Binding.Tangent)] Vector3 tangent,
[Slot(3, Binding.Bitangent)] Vector3 biTangent,
[Slot(4, Binding.Normal)] Vector3 normal)
return true;
}
public bool RequiresTangent()
{
return true;
}
public bool RequiresBitangent()
{
return true;
result = Vector3.zero;
return
@"
{
{precision}3x3 tangentToWorld = transpose({precision}3x3(tangent, biTangent, normal));
result= saturate(mul(tangentToWorld, normalize(inVector)));
}
";
}
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/LevelsNodePresenter.cs


if (tNode == null)
return;
tNode.inputMin = EditorGUILayout.FloatField("InputMin:", tNode.inputMin);
/*tNode.inputMin = EditorGUILayout.FloatField("InputMin:", tNode.inputMin);
tNode.outputMax = EditorGUILayout.FloatField("OutputMax:", tNode.outputMax);
tNode.outputMax = EditorGUILayout.FloatField("OutputMax:", tNode.outputMax);*/
}
public override float GetHeight()

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


typeMapper[typeof(AbstractSurfaceMasterNode)] = typeof(SurfaceMasterPresenter);
typeMapper[typeof(LevelsNode)] = typeof(LevelsNodePresenter);
typeMapper[typeof(ConstantsNode)] = typeof(ConstantsNodePresenter);
typeMapper[typeof(SwizzleNode)] = typeof(SwizzleNodePresenter);
//typeMapper[typeof(SwizzleNode)] = typeof(SwizzleNodePresenter);
typeMapper[typeof(BlendModeNode)] = typeof(BlendModeNodePresenter);
typeMapper[typeof(AddManyNode)] = typeof(AddManyNodePresenter);
typeMapper[typeof(IfNode)] = typeof(IfNodePresenter);

.Where(nap => nap.IsConnectable() &&
nap.orientation == startAnchor.orientation &&
nap.direction != startAnchor.direction &&
nodeAdapter.GetAdapter(nap.source, startAnchor.source) != null &&
(startAnchor is GraphAnchorPresenter && ((GraphAnchorPresenter)nap).slot is MaterialSlot &&
nodeAdapter.GetAdapter(nap.source, startAnchor.source) != null &&
(startAnchor is GraphAnchorPresenter && ((GraphAnchorPresenter)nap).slot is MaterialSlot &&
((MaterialSlot)((GraphAnchorPresenter)startAnchor).slot).IsCompatibleWithInputSlotType(((MaterialSlot)((GraphAnchorPresenter)nap).slot).valueType)))
.ToList();
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SwizzleNodePresenter.cs


{
base.OnGUIHandler();
var tNode = node as SwizzleNode;
/*var tNode = node as SwizzleNode;
if (tNode == null)
return;

if (EditorGUI.EndChangeCheck())
{
tNode.swizzleChannels = newSwizzleChannels;
}
}*/
}
public override float GetHeight()

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PixelShaderNodeTests.cs


m_Graph.Connect(m_InputOne.GetSlotReference(Vector1Node.OutputSlotId), m_PixelNode.GetSlotReference(AbstractSurfaceMasterNode.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(AbstractSurfaceMasterNode.AlbedoSlotId));
// m_Graph.Connect(m_InputOne.GetSlotReference(Vector1Node.OutputSlotId), m_Abs.GetSlotReference(Function1Input.InputSlotId));
//m_Graph.Connect(m_Abs.GetSlotReference(Function1Input.OutputSlotId), m_PixelNode.GetSlotReference(AbstractSurfaceMasterNode.AlbedoSlotId));
[Test]
/* [Test]
public void TestNodeGeneratesCorrectNodeCode()
{
string expected = string.Format("half {0} = 0.2;" + Environment.NewLine

Assert.AreEqual(expected, generator.GetShaderString(0));
Assert.AreEqual(string.Empty, generator.GetPragmaString());
}
}*/
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/ContrastNode.cs


// Contrast (reacts better when applied in log)
// Optimal range: [0.0, 2.0]]
// From PostProcessing
result = (input - midpoint) * contrast + midPoint;
result = (input - midPoint) * contrast + midPoint;
}";
}
}

44
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/HueNode.cs


using UnityEngine.Graphing;
using System.Reflection;
public class HueNode : Function1Input, IGeneratesFunction
public class HueNode : CodeFunctionNode
{
public HueNode()
{

protected override string GetFunctionName()
{
return "unity_hue_" + precision;
}
protected override MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector1, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot()
protected override MethodInfo GetFunctionToConvert()
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero);
return GetType().GetMethod("Unity_Hue", BindingFlags.Static | BindingFlags.NonPublic);
//TODO:Externalize
//Reference code from:https://github.com/Unity-Technologies/PostProcessing/blob/master/PostProcessing/Resources/Shaders/ColorGrading.cginc#L175
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
static string Unity_Hue(
[Slot(0, Binding.None)] Vector1 argument,
[Slot(1, Binding.None)] out Vector3 result)
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(precision + "4 K = " + precision + "4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);", false);
outputString.AddShaderChunk(precision + "3 P = abs(frac(arg1.xxx + K.xyz) * 6.0 - K.www);", false);
outputString.AddShaderChunk("return 1 * lerp(K.xxx, saturate(P - K.xxx), 1);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
result = Vector3.zero;
return
@"
{
{precision}4 K = {precision}4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
{precision}3 P = abs(frac(argument.xxx + K.xyz) * 6.0 - K.www);
result = 1 * lerp(K.xxx, saturate(P - K.xxx), 1);
}
";
}
}
}

158
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/LevelsNode.cs


using UnityEngine.Graphing;
using System.Collections.Generic;
using System.Reflection;
public class LevelsNode : Function1Input, IGeneratesFunction
public class LevelsNode : CodeFunctionNode
{
[SerializeField]
private float m_InputMin = 0.0f;

[SerializeField]
private float m_OutputMax = 1.0f;
public float inputMin
{
get { return m_InputMin; }
set
{
if (m_InputMin == value)
return;
m_InputMin = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public float inputMax
{
get { return m_InputMax; }
set
{
if (m_InputMax == value)
return;
m_InputMax = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public float inputGamma
{
get { return m_InputGamma; }
set
{
if (m_InputGamma == value)
return;
m_InputGamma = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public float outputMin
{
get { return m_OutputMin; }
set
{
if (m_OutputMin == value)
return;
m_OutputMin = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public float outputMax
{
get { return m_OutputMax; }
set
{
if (m_OutputMax == value)
return;
m_OutputMax = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
protected override string GetFunctionName()
{
return "unity_levels_" + precision;
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (generationMode.IsPreview())
{
var propGuid = GetVariableNameForNode();
visitor.AddShaderChunk(precision + " inputMin" + propGuid +";", true);
visitor.AddShaderChunk(precision + " inputMax" + propGuid + ";", true);
visitor.AddShaderChunk(precision + " inputInvGamma" + propGuid + ";", true);
visitor.AddShaderChunk(precision + " outputMin" + propGuid + ";", true);
visitor.AddShaderChunk(precision + " outputMax" + propGuid + ";", true);
}
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
protected override MethodInfo GetFunctionToConvert()
if (generationMode.IsPreview())
return;
float inputInvGamma = 1.0f / m_InputGamma;
var propGuid = GetVariableNameForNode();
visitor.AddShaderChunk(precision + " inputMin" + propGuid + " = " + m_InputMin + ";", true);
visitor.AddShaderChunk(precision + " inputMax" + propGuid + " = " + m_InputMax + ";", true);
visitor.AddShaderChunk(precision + " inputInvGamma" + propGuid + " = " + inputInvGamma + ";", true);
visitor.AddShaderChunk(precision + " outputMin" + propGuid + " = " + m_OutputMin + ";", true);
visitor.AddShaderChunk(precision + " outputMax" + propGuid + " = " + m_OutputMax + ";", true);
return GetType().GetMethod("Unity_Levels", BindingFlags.Static | BindingFlags.NonPublic);
protected override string GetFunctionCallBody(string inputValue)
static string Unity_Levels(
[Slot(0, Binding.None)] DynamicDimensionVector input,
[Slot(1, Binding.None)] Vector1 inputMin,
[Slot(2, Binding.None, 1, 1, 1, 1)] Vector1 inputMax,
[Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 inputInvGamma,
[Slot(4, Binding.None)] Vector1 outputMin,
[Slot(5, Binding.None, 1, 1, 1, 1)] Vector1 outputMax,
[Slot(6, Binding.None)] out DynamicDimensionVector result)
string propGuid = GetVariableNameForNode();
return GetFunctionName() + "(" + inputValue +
", inputMin" + propGuid +
", inputMax" + propGuid +
", inputInvGamma" + propGuid +
", outputMin" + propGuid +
", outputMax" + propGuid +
");";
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk("inline " + precision + outputDimension + " unity_level_" + precision + " (" + precision + outputDimension + " arg1, "
+ precision + " inputMin, "
+ precision + " inputMax, "
+ precision + " inputInvGamma, "
+ precision + " outputMin, "
+ precision + " outputMax)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(precision + inputDimension + " colorMinClamped = max(arg1 - inputMin, 0.0);", false);
outputString.AddShaderChunk(precision + inputDimension + " colorMinMaxClamped = min(colorMinClamped / (inputMax - inputMin), 1.0);", false);
outputString.AddShaderChunk("return lerp(outputMin, outputMax, pow(colorMinMaxClamped, inputInvGamma));", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
var propGuid = GetVariableNameForNode();
base.CollectPreviewMaterialProperties(properties);
float inputInvGamma = 1.0f / m_InputGamma;
properties.Add(new PreviewProperty { m_Name = "inputMin" + propGuid, m_PropType = PropertyType.Float, m_Float = m_InputMin } );
properties.Add(new PreviewProperty { m_Name = "inputMax" + propGuid, m_PropType = PropertyType.Float, m_Float = m_InputMax } );
properties.Add(new PreviewProperty { m_Name = "inputInvGamma" + propGuid, m_PropType = PropertyType.Float, m_Float = inputInvGamma });
properties.Add(new PreviewProperty { m_Name = "outputMin" + propGuid, m_PropType = PropertyType.Float, m_Float = m_OutputMin });
properties.Add(new PreviewProperty { m_Name = "outputMax" + propGuid, m_PropType = PropertyType.Float, m_Float = m_OutputMax });
return
@"
{
{precision}{slot6dimension} colorMinClamped = max(arg1 - inputMin, 0.0);
{precision}{slot6dimension} colorMinMaxClamped = min(colorMinClamped / (inputMax - inputMin), 1.0);
return lerp(outputMin, outputMax, pow(colorMinMaxClamped, inputInvGamma));
}
";
}
}
}

52
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/HSVtoRGBNode.cs


using System.Reflection;
public class HSVtoRGBNode : Function1Input, IGeneratesFunction
public class HSVtoRGBNode : CodeFunctionNode
{
public HSVtoRGBNode ()
{

protected override string GetFunctionName ()
{
return "unity_hsvtorgb_" + 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);
}
//TODO:Externalize
//Reference code from:https://github.com/Unity-Technologies/PostProcessing/blob/master/PostProcessing/Resources/Shaders/ColorGrading.cginc#L175
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator ();
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false);
outputString.AddShaderChunk ("{", false);
outputString.Indent ();
outputString.AddShaderChunk (precision + "4 K = " + precision + "4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);", false);
outputString.AddShaderChunk (precision + "3 P = abs(frac(arg1.xxx + K.xyz) * 6.0 - K.www);", false);
outputString.AddShaderChunk ("return arg1.z * lerp(K.xxx, saturate(P - K.xxx), arg1.y);", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_HSVToRGB", BindingFlags.Static | BindingFlags.NonPublic);
}
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
static string Unity_HSVToRGB(
[Slot(0, Binding.None)] Vector3 hsv,
[Slot(1, Binding.None)] out Vector3 rgb)
{
rgb = Vector3.zero;
return
@"
{
//Reference code from:https://github.com/Unity-Technologies/PostProcessing/blob/master/PostProcessing/Resources/Shaders/ColorGrading.cginc#L175
{precision}4 K = {precision}4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
{precision}3 P = abs(frac(hsv.xxx + K.xyz) * 6.0 - K.www);
rgb = hsv.z * lerp(K.xxx, saturate(P - K.xxx), hsv.y);
}
";
}
}
}

50
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/LinearToRGBNode.cs


using System.Reflection;
public class LineartoRGBNode : Function1Input, IGeneratesFunction
public class LineartoRGBNode : CodeFunctionNode
{
public LineartoRGBNode()
{

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);
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_LinearToRGB", BindingFlags.Static | BindingFlags.NonPublic);
}
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
static string Unity_LinearToRGB(
[Slot(0, Binding.None)] Vector3 linearColor,
[Slot(1, Binding.None)] out Vector3 rgb)
{
rgb = Vector3.zero;
return
@"
{
//Reference code from:https://github.com/Unity-Technologies/PostProcessing/blob/master/PostProcessing/Resources/Shaders/ColorGrading.cginc#L175
{precision}3 sRGBLo = linearColor * 12.92;
{precision}3 sRGBHi = (pow(max(abs(linearColor), 1.192092896e-07), {precision}3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4)) * 1.055) - 0.055;
rgb = {precision}3(linearColor <= 0.0031308) ? sRGBLo : sRGBHi;
}
";
}
}
}

59
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoHSVNode.cs


using UnityEngine.Graphing;
using System.Reflection;
public class RGBtoHSVNode : Function1Input, IGeneratesFunction
public class RGBtoHSVNode : CodeFunctionNode
{
public RGBtoHSVNode ()
{

protected override string GetFunctionName ()
{
return "unity_rgbtohsv_" + precision;
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_RGBtoHSV", BindingFlags.Static | BindingFlags.NonPublic);
}
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);
}
//TODO:Externalize
//Reference code from:http://www.chilliant.com/rgb2hsv.html
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator ();
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false);
outputString.AddShaderChunk ("{", false);
outputString.Indent ();
outputString.AddShaderChunk (precision + "4 K = " + precision + "4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);", false);
outputString.AddShaderChunk (precision + "4 P = lerp(" + precision + "4(arg1.bg, K.wz), " + precision + "4(arg1.gb, K.xy), step(arg1.b, arg1.g));", false);
outputString.AddShaderChunk (precision + "4 Q = lerp(" + precision + "4(P.xyw, arg1.r), " + precision + "4(arg1.r, P.yzx), step(P.x, arg1.r));", false);
outputString.AddShaderChunk (precision + " D = Q.x - min(Q.w, Q.y);", false);
outputString.AddShaderChunk (precision + " E = 1e-10;", false);
outputString.AddShaderChunk ("return " + precision + "3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
static string Unity_RGBtoHSV(
[Slot(0, Binding.None)] Vector3 rgb,
[Slot(1, Binding.None)] out Vector3 hsv)
{
hsv = Vector3.zero;
return
@"
{
//Reference code from:http://www.chilliant.com/rgb2hsv.html
{precision}4 K = {precision}4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
{precision}4 P = lerp({precision}4(rgb.bg, K.wz), {precision}4(rgb.gb, K.xy), step(rgb.b, rgb.g));
{precision}4 Q = lerp({precision}4(P.xyw, rgb.r), {precision}4(rgb.r, P.yzx), step(P.x, rgb.r));
{precision} D = Q.x - min(Q.w, Q.y);
{precision} E = 1e-10;
hsv = {precision}3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);
}
";
}
}
}

64
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoLinearNode.cs


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

60
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoLuminanceNode.cs


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

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SwizzleNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Channel/Swizzle")]
/* [Title("Channel/Swizzle")]
public class SwizzleNode : Function1Input
{
public enum SwizzleChannel

}
return outputString;
}
}
}*/
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/HLSLNode.cs


{
public int slotId { get; private set; }
public Binding binding { get; private set; }
public Vector4? defaultValue { get; private set; }
defaultValue = null;
}
public SlotAttribute(int mslotId, Binding mImplicitBinding, int defaultX, int defaultY, int defaultZ, int defaultW)
{
slotId = mslotId;
binding = mImplicitBinding;
defaultValue = new Vector4(defaultX, defaultY, defaultZ, defaultW);
}
}

{
return SlotValueType.Dynamic;
}
if (t == typeof(Matrix4x4))
{
return SlotValueType.Matrix4;
}
throw new ArgumentException("Unsupported type " + t);
}

List<MaterialSlot> slots = new List<MaterialSlot>();
foreach (var par in method.GetParameters())
{
var slotid = GetSlotAttribute(par);
var attribute = GetSlotAttribute(par);
slots.Add(new MaterialSlot(slotid.slotId, par.Name, par.Name, par.IsOut ? SlotType.Output : SlotType.Input,
ConvertTypeToSlotValueType(par), Vector4.zero));
slots.Add(new MaterialSlot(attribute.slotId, par.Name, par.Name, par.IsOut ? SlotType.Output : SlotType.Input,
ConvertTypeToSlotValueType(par), attribute.defaultValue ?? Vector4.zero));
m_Slots.Add(slotid);
m_Slots.Add(attribute);
}
foreach (var slot in slots)
{

return result;
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
public virtual void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
string function = GetFunctionHeader() + GetFunctionBody(GetFunctionToConvert());
visitor.AddShaderChunk(function, true);

156
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic/IFNode.cs


using UnityEngine.MaterialGraph;
using System;
using System.Reflection;
public class IfNode : Function4Input, IGeneratesFunction
public class IfNode : CodeFunctionNode
{
public enum ComparisonOperationType
{

GreaterThanOfEqual,
GreaterThanOrEqual,
LessThanOfEqual
LessThanOrEqual
}
[SerializeField]

name = "If";
}
protected override string GetFunctionName()
protected override MethodInfo GetFunctionToConvert()
return "unity_if_" + precision;
}
protected override string GetInputSlot1Name()
{
return "A";
}
protected override string GetInputSlot2Name()
{
return "B";
}
switch (ComparisonOperation)
{
case ComparisonOperationType.Equal:
return GetType().GetMethod("Unity_IfEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.NotEqual:
return GetType().GetMethod("Unity_IfNotEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.GreaterThan:
return GetType().GetMethod("Unity_IfGreaterThan", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.GreaterThanOrEqual:
return GetType().GetMethod("Unity_IfGreaterThanOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.LessThan:
return GetType().GetMethod("Unity_IfLessThan", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.LessThanOrEqual:
return GetType().GetMethod("Unity_IfLessThanOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
default:
throw new ArgumentOutOfRangeException();
}
protected override string GetInputSlot3Name()
{
return "True Value";
protected override string GetInputSlot4Name()
const string functionTemplate = @"
{
if({comparitor})
{
result = trueValue;
}
else
{
result = falseValue;
}
}
";
static string Unity_IfEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result )
return "False Value";
return functionTemplate.Replace("{comparitor}", "a == b");
protected override MaterialSlot GetInputSlot1()
static string Unity_IfNotEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result )
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
return functionTemplate.Replace("{comparitor}", "a != b");
protected override MaterialSlot GetInputSlot2()
static string Unity_IfGreaterThan(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result )
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
return functionTemplate.Replace("{comparitor}", "a > b");
protected override MaterialSlot GetInputSlot3()
static string Unity_IfGreaterThanOrEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result )
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
return functionTemplate.Replace("{comparitor}", "a >= b");
protected override MaterialSlot GetOutputSlot()
static string Unity_IfLessThan(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result )
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
return functionTemplate.Replace("{comparitor}", "a < b");
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
static string Unity_IfLessThanOrEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result )
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("a", "b", "trueOutputValue", "falseOutputValue"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
if (m_comparisonOperation == ComparisonOperationType.Equal)
{
outputString.AddShaderChunk("if (a == b)", false);
}
else if (m_comparisonOperation == ComparisonOperationType.NotEqual)
{
outputString.AddShaderChunk("if (a != b)", false);
}
else if (m_comparisonOperation == ComparisonOperationType.GreaterThan)
{
outputString.AddShaderChunk("if (a > b)", false);
}
else if (m_comparisonOperation == ComparisonOperationType.GreaterThanOfEqual)
{
outputString.AddShaderChunk("if (a >= b)", false);
}
else if (m_comparisonOperation == ComparisonOperationType.LessThan)
{
outputString.AddShaderChunk("if (a < b)", false);
}
else if (m_comparisonOperation == ComparisonOperationType.LessThanOfEqual)
{
outputString.AddShaderChunk("if (a <= b)", false);
}
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return trueOutputValue;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("else", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return falseOutputValue;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
return functionTemplate.Replace("{comparitor}", "a <= b");
}
}
}

21
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/AbsoluteNode.cs


using System.Reflection;
public class AbsoluteNode : Function1Input
public class AbsoluteNode : CodeFunctionNode
{
public AbsoluteNode()
{

protected override string GetFunctionName() {return "abs"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Absolute", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Absolute(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = abs(argument);
}
";
}
}
}

21
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/LengthNode.cs


using System.Reflection;
public class LengthNode : Function1Input
public class LengthNode : CodeFunctionNode
{
public LengthNode()
{

protected override string GetFunctionName() { return "length"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Length", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Length(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = length(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/LogNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class LogNode : Function1Input
public class LogNode : CodeFunctionNode
{
public LogNode()
{

protected override string GetFunctionName() { return "log"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Log", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Log(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = log(argument);
}
";
}
}
}

29
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/NegateNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class NegateNode : Function1Input, IGeneratesFunction
public class NegateNode : CodeFunctionNode
{
public NegateNode()
{

protected override string GetFunctionName()
protected override MethodInfo GetFunctionToConvert()
return "unity_negate_" + precision;
return GetType().GetMethod("Unity_Negate", BindingFlags.Static | BindingFlags.NonPublic);
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
static string Unity_Negate(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return -1 * arg1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
return
@"
{
result = -1 * argument;
}
";
}
}
}

21
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/NormalizeNode.cs


using System.Reflection;
class NormalizeNode : Function1Input
class NormalizeNode : CodeFunctionNode
{
public NormalizeNode()
{

protected override string GetFunctionName() { return "normalize"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Normalize", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Normalize(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = normalize(argument);
}
";
}
}
}

29
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/ReciprocalNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class ReciprocalNode : Function1Input, IGeneratesFunction
public class ReciprocalNode : CodeFunctionNode
{
public ReciprocalNode()
{

protected override string GetFunctionName()
protected override MethodInfo GetFunctionToConvert()
return "unity_reciprocal_" + precision;
return GetType().GetMethod("Unity_Reciprocal", BindingFlags.Static | BindingFlags.NonPublic);
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
static string Unity_Reciprocal(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return 1.0/arg1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
return
@"
{
result = 1.0/argument;
}
";
}
}
}

40
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Basic/ExponentialNode.cs


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

40
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Basic/SquareRootNode.cs


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

43
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs


using UnityEngine.Graphing;
using System.Reflection;
public class MatrixTransposeNode : Function1Input, IGeneratesFunction
public class MatrixTransposeNode : CodeFunctionNode
{
public MatrixTransposeNode()
{

protected override string GetFunctionName()
protected override MethodInfo GetFunctionToConvert()
return "unity_matrix_transpose_" + precision;
return GetType().GetMethod("unity_MatrixTranspose_", BindingFlags.Static | BindingFlags.NonPublic);
public override bool hasPreview
static string unity_MatrixTranspose_(
[Slot(0, Binding.None)] Matrix4x4 inMatrix,
[Slot(1, Binding.None)] out Matrix4x4 outMatrix)
get { return false; }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return transpose(arg1);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
protected override MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Matrix4, Vector4.zero);
outMatrix = Matrix4x4.identity;
return
@"
{
outMatrix = transpose(inMatrix);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/FractionNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class FractionNode : Function1Input
public class FractionNode : CodeFunctionNode
{
public FractionNode()
{

protected override string GetFunctionName() { return "frac"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Frac", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Frac(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = frac(argument);
}
";
}
}
}

49
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/OneMinus.cs


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

26
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/SaturateNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
class SaturateNode : Function1Input
class SaturateNode : CodeFunctionNode
{
public SaturateNode()
{

protected override string GetFunctionName() { return "saturate"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Saturate", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Saturate(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = saturate(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/CeilNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class CeilNode : Function1Input
public class CeilNode : CodeFunctionNode
{
public CeilNode()
{

protected override string GetFunctionName() { return "ceil"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Ceil", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Ceil(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = ceil(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/FloorNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class FloorNode : Function1Input
public class FloorNode : CodeFunctionNode
{
public FloorNode()
{

protected override string GetFunctionName() { return "floor"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Floor", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Floor(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = floor(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/RoundNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class RoundNode : Function1Input
public class RoundNode : CodeFunctionNode
{
public RoundNode()
{

protected override string GetFunctionName() { return "round"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Round", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Round(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = round(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/SignNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class SignNode : Function1Input
public class SignNode : CodeFunctionNode
{
public SignNode()
{

protected override string GetFunctionName() { return "sign"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Sign", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Sign(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = sign(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Round/TruncNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class TruncateNode : Function1Input
public class TruncateNode : CodeFunctionNode
{
public TruncateNode()
{

protected override string GetFunctionName() { return "truncate"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Truncate", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Truncate(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = truncate(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/ArcCosNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class ACosNode : Function1Input
public class ACosNode : CodeFunctionNode
{
public ACosNode()
{

protected override string GetFunctionName() { return "acos"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_ACos", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_ACos(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = acos(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/ArcSinNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class ASinNode : Function1Input
public class ASinNode : CodeFunctionNode
{
public ASinNode()
{

protected override string GetFunctionName() { return "asin"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_ASin", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_ASin(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = asin(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/ArcTanNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class ATanNode : Function1Input
public class ATanNode : CodeFunctionNode
{
public ATanNode()
{

protected override string GetFunctionName() { return "atan"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_ATan", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_ATan(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = atan(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/CosNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class CosNode : Function1Input
public class CosNode : CodeFunctionNode
{
public CosNode()
{

protected override string GetFunctionName() { return "cos"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Cos", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Cos(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = cos(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/DegreesToRadiansNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class DegreesToRadiansNode : Function1Input
public class DegreesToRadiansNode : CodeFunctionNode
{
public DegreesToRadiansNode()
{

protected override string GetFunctionName() { return "radians"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_DegreesToRadians", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_DegreesToRadians(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = radians(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/RadiansToDegreesNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class RadiansToDegreesNode : Function1Input
public class RadiansToDegreesNode : CodeFunctionNode
{
public RadiansToDegreesNode()
{

protected override string GetFunctionName() { return "degrees"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_RadiansToDegrees", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_RadiansToDegrees(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = degrees(argument);
}
";
}
}
}

26
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/SinCosNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
[Title("Math/Trigonometry/SinCos")]
public class SinCosNode : Function1Input
[Title("Math/Trigonometry/SinCos")]
public class SinCosNode : CodeFunctionNode
{
public SinCosNode()
{

protected override string GetFunctionName() { return "cos"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_SinCos", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_SinCos(
[Slot(0, Binding.None)] Vector1 argument,
[Slot(1, Binding.None)] out Vector1 sin,
[Slot(2, Binding.None)] out Vector1 cos)
{
return
@"
{
sincos(argument, sin, cos);
}
";
}
}
}

21
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/SinNode.cs


using System.Reflection;
class SinNode : Function1Input
class SinNode : CodeFunctionNode
{
public SinNode()
{

protected override string GetFunctionName() {return "sin"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Sin", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Sin(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = sin(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/TanNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class TanNode : Function1Input
public class TanNode : CodeFunctionNode
{
public TanNode()
{

protected override string GetFunctionName() { return "tan"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Tan", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Tan(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = tan(argument);
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/DDX.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class DDXNode : Function1Input
public class DDXNode : CodeFunctionNode
{
public DDXNode()
{

protected override string GetFunctionName() { return "ddx"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_DDX", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_DDX(
[Slot(0, Binding.None)] Vector1 argument,
[Slot(1, Binding.None)] out Vector1 result)
{
return
@"
{
result = ddx(argument);
}
";
}
}
}

29
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/DDXY.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class DDXYNode : Function1Input, IGeneratesFunction
public class DDXYNode : CodeFunctionNode
{
public DDXYNode()
{

protected override string GetFunctionName()
protected override MethodInfo GetFunctionToConvert()
return "unity_ddxy_" + precision;
return GetType().GetMethod("Unity_DDXY", BindingFlags.Static | BindingFlags.NonPublic);
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
static string Unity_DDXY(
[Slot(0, Binding.None)] Vector1 argument,
[Slot(1, Binding.None)] out Vector1 result)
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return abs(ddx(arg1) + ddy(arg1));", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
return
@"
{
result = abs(ddx(argument) + ddy(argument));
}
";
}
}
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/DDY.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class DDYNode : Function1Input
public class DDYNode : CodeFunctionNode
{
public DDYNode()
{

protected override string GetFunctionName() { return "ddy"; }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_DDY", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_DDY(
[Slot(0, Binding.None)] Vector1 argument,
[Slot(1, Binding.None)] out Vector1 result)
{
return
@"
{
result = ddy(argument);
}
";
}
}
}

27
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Normal/UnpackNormalNode.cs


using System.Reflection;
using UnityEngine.Graphing;

internal class UnpackNormalNode : Function1Input
internal class UnpackNormalNode : CodeFunctionNode
{
public UnpackNormalNode()
{

get { return false; }
}
protected override MaterialSlot GetInputSlot()
protected override MethodInfo GetFunctionToConvert()
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector4, Vector4.zero);
return GetType().GetMethod("Unity_UnpackNormal", BindingFlags.Static | BindingFlags.NonPublic);
protected override MaterialSlot GetOutputSlot()
static string Unity_Sign(
[Slot(0, Binding.None)] Vector4 packedNormal,
[Slot(1, Binding.None)] out Vector3 normal)
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero);
}
protected override string GetInputSlotName() {return "PackedNormal"; }
protected override string GetOutputSlotName() {return "Normal"; }
protected override string GetFunctionName()
{
return "UnpackNormal";
normal = Vector3.up;
return
@"
{
normal = UnpackNormal(packedNormal);
}
";
}
}
}

135
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/NoiseNode.cs


namespace UnityEngine.MaterialGraph
using System.Reflection;
namespace UnityEngine.MaterialGraph
public class NoiseNode : Function1Input, IGeneratesFunction
public class NoiseNode : CodeFunctionNode
{
public NoiseNode()
{

protected override string GetFunctionName()
protected override MethodInfo GetFunctionToConvert()
return "unity_noise_" + precision;
return GetType().GetMethod("Unity_Noise", BindingFlags.Static | BindingFlags.NonPublic);
protected override string GetInputSlotName()
static string Unity_Noise(
[Slot(0, Binding.MeshUV0)] Vector2 uv,
[Slot(1, Binding.None)] out Vector1 noise)
return "UV";
return
@"
{
float t = 0.0;
for(int i = 0; i < 3; i++)
{
float freq = pow(2.0, float(i));
float amp = pow(0.5, float(3-i));
t += unity_valueNoise(float2(uv.x/freq, uv.y/freq))*amp;
}
noise = t;
}
";
protected override MaterialSlot GetInputSlot()
public override void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
string functionPreamble = @"
inline float unity_noise_randomValue (float2 uv)
{
return frac(sin(dot(uv, float2(12.9898, 78.233)))*43758.5453);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector1, Vector2.zero);
}
inline float unity_noise_interpolate (float a, float b, float t)
{
return (1.0-t)*a + (t*b);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
inline float unity_valueNoise (float2 uv)
{
float2 i = floor(uv);
float2 f = frac(uv);
f = f * f * (3.0 - 2.0 * f);
outputString.AddShaderChunk("inline float unity_noise_randomValue (float2 uv)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
uv = abs(frac(uv) - 0.5);
float2 c0 = i + float2(0.0, 0.0);
float2 c1 = i + float2(1.0, 0.0);
float2 c2 = i + float2(0.0, 1.0);
float2 c3 = i + float2(1.0, 1.0);
float r0 = unity_noise_randomValue(c0);
float r1 = unity_noise_randomValue(c1);
float r2 = unity_noise_randomValue(c2);
float r3 = unity_noise_randomValue(c3);
outputString.AddShaderChunk("return frac(sin(dot(uv, float2(12.9898, 78.233)))*43758.5453);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("inline float unity_noise_interpolate (float a, float b, float t)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return (1.0-t)*a + (t*b);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("inline float unity_valueNoise (float2 uv)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float2 i = floor(uv);", false);
outputString.AddShaderChunk("float2 f = frac(uv);", false);
outputString.AddShaderChunk("f = f * f * (3.0 - 2.0 * f);", false);
outputString.AddShaderChunk("uv = abs(frac(uv) - 0.5);", false);
outputString.AddShaderChunk("float2 c0 = i + float2(0.0, 0.0);", false);
outputString.AddShaderChunk("float2 c1 = i + float2(1.0, 0.0);", false);
outputString.AddShaderChunk("float2 c2 = i + float2(0.0, 1.0);", false);
outputString.AddShaderChunk("float2 c3 = i + float2(1.0, 1.0);", false);
outputString.AddShaderChunk("float r0 = unity_noise_randomValue(c0);", false);
outputString.AddShaderChunk("float r1 = unity_noise_randomValue(c1);", false);
outputString.AddShaderChunk("float r2 = unity_noise_randomValue(c2);", false);
outputString.AddShaderChunk("float r3 = unity_noise_randomValue(c3);", false);
outputString.AddShaderChunk("float bottomOfGrid = unity_noise_interpolate(r0, r1, f.x);", false);
outputString.AddShaderChunk("float topOfGrid = unity_noise_interpolate(r2, r3, f.x);", false);
outputString.AddShaderChunk("float t = unity_noise_interpolate(bottomOfGrid, topOfGrid, f.y);", false);
outputString.AddShaderChunk("return t;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk(GetFunctionPrototype("uv"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float t = 0.0;", false);
outputString.AddShaderChunk("for(int i = 0; i < 3; i++)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float freq = pow(2.0, float(i));", false);
outputString.AddShaderChunk("float amp = pow(0.5, float(3-i));", false);
outputString.AddShaderChunk("t += unity_valueNoise(float2(uv.x/freq, uv.y/freq))*amp;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("return t;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
float bottomOfGrid = unity_noise_interpolate(r0, r1, f.x);
float topOfGrid = unity_noise_interpolate(r2, r3, f.x);
float t = unity_noise_interpolate(bottomOfGrid, topOfGrid, f.y);
return t;
}";
visitor.AddShaderChunk(functionPreamble, true);
base.GenerateNodeFunction(visitor, generationMode);
}
}
}

48
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/CartesianToPolarNode.cs


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

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/SpherizeNode.cs


{precision}2 fromUVToPoint = position - uv;
{precision} dist = length(fromUVToPoint);
{precision} mag = ((1.0 - (dist / radiusAndStrength.x)) * radiusAndStrength.y) * step(dist, radiusAndStrength.x);
return uv + (mag * fromUVToPoint);
result = uv + (mag * fromUVToPoint);
}";
}
}

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


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

93
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs


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

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:

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

77
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function1Input.cs


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

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function1Input.cs.meta


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

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:

9
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Legacy.meta


fileFormatVersion: 2
guid: eb0cb153896a18c4ebb6d116283dfda4
folderAsset: yes
timeCreated: 1495532221
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/_MingWai/GeneratedTextureDemo/StandardShader.meta


fileFormatVersion: 2
guid: 0255be381ce130c4ea649efcaaa61c0a
folderAsset: yes
timeCreated: 1495751822
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存