ExponentialNode.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Reflection;
  2. using UnityEngine;
  3. using UnityEditor.Graphing;
  4. using UnityEditor.ShaderGraph.Drawing.Controls;
  5. namespace UnityEditor.ShaderGraph
  6. {
  7. enum ExponentialBase
  8. {
  9. BaseE,
  10. Base2
  11. };
  12. [Title("Math", "Advanced", "Exponential")]
  13. class ExponentialNode : CodeFunctionNode
  14. {
  15. public ExponentialNode()
  16. {
  17. name = "Exponential";
  18. }
  19. [SerializeField]
  20. private ExponentialBase m_ExponentialBase = ExponentialBase.BaseE;
  21. [EnumControl("Base")]
  22. public ExponentialBase exponentialBase
  23. {
  24. get { return m_ExponentialBase; }
  25. set
  26. {
  27. if (m_ExponentialBase == value)
  28. return;
  29. m_ExponentialBase = value;
  30. Dirty(ModificationScope.Graph);
  31. }
  32. }
  33. protected override MethodInfo GetFunctionToConvert()
  34. {
  35. switch (m_ExponentialBase)
  36. {
  37. case ExponentialBase.Base2:
  38. return GetType().GetMethod("Unity_Exponential2", BindingFlags.Static | BindingFlags.NonPublic);
  39. default:
  40. return GetType().GetMethod("Unity_Exponential", BindingFlags.Static | BindingFlags.NonPublic);
  41. }
  42. }
  43. static string Unity_Exponential(
  44. [Slot(0, Binding.None)] DynamicDimensionVector In,
  45. [Slot(1, Binding.None)] out DynamicDimensionVector Out)
  46. {
  47. return
  48. @"
  49. {
  50. Out = exp(In);
  51. }
  52. ";
  53. }
  54. static string Unity_Exponential2(
  55. [Slot(0, Binding.None)] DynamicDimensionVector In,
  56. [Slot(1, Binding.None)] out DynamicDimensionVector Out)
  57. {
  58. return
  59. @"
  60. {
  61. Out = exp2(In);
  62. }
  63. ";
  64. }
  65. }
  66. }