RadialShearNode.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Reflection;
  2. using UnityEngine;
  3. namespace UnityEditor.ShaderGraph
  4. {
  5. [Title("UV", "Radial Shear")]
  6. class RadialShearNode : CodeFunctionNode
  7. {
  8. public RadialShearNode()
  9. {
  10. name = "Radial Shear";
  11. }
  12. protected override MethodInfo GetFunctionToConvert()
  13. {
  14. return GetType().GetMethod("Unity_RadialShear", BindingFlags.Static | BindingFlags.NonPublic);
  15. }
  16. static string Unity_RadialShear(
  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, 10f, 10f, 10f, 10f)] Vector2 Strength,
  20. [Slot(3, Binding.None)] Vector2 Offset,
  21. [Slot(4, Binding.None)] out Vector2 Out)
  22. {
  23. Out = Vector2.zero;
  24. return
  25. @"
  26. {
  27. $precision2 delta = UV - Center;
  28. $precision delta2 = dot(delta.xy, delta.xy);
  29. $precision2 delta_offset = delta2 * Strength;
  30. Out = UV + $precision2(delta.y, -delta.x) * delta_offset + Offset;
  31. }
  32. ";
  33. }
  34. }
  35. }