浏览代码

Maths Part 1

- Maths/Basic
- Maths/Advanced
- Maths/Range
- Add HLSL safe conversion for node name
/main
Matt Dean 7 年前
当前提交
4ec6fe3b
共有 46 个文件被更改,包括 449 次插入373 次删除
  1. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
  2. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/AbsoluteNode.cs
  3. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/LengthNode.cs
  4. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/LogNode.cs
  5. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/NegateNode.cs
  6. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/NormalizeNode.cs
  7. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/PosterizeNode.cs
  8. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/ReciprocalNode.cs
  9. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/AddNode.cs
  10. 45
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/ExponentialNode.cs
  11. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/MultiplyNode.cs
  12. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/PowerNode.cs
  13. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/SquareRootNode.cs
  14. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/SubtractNode.cs
  15. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/ClampNode.cs
  16. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/FractionNode.cs
  17. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/RemapNode.cs
  18. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/SaturateNode.cs
  19. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic.meta
  20. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/ModuloNode.cs
  21. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/ReciprocalSquareRootNode.cs
  22. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/DivideNode.cs
  23. 31
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MaximumNode.cs
  24. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MinimumNode.cs
  25. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/OneMinusNode.cs
  26. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/RandomRangeNode.cs
  27. 73
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/ConstantNode.cs
  28. 32
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/RandomRangeNode.cs
  29. 30
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/ReciprocalSqrtNode.cs
  30. 60
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs
  31. 11
      MaterialGraphProject/Assets/NewNodes/Editor/ConstantType.cs
  32. 12
      MaterialGraphProject/Assets/NewNodes/Editor/ConstantType.cs.meta
  33. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/FmodNode.cs
  34. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/DivNode.cs
  35. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MinNode.cs
  36. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/OneMinus.cs
  37. 31
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MaxNode.cs
  38. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/ModuloNode.cs.meta
  39. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/DivideNode.cs.meta
  40. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MaximumNode.cs.meta
  41. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MinimumNode.cs.meta
  42. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/OneMinusNode.cs.meta
  43. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/ConstantNode.cs.meta
  44. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/RandomRangeNode.cs.meta
  45. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/ReciprocalSquareRootNode.cs.meta

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs


var slot = FindSlot<MaterialSlot>(slotId);
if (slot == null)
throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId");
return GetVariableNameForNode() + "_" + slot.shaderOutputName;
return "_" + GetVariableNameForNode() + "_" + GetHLSLSafeName(slot.shaderOutputName);
return name + "_" + GuidEncoder.Encode(guid);
return GetHLSLSafeName(name) + "_" + GuidEncoder.Encode(guid);
}
public virtual string GetHLSLSafeName(string input)
{
char[] arr = input.ToCharArray();
arr = Array.FindAll<char>(arr, (c => (char.IsLetterOrDigit(c))));
return new string(arr);
}
public sealed override void AddSlot(ISlot slot)

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/AbsoluteNode.cs


}
static string Unity_Absolute(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
result = abs(argument);
Out = abs(In);
}
";
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/LengthNode.cs


}
static string Unity_Length(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
result = length(argument);
Out = length(In);
}
";
}

43
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/LogNode.cs


using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
public enum LogType
{
Log,
Log2,
Log10
};
[Title("Math/Advanced/Log")]
public class LogNode : CodeFunctionNode
{

}
static Dictionary<LogType, string> m_LogTypes = new Dictionary<LogType, string>
{
{LogType.Log, "" },
{LogType.Log2, "2" },
{LogType.Log10, "10" },
};
[SerializeField]
private static LogType m_LogType = LogType.Log;
[EnumControl("")]
public LogType logType
{
get { return m_LogType; }
set
{
if (m_LogType == value)
return;
m_LogType = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Log", BindingFlags.Static | BindingFlags.NonPublic);

[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
result = log(argument);
Out = log"+ m_LogTypes[m_LogType] + @"(In);
}
";
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/NegateNode.cs


}
static string Unity_Negate(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
result = -1 * argument;
Out = -1 * In;
}
";
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/NormalizeNode.cs


}
static string Unity_Normalize(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
result = normalize(argument);
Out = normalize(In);
}
";
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/PosterizeNode.cs


}
static string Unity_Posterize(
[Slot(0, Binding.None)] DynamicDimensionVector input,
[Slot(1, Binding.None)] DynamicDimensionVector stepsize,
[Slot(2, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] DynamicDimensionVector Steps,
[Slot(2, Binding.None)] out DynamicDimensionVector Out)
result = floor(input / stepsize) * stepsize;;
Out = floor(In / (1 / Steps)) * (1 / Steps);
}
";
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/ReciprocalNode.cs


}
static string Unity_Reciprocal(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
result = 1.0/argument;
Out = 1.0/In;
}
";
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/AddNode.cs


}
static string Unity_Add(
[Slot(0, Binding.None)] DynamicDimensionVector first,
[Slot(1, Binding.None)] DynamicDimensionVector second,
[Slot(2, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector A,
[Slot(1, Binding.None)] DynamicDimensionVector B,
[Slot(2, Binding.None)] out DynamicDimensionVector Out)
result = first + second;
Out = A + B;
}
";
}

