LogNode.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System.Reflection;
  2. using UnityEngine;
  3. using UnityEditor.Graphing;
  4. using UnityEditor.ShaderGraph.Drawing.Controls;
  5. namespace UnityEditor.ShaderGraph
  6. {
  7. enum LogBase
  8. {
  9. BaseE,
  10. Base2,
  11. Base10
  12. };
  13. [Title("Math", "Advanced", "Log")]
  14. class LogNode : CodeFunctionNode
  15. {
  16. public LogNode()
  17. {
  18. name = "Log";
  19. }
  20. [SerializeField]
  21. private LogBase m_LogBase = LogBase.BaseE;
  22. [EnumControl("Base")]
  23. public LogBase logBase
  24. {
  25. get { return m_LogBase; }
  26. set
  27. {
  28. if (m_LogBase == value)
  29. return;
  30. m_LogBase = value;
  31. Dirty(ModificationScope.Graph);
  32. }
  33. }
  34. protected override MethodInfo GetFunctionToConvert()
  35. {
  36. switch (m_LogBase)
  37. {
  38. case LogBase.Base2:
  39. return GetType().GetMethod("Unity_Log2", BindingFlags.Static | BindingFlags.NonPublic);
  40. case LogBase.Base10:
  41. return GetType().GetMethod("Unity_Log10", BindingFlags.Static | BindingFlags.NonPublic);
  42. default:
  43. return GetType().GetMethod("Unity_Log", BindingFlags.Static | BindingFlags.NonPublic);
  44. }
  45. }
  46. static string Unity_Log(
  47. [Slot(0, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector In,
  48. [Slot(1, Binding.None)] out DynamicDimensionVector Out)
  49. {
  50. return
  51. @"
  52. {
  53. Out = log(In);
  54. }
  55. ";
  56. }
  57. static string Unity_Log2(
  58. [Slot(0, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector In,
  59. [Slot(1, Binding.None)] out DynamicDimensionVector Out)
  60. {
  61. return
  62. @"
  63. {
  64. Out = log2(In);
  65. }
  66. ";
  67. }
  68. static string Unity_Log10(
  69. [Slot(0, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector In,
  70. [Slot(1, Binding.None)] out DynamicDimensionVector Out)
  71. {
  72. return
  73. @"
  74. {
  75. Out = log10(In);
  76. }
  77. ";
  78. }
  79. }
  80. }