123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System.Reflection;
- using UnityEngine;
- using UnityEditor.Graphing;
- using UnityEditor.ShaderGraph.Drawing.Controls;
- namespace UnityEditor.ShaderGraph
- {
- enum ReciprocalMethod
- {
- Default,
- Fast
- };
- [Title("Math", "Advanced", "Reciprocal")]
- class ReciprocalNode : CodeFunctionNode
- {
- public ReciprocalNode()
- {
- name = "Reciprocal";
- }
- [SerializeField]
- private ReciprocalMethod m_ReciprocalMethod = ReciprocalMethod.Default;
- [EnumControl("Method")]
- public ReciprocalMethod reciprocalMethod
- {
- get { return m_ReciprocalMethod; }
- set
- {
- if (m_ReciprocalMethod == value)
- return;
- m_ReciprocalMethod = value;
- Dirty(ModificationScope.Graph);
- }
- }
- protected override MethodInfo GetFunctionToConvert()
- {
- switch (m_ReciprocalMethod)
- {
- case ReciprocalMethod.Fast:
- return GetType().GetMethod("Unity_Reciprocal_Fast", BindingFlags.Static | BindingFlags.NonPublic);
- default:
- return GetType().GetMethod("Unity_Reciprocal", BindingFlags.Static | BindingFlags.NonPublic);
- }
- }
- static string Unity_Reciprocal(
- [Slot(0, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector In,
- [Slot(1, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = 1.0/In;
- }
- ";
- }
- static string Unity_Reciprocal_Fast(
- [Slot(0, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector In,
- [Slot(1, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = rcp(In);
- }
- ";
- }
- }
- }
|