45
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/ExponentialNode.cs


using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
public enum ExponentialType
{
Exp,
Exp2
};
[Title("Math/Basic/Exponential")]
public class ExponentialNode : CodeFunctionNode
{

}
static Dictionary<ExponentialType, string> m_ExponentialTypes = new Dictionary<ExponentialType, string>
{
{ExponentialType.Exp, "" },
{ExponentialType.Exp2, "2" },
};
[SerializeField]
private static ExponentialType m_ExponentialType = ExponentialType.Exp;
[EnumControl("")]
public ExponentialType exponentialType
{
get { return m_ExponentialType; }
set
{
if (m_ExponentialType == value)
return;
m_ExponentialType = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
return GetType().GetMethod("Unity_Exp", BindingFlags.Static | BindingFlags.NonPublic);
return GetType().GetMethod("Unity_Exponential", BindingFlags.Static | BindingFlags.NonPublic);
static string Unity_Exp(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
static string Unity_Exponential(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
result = exp(argument);
Out = exp"+m_ExponentialTypes[m_ExponentialType] +@"(In);
}
";
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/MultiplyNode.cs


}
static string Unity_Multiply(
[Slot(0, Binding.None)] DynamicDimensionVector first,
[Slot(1, Binding.None)] DynamicDimensionVector second,
[Slot(2, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector A,
[Slot(1, Binding.None)] DynamicDimensionVector B,
[Slot(2, Binding.None)] out DynamicDimensionVector Out)
result = first * second;
Out = A * B;
}
";
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/PowerNode.cs


protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Pow", BindingFlags.Static | BindingFlags.NonPublic);
return GetType().GetMethod("Unity_Power", BindingFlags.Static | BindingFlags.NonPublic);
static string Unity_Pow(
[Slot(0, Binding.None)] DynamicDimensionVector first,
[Slot(1, Binding.None)] DynamicDimensionVector second,
[Slot(2, Binding.None)] out DynamicDimensionVector result)
static string Unity_Power(
[Slot(0, Binding.None)] DynamicDimensionVector A,
[Slot(1, Binding.None)] DynamicDimensionVector B,
[Slot(2, Binding.None)] out DynamicDimensionVector Out)
result = pow(first, second);
Out = pow(A, B);
}
";
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/SquareRootNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Basic/SquareRoot")]
[Title("Math/Basic/Square Root")]
name = "SquareRoot";
name = "Square Root";
return GetType().GetMethod("Unity_Sqrt", BindingFlags.Static | BindingFlags.NonPublic);
return GetType().GetMethod("Unity_SquareRoot", BindingFlags.Static | BindingFlags.NonPublic);
static string Unity_Sqrt(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
static string Unity_SquareRoot(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
result = sqrt(argument);
Out = sqrt(In);
}
";
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/SubtractNode.cs


}
static string Unity_Subtract(
[Slot(0, Binding.None)] DynamicDimensionVector first,
[Slot(1, Binding.None)] DynamicDimensionVector second,
[Slot(2, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector A,
[Slot(1, Binding.None)] DynamicDimensionVector B,
[Slot(2, Binding.None)] out DynamicDimensionVector Out)
result = first - second;
Out = A - B;
}
";
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/ClampNode.cs


protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Smoothstep", BindingFlags.Static | BindingFlags.NonPublic);
return GetType().GetMethod("Unity_Clamp", BindingFlags.Static | BindingFlags.NonPublic);
static string Unity_Smoothstep(
[Slot(0, Binding.None)] DynamicDimensionVector input,
[Slot(1, Binding.None)] DynamicDimensionVector min,
[Slot(2, Binding.None)] DynamicDimensionVector max,
[Slot(3, Binding.None)] out DynamicDimensionVector result)
static string Unity_Clamp(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] DynamicDimensionVector Min,
[Slot(2, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector Max,
[Slot(3, Binding.None)] out DynamicDimensionVector Out)
result = clamp(input, min, max);
Out = clamp(In, Min, Max);
}";
}
}

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/FractionNode.cs


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

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/RemapNode.cs


}
static string Unity_Remap(
[Slot(0, Binding.None)] DynamicDimensionVector input,
[Slot(1, Binding.None)] Vector2 inMinMax,
[Slot(2, Binding.None)] Vector2 outMinMax,
[Slot(3, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None, 0, 1, 0, 0)] Vector2 InMinMax,
[Slot(2, Binding.None, 0, 1, 0, 0)] Vector2 OutMinMax,
[Slot(3, Binding.None)] out DynamicDimensionVector Out)
result = outMinMax.x + (input - inMinMax.x) * (outMinMax.y - outMinMax.x) / (inMinMax.y - inMinMax.x);
Out = OutMinMax.x + (In - InMinMax.x) * (OutMinMax.y - OutMinMax.x) / (InMinMax.y - InMinMax.x);
}
";
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/SaturateNode.cs


}
static string Unity_Saturate(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
result = saturate(argument);
Out = saturate(In);
}
";
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic.meta


