RectangleNode.cs 958 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Reflection;
  2. using UnityEngine;
  3. namespace UnityEditor.ShaderGraph
  4. {
  5. [Title("Procedural", "Shape", "Rectangle")]
  6. class RectangleNode : CodeFunctionNode
  7. {
  8. public RectangleNode()
  9. {
  10. name = "Rectangle";
  11. }
  12. protected override MethodInfo GetFunctionToConvert()
  13. {
  14. return GetType().GetMethod("Unity_Rectangle", BindingFlags.Static | BindingFlags.NonPublic);
  15. }
  16. static string Unity_Rectangle(
  17. [Slot(0, Binding.MeshUV0)] Vector2 UV,
  18. [Slot(1, Binding.None, 0.5f, 0, 0, 0)] Vector1 Width,
  19. [Slot(2, Binding.None, 0.5f, 0, 0, 0)] Vector1 Height,
  20. [Slot(3, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
  21. {
  22. return
  23. @"
  24. {
  25. $precision2 d = abs(UV * 2 - 1) - $precision2(Width, Height);
  26. d = 1 - d / fwidth(d);
  27. Out = saturate(min(d.x, d.y));
  28. }";
  29. }
  30. }
  31. }