RemapNode.cs 914 B

12345678910111213141516171819202122232425262728293031323334
  1. using System.Reflection;
  2. using UnityEngine;
  3. namespace UnityEditor.ShaderGraph
  4. {
  5. [Title("Math", "Range", "Remap")]
  6. class RemapNode : CodeFunctionNode
  7. {
  8. public RemapNode()
  9. {
  10. name = "Remap";
  11. }
  12. protected override MethodInfo GetFunctionToConvert()
  13. {
  14. return GetType().GetMethod("Unity_Remap", BindingFlags.Static | BindingFlags.NonPublic);
  15. }
  16. static string Unity_Remap(
  17. [Slot(0, Binding.None, -1, -1, -1, -1)] DynamicDimensionVector In,
  18. [Slot(1, Binding.None, -1, 1, 0, 0)] Vector2 InMinMax,
  19. [Slot(2, Binding.None, 0, 1, 0, 0)] Vector2 OutMinMax,
  20. [Slot(3, Binding.None)] out DynamicDimensionVector Out)
  21. {
  22. return
  23. @"
  24. {
  25. Out = OutMinMax.x + (In - InMinMax.x) * (OutMinMax.y - OutMinMax.x) / (InMinMax.y - InMinMax.x);
  26. }
  27. ";
  28. }
  29. }
  30. }