fileFormatVersion: 2
guid: b43ef3944c134a74995e6582de94d21b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/ModuloNode.cs


using System;
using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Advanced/Modulo")]
public class ModuloNode : CodeFunctionNode
{
public ModuloNode()
{
name = "Modulo";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Modulo", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Modulo(
[Slot(0, Binding.None)] DynamicDimensionVector A,
[Slot(1, Binding.None)] DynamicDimensionVector B,
[Slot(2, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = fmod(A, B);
}
";
}
}
}

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/ReciprocalSquareRootNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Advanced/Reciprocal Square Root")]
public class ReciprocalSquareRootNode : CodeFunctionNode
{
public ReciprocalSquareRootNode()
{
name = "Reciprocal Square Root";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Rsqrt", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Rsqrt(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = rsqrt(In);
}
";
}
}
}

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/DivideNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Basic/Divide")]
public class DivideNode : CodeFunctionNode
{
public DivideNode()
{
name = "Divide";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Divide", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Divide(
[Slot(0, Binding.None)] DynamicDimensionVector A,
[Slot(1, Binding.None)] DynamicDimensionVector B,
[Slot(2, Binding.None)] out DynamicDimensionVector Out)
{
return @"
{
Out = A / B;
}
";
}
}
}

31
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MaximumNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Range/Maximum")]
public class MaximumNode : CodeFunctionNode
{
public MaximumNode()
{
name = "Maximum";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Maximum", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Maximum(
[Slot(0, Binding.None)] DynamicDimensionVector A,
[Slot(1, Binding.None)] DynamicDimensionVector B,
[Slot(2, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = max(A, B);
}
";
}
}
}

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MinimumNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Range/Minimum")]
public class MinimumNode : CodeFunctionNode
{
public MinimumNode()
{
name = "Minimum";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Minimum", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Minimum(
[Slot(0, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector A,
[Slot(1, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector B,
[Slot(2, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = min(A, B);
};";
}
}
}

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/OneMinusNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Range/One Minus")]
public class OneMinusNode : CodeFunctionNode
{
public OneMinusNode()
{
name = "One Minus";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_OneMinus", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_OneMinus(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = 1 - In;
}
";
}
}
}

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/RandomRangeNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Range/Random Range")]
public class RandomRangeNode : CodeFunctionNode
{
public RandomRangeNode()
{
name = "Random Range";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_RandomRange", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_RandomRange(
[Slot(0, Binding.None)] Vector1 Seed,
[Slot(1, Binding.None)] Vector1 Min,
[Slot(2, Binding.None, 1, 1, 1, 1)] Vector1 Max,
[Slot(3, Binding.None)] out Vector1 Out)
{
return
@"
{
{precision} randomno = frac(sin(dot({precision}2(Seed, Seed), float2(12.9898, 78.233)))*43758.5453);
Out = floor(randomno * (Max - Min + 1)) + Min;
}";
}
}
}

73
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/ConstantNode.cs


using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
public enum ConstantType
{
PI,
TAU,
PHI,
E,
SQRT2
};
[Title("Input/Basic/Constant")]
public class ConstantNode : AbstractMaterialNode, IGeneratesBodyCode
{
static Dictionary<ConstantType, float> m_constantList = new Dictionary<ConstantType, float>
{
{ConstantType.PI, 3.1415926f },
{ConstantType.TAU, 6.28318530f},
{ConstantType.PHI, 1.618034f},
{ConstantType.E, 2.718282f},
{ConstantType.SQRT2, 1.414214f},
};
[SerializeField]
private ConstantType m_constant = ConstantType.PI;
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";
[EnumControl("")]
public ConstantType constant
{
get { return m_constant; }
set
{
if (m_constant == value)
return;
m_constant = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public ConstantNode()
{
name = "Constant";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_constantList[constant] + ";", true);
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
}
}

32
MaterialGraphProject/Assets/NewNodes/Editor/Keep/RandomRangeNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Range/RandomRange")]
public class RandomRangeNode : CodeFunctionNode
{
public RandomRangeNode()
{
name = "RandomRange";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Randomrange", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Randomrange(
[Slot(0, Binding.None)] Vector2 seed,
[Slot(1, Binding.None)] Vector1 min,
[Slot(2, Binding.None)] Vector1 max,
[Slot(3, Binding.None)] out Vector1 result)
{
return
@"
{
{precision} randomno = frac(sin(dot(seed, float2(12.9898, 78.233)))*43758.5453);
retresult = floor(randomno * (max - min + 1)) + min;
}";
}
}
}

30
MaterialGraphProject/Assets/NewNodes/Editor/Keep/ReciprocalSqrtNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Advanced/Reciprocal Square Root")]
public class ReciprocalSqrtNode : CodeFunctionNode
{
public ReciprocalSqrtNode()
{
name = "ReciprocalSquareRoot";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Rsqrt", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Rsqrt(
[Slot(0, Binding.None)] DynamicDimensionVector first,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = rsqrt(argument);
}
";
}
}
}

