PolarCoordinatesNode.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Reflection;
  2. using UnityEngine;
  3. namespace UnityEditor.ShaderGraph
  4. {
  5. [Title("UV", "Polar Coordinates")]
  6. class PolarCoordinatesNode : CodeFunctionNode
  7. {
  8. public PolarCoordinatesNode()
  9. {
  10. name = "Polar Coordinates";
  11. }
  12. protected override MethodInfo GetFunctionToConvert()
  13. {
  14. return GetType().GetMethod("Unity_PolarCoordinates", BindingFlags.Static | BindingFlags.NonPublic);
  15. }
  16. static string Unity_PolarCoordinates(
  17. [Slot(0, Binding.MeshUV0)] Vector2 UV,
  18. [Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector2 Center,
  19. [Slot(2, Binding.None, 1.0f, 1.0f, 1.0f, 1.0f)] Vector1 RadialScale,
  20. [Slot(3, Binding.None, 1.0f, 1.0f, 1.0f, 1.0f)] Vector1 LengthScale,
  21. [Slot(4, Binding.None)] out Vector2 Out)
  22. {
  23. Out = Vector2.zero;
  24. return
  25. @"
  26. {
  27. $precision2 delta = UV - Center;
  28. $precision radius = length(delta) * 2 * RadialScale;
  29. $precision angle = atan2(delta.x, delta.y) * 1.0/6.28 * LengthScale;
  30. Out = $precision2(radius, angle);
  31. }
  32. ";
  33. }
  34. }
  35. }