-
Notifications
You must be signed in to change notification settings - Fork 877
Expand file tree
/
Copy pathBillboardNode.cs
More file actions
130 lines (128 loc) · 6.63 KB
/
Copy pathBillboardNode.cs
File metadata and controls
130 lines (128 loc) · 6.63 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using UnityEditor.ShaderGraph.GraphDelta;
namespace UnityEditor.ShaderGraph.Defs
{
internal class BillboardNode : IStandardNode
{
static string Name => "Billboard";
static int Version => 1;
public static NodeDescriptor NodeDescriptor => new(
Version,
Name,
"Billboard",
functions: new FunctionDescriptor[] {
new(
"Spherical",
@"Scale = mul(temp, UNITY_MATRIX_M);
rotationMatrix = UNITY_MATRIX_I_V;
Scaled_Pos.xyz = Position * Scale;
Scaled_Pos.w = 0;
BillboardPosition = TransformWorldToObject(SHADERGRAPH_OBJECT_POSITION + PivotOffset + mul(rotationMatrix, Scaled_Pos).xyz);
tempNormal.xyz = Normal;
tempNormal.w = 0;
tempTangent.xyz = Tangent;
tempTangent.w = 0;
BillboardNormal = TransformWorldToObject(mul(rotationMatrix, tempNormal).xyz);
BillboardTangent = TransformWorldToObject(mul(rotationMatrix, tempTangent).xyz);",
new ParameterDescriptor[]
{
new ParameterDescriptor("Scale", TYPE.Vec3, GraphType.Usage.Local),
new ParameterDescriptor("temp", TYPE.Vec3, GraphType.Usage.Local, new float[] {1f, 1f, 1f }),
new ParameterDescriptor("tempNormal", TYPE.Vec4, GraphType.Usage.Local),
new ParameterDescriptor("tempTangent", TYPE.Vec4, GraphType.Usage.Local),
new ParameterDescriptor("rotationMatrix", TYPE.Mat4, GraphType.Usage.Local),
new ParameterDescriptor("Scaled_Pos", TYPE.Vec4, GraphType.Usage.Local),
new ParameterDescriptor("Position", TYPE.Vec3, GraphType.Usage.In, REF.ObjectSpace_Position),
new ParameterDescriptor("Normal", TYPE.Vec3, GraphType.Usage.In, REF.ObjectSpace_Normal),
new ParameterDescriptor("Tangent", TYPE.Vec3, GraphType.Usage.In, REF.ObjectSpace_Tangent),
new ParameterDescriptor("PivotOffset", TYPE.Vec3, GraphType.Usage.In, new float[] {0f, .5f, 0f }),
new ParameterDescriptor("BillboardPosition", TYPE.Vec3, GraphType.Usage.Out),
new ParameterDescriptor("BillboardNormal", TYPE.Vec3, GraphType.Usage.Out),
new ParameterDescriptor("BillboardTangent", TYPE.Vec3, GraphType.Usage.Out)
}
),
new(
"Cylindrical",
@"Scale = mul(temp, UNITY_MATRIX_M);
rotationMatrix = UNITY_MATRIX_I_V;
rotationMatrix[1] = UpDir;
Scaled_Pos.xyz = Position * Scale;
Scaled_Pos.w = 0;
BillboardPosition = TransformWorldToObject(SHADERGRAPH_OBJECT_POSITION + PivotOffset + mul(rotationMatrix, Scaled_Pos).xyz);
tempNormal.xyz = Normal;
tempNormal.w = 0;
tempTangent.xyz = Tangent;
tempTangent.w = 0;
BillboardNormal = TransformWorldToObject(mul(rotationMatrix, tempNormal).xyz);
BillboardTangent = TransformWorldToObject(mul(rotationMatrix, tempTangent).xyz);",
new ParameterDescriptor[]
{
new ParameterDescriptor("Scale", TYPE.Vec3, GraphType.Usage.Local),
new ParameterDescriptor("temp", TYPE.Vec3, GraphType.Usage.Local, new float[] {1f, 1f, 1f }),
new ParameterDescriptor("UpDir", TYPE.Vec4, GraphType.Usage.Local, new float[] {0f, 1f, 0f, 0f }),
new ParameterDescriptor("tempNormal", TYPE.Vec4, GraphType.Usage.Local),
new ParameterDescriptor("tempTangent", TYPE.Vec4, GraphType.Usage.Local),
new ParameterDescriptor("rotationMatrix", TYPE.Mat4, GraphType.Usage.Local),
new ParameterDescriptor("Scaled_Pos", TYPE.Vec4, GraphType.Usage.Local),
new ParameterDescriptor("Position", TYPE.Vec3, GraphType.Usage.In, REF.ObjectSpace_Position),
new ParameterDescriptor("Normal", TYPE.Vec3, GraphType.Usage.In, REF.ObjectSpace_Normal),
new ParameterDescriptor("Tangent", TYPE.Vec3, GraphType.Usage.In, REF.ObjectSpace_Tangent),
new ParameterDescriptor("PivotOffset", TYPE.Vec3, GraphType.Usage.In, new float[] {0f, .5f, 0f }),
new ParameterDescriptor("BillboardPosition", TYPE.Vec3, GraphType.Usage.Out),
new ParameterDescriptor("BillboardNormal", TYPE.Vec3, GraphType.Usage.Out),
new ParameterDescriptor("BillboardTangent", TYPE.Vec3, GraphType.Usage.Out)
}
)
}
);
public static NodeUIDescriptor NodeUIDescriptor => new(
Version,
Name,
displayName: "Billboard",
tooltip: "Rotates the vertex posiiton, normal, and tangent to align all three axes with the camera or only the x and z axes.",
category: "Input/Mesh Deformation",
hasPreview: false,
description: "pkg://Documentation~/previews/Billboard.md",
synonyms: new string[] { "align, facing, rotate, pivot" },
selectableFunctions: new()
{
{ "Spherical", "Spherical" },
{ "Cylindrical", "Cylindrical" }
},
functionSelectorLabel: "Mode",
parameters: new ParameterUIDescriptor[] {
new ParameterUIDescriptor(
name: "Position",
tooltip: "The input vertex postion"
),
new ParameterUIDescriptor(
name: "Normal",
tooltip: "The input vertex Normal"
),
new ParameterUIDescriptor(
name: "Tangent",
tooltip: "The input vertex Tangent"
),
new ParameterUIDescriptor(
name: "PivotOffset",
displayName:"Pivot Offset",
tooltip: "The value to offset the object piviot point"
),
new ParameterUIDescriptor(
name: "BillboardPosition",
displayName:"Billboard Position",
tooltip: "The billboard vertex position"
),
new ParameterUIDescriptor(
name: "BillboardNormal",
displayName:"Billboard Normal",
tooltip: "The billboard vertex normal"
),
new ParameterUIDescriptor(
name: "BillboardTangent",
displayName:"Billboard Tangent",
tooltip: "The billboard vertex tangent"
)
}
);
}
}