60
MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs


using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.MaterialGraph;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Constants")]
public class ConstantsNode : AbstractMaterialNode, IGeneratesBodyCode
{
static Dictionary<ConstantType, float> m_constantList = new Dictionary<ConstantType, float>
{
{ConstantType.PI, 3.1415926f },
{ConstantType.TAU, 6.28318530f},
{ConstantType.PHI, 1.618034f},
{ConstantType.E, 2.718282f},
{ConstantType.SQRT2, 1.414214f},
};
[SerializeField]
private ConstantType m_constant = ConstantType.PI;
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Constant";
[EnumControl("")]
public ConstantType constant
{
get { return m_constant; }
set
{
if (m_constant == value)
return;
m_constant = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public ConstantsNode()
{
name = "MathConstant";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_constantList[constant] + ";", true);
}
}
}

11
MaterialGraphProject/Assets/NewNodes/Editor/ConstantType.cs


namespace UnityEngine.MaterialGraph
{
public enum ConstantType
{
PI,
TAU,
PHI,
E,
SQRT2
};
}

12
MaterialGraphProject/Assets/NewNodes/Editor/ConstantType.cs.meta


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

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/FmodNode.cs


using System;
using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Advanced/Fmod")]
public class FmodNode : CodeFunctionNode
{
public FmodNode()
{
name = "Fmod";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Fmod", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Fmod(
[Slot(0, Binding.None)] DynamicDimensionVector first,
[Slot(1, Binding.None)] DynamicDimensionVector second,
[Slot(2, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = fmod(first, second);
}
";
}
}
}

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/DivNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Basic/Divide")]
public class DivNode : CodeFunctionNode
{
public DivNode()
{
name = "Divide";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Div", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Div(
[Slot(0, Binding.None)] DynamicDimensionVector first,
[Slot(1, Binding.None)] DynamicDimensionVector second,
[Slot(2, Binding.None)] out DynamicDimensionVector result)
{
return @"
{
result = first / second;
}
";
}
}
}

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MinNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Range/Minimum")]
public class MinimumNode : CodeFunctionNode
{
public MinimumNode()
{
name = "Minimum";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Min", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Min(
[Slot(0, Binding.None)] DynamicDimensionVector first,
[Slot(1, Binding.None)] DynamicDimensionVector second,
[Slot(2, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = min(first, second);
};";
}
}
}

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/OneMinus.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Range/OneMinus")]
public class OneMinusNode : CodeFunctionNode
{
public OneMinusNode()
{
name = "OneMinus";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_OneMinus", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_OneMinus(
[Slot(0, Binding.None)] DynamicDimensionVector argument,
[Slot(1, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = argument * -1 + 1;;
}
";
}
}
}

31
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MaxNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Range/Maximum")]
public class MaximumNode : CodeFunctionNode
{
public MaximumNode()
{
name = "Maximum";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Max", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Max(
[Slot(0, Binding.None)] DynamicDimensionVector first,
[Slot(1, Binding.None)] DynamicDimensionVector second,
[Slot(2, Binding.None)] out DynamicDimensionVector result)
{
return
@"
{
result = max(first, second);
}
";
}
}
}

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/FmodNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/ModuloNode.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/DivNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/DivideNode.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MaxNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MaximumNode.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MinNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/MinimumNode.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/OneMinus.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/OneMinusNode.cs.meta

/MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/ConstantNode.cs.meta

/MaterialGraphProject/Assets/NewNodes/Editor/Keep/RandomRangeNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Range/RandomRangeNode.cs.meta

/MaterialGraphProject/Assets/NewNodes/Editor/Keep/ReciprocalSqrtNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/ReciprocalSquareRootNode.cs.meta

正在加载...
取消
保存