/
VectorSwizzleNode.cs
72 lines (62 loc) · 1.59 KB
/
VectorSwizzleNode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GraphProcessor;
using System.Linq;
using UnityEngine.Rendering;
namespace Mixture
{
[Documentation(@"
Swizzle the input vector, you can also choose tou output a custom value instead of a vector component.
")]
[System.Serializable, NodeMenuItem("Math/Vector Swizzle")]
public class VectorSwizzle : MixtureNode
{
[Input("Input")]
public Vector4 input;
[Output]
public Vector4 output;
public override bool showDefaultInspector => true;
public Component compX = Component.X;
public Component compY = Component.Y;
public Component compZ = Component.Z;
public Component compW = Component.W;
public float custom;
public enum Component
{
X,
Y,
Z,
W,
Custom,
}
IEnumerable< PortData > CustomOutputPort(List< SerializableEdge > edges)
{
yield return new PortData {
identifier = "Output",
displayName = $"{compX.ToString()[0]}{compY.ToString()[0]}{compZ.ToString()[0]}{compW.ToString()[0]}",
displayType = typeof(Vector4),
};
}
public override string name => "Vector Swizzle";
float Swizzle(Component c, Vector4 v)
{
switch (c)
{
case Component.X: return v.x;
case Component.Y: return v.y;
case Component.Z: return v.z;
case Component.W: return v.w;
default: case Component.Custom: return custom;
}
}
protected override bool ProcessNode(CommandBuffer cmd)
{
output.x = Swizzle(compX, input);
output.y = Swizzle(compY, input);
output.z = Swizzle(compZ, input);
output.w = Swizzle(compW, input);
return true;
}
}
}