您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
79 行
2.0 KiB
79 行
2.0 KiB
using System.Reflection;
|
|
using UnityEngine;
|
|
using UnityEditor.Graphing;
|
|
using UnityEditor.ShaderGraph.Drawing.Controls;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
public enum ReciprocalMethod
|
|
{
|
|
Default,
|
|
Fast
|
|
};
|
|
|
|
[Title("Math", "Advanced", "Reciprocal")]
|
|
public class ReciprocalNode : CodeFunctionNode
|
|
{
|
|
public ReciprocalNode()
|
|
{
|
|
name = "Reciprocal";
|
|
}
|
|
|
|
public override string documentationURL
|
|
{
|
|
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Reciprocal-Node"; }
|
|
}
|
|
|
|
[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);
|
|
}
|
|
";
|
|
}
|
|
}
|
|
}
|