您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
46 行
1.1 KiB
46 行
1.1 KiB
using System.Reflection;
|
|
|
|
namespace UnityEngine.MaterialGraph
|
|
{
|
|
[Title("UV/UV Rotator")]
|
|
public class UVRotatorNode : CodeFunctionNode
|
|
{
|
|
public UVRotatorNode()
|
|
{
|
|
name = "UVRotator";
|
|
}
|
|
|
|
protected override MethodInfo GetFunctionToConvert()
|
|
{
|
|
return GetType().GetMethod("Unity_UVRotator", BindingFlags.Static | BindingFlags.NonPublic);
|
|
}
|
|
|
|
static string Unity_UVRotator(
|
|
[Slot(0, Binding.MeshUV0)] Vector4 uv,
|
|
[Slot(1, Binding.None)] Vector1 rotation,
|
|
[Slot(2, Binding.None)] out Vector4 result)
|
|
{
|
|
result = Vector2.zero;
|
|
return
|
|
@"
|
|
{
|
|
//rotation matrix
|
|
uv.xy -= 0.5;
|
|
{precision} s = sin(rotation);
|
|
{precision} c = cos(rotation);
|
|
|
|
|
|
//center rotation matrix
|
|
{precision}2x2 rMatrix = float2x2(c, -s, s, c);
|
|
rMatrix *= 0.5;
|
|
rMatrix += 0.5;
|
|
rMatrix = rMatrix*2 - 1;
|
|
|
|
//multiply the UVs by the rotation matrix
|
|
uv.xy = mul(uv.xy, rMatrix);
|
|
uv.xy += 0.5;
|
|
result = uv;
|
|
}";
|
|
}
|
|
}
|
|
}
|