您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
41 行
1.1 KiB
41 行
1.1 KiB
using System.Reflection;
|
|
using UnityEngine;
|
|
using UnityEditor.Graphing;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
[Title("UV", "Twirl")]
|
|
public class TwirlNode : CodeFunctionNode
|
|
{
|
|
public TwirlNode()
|
|
{
|
|
name = "Twirl";
|
|
}
|
|
|
|
protected override MethodInfo GetFunctionToConvert()
|
|
{
|
|
return GetType().GetMethod("Unity_Twirl", BindingFlags.Static | BindingFlags.NonPublic);
|
|
}
|
|
|
|
static string Unity_Twirl(
|
|
[Slot(0, Binding.MeshUV0)] Vector2 UV,
|
|
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector2 Center,
|
|
[Slot(2, Binding.None, 0f, 0f, 0f, 0f)] Vector1 Strength,
|
|
[Slot(3, Binding.None)] Vector2 Offset,
|
|
[Slot(4, Binding.None)] out Vector2 Out)
|
|
{
|
|
Out = Vector2.zero;
|
|
|
|
return
|
|
@"
|
|
{
|
|
float2 delta = UV - Center;
|
|
{precision} angle = Strength * length(delta);
|
|
{precision} x = cos(angle) * delta.x - sin(angle) * delta.y;
|
|
{precision} y = sin(angle) * delta.x + cos(angle) * delta.y;
|
|
Out = float2(x + Center.x + Offset.x, y + Center.y + Offset.y);
|
|
}
|
|
";
|
|
}
|
|
}
|
|
}
|