A game about forced loneliness, made by TACStudios
1using System.Reflection;
2using UnityEngine;
3using UnityEditor.Graphing;
4using UnityEditor.ShaderGraph.Drawing.Controls;
5
6namespace UnityEditor.ShaderGraph
7{
8 enum ReciprocalMethod
9 {
10 Default,
11 Fast
12 };
13
14 [Title("Math", "Advanced", "Reciprocal")]
15 class ReciprocalNode : CodeFunctionNode
16 {
17 public ReciprocalNode()
18 {
19 name = "Reciprocal";
20 synonyms = new string[] { "rcp" };
21 }
22
23 [SerializeField]
24 private ReciprocalMethod m_ReciprocalMethod = ReciprocalMethod.Default;
25
26 [EnumControl("Method")]
27 public ReciprocalMethod reciprocalMethod
28 {
29 get { return m_ReciprocalMethod; }
30 set
31 {
32 if (m_ReciprocalMethod == value)
33 return;
34
35 m_ReciprocalMethod = value;
36 Dirty(ModificationScope.Graph);
37 }
38 }
39
40 protected override MethodInfo GetFunctionToConvert()
41 {
42 switch (m_ReciprocalMethod)
43 {
44 case ReciprocalMethod.Fast:
45 return GetType().GetMethod("Unity_Reciprocal_Fast", BindingFlags.Static | BindingFlags.NonPublic);
46 default:
47 return GetType().GetMethod("Unity_Reciprocal", BindingFlags.Static | BindingFlags.NonPublic);
48 }
49 }
50
51 static string Unity_Reciprocal(
52 [Slot(0, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector In,
53 [Slot(1, Binding.None)] out DynamicDimensionVector Out)
54 {
55 return
56@"
57{
58 Out = 1.0/In;
59}
60";
61 }
62
63 static string Unity_Reciprocal_Fast(
64 [Slot(0, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector In,
65 [Slot(1, Binding.None)] out DynamicDimensionVector Out)
66 {
67 return
68@"
69{
70 Out = rcp(In);
71}
72";
73 }
74 }
75}