EllipseNode.cs 929 B

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