-
Notifications
You must be signed in to change notification settings - Fork 0
/
VariableStruct.cs
71 lines (57 loc) · 2.05 KB
/
VariableStruct.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ShaderComposer.Interface.Designer;
using ShaderComposer.Interface.Designer.Variables;
namespace ShaderComposer.Compilers
{
class VariableStruct
{
// Parent node
private Node node;
public Dictionary<Variable, string> dictonaryVariableIdentifiers = new Dictionary<Variable, string>();
public VariableStruct(Node node, Variable.VariableType variableType)
{
this.node = node;
// Create the identifier
Identifier = "s" + getUniqueID();
// Create the hlsl description
HLSLDescription = "struct " + Identifier + " {\n";
foreach (Variable variable in node.Variables)
{
if (variable.Type == variableType)
{
string variableIdentifier = "v" + getUniqueID();
dictonaryVariableIdentifiers[variable] = variableIdentifier;
HLSLDescription += "\t" + determineTypeIdentifier(variable) + " " + variableIdentifier + ";\n";
}
}
HLSLDescription += "};\n\n";
}
// Provides unique id's
private int getUniqueID()
{
return uniqueID++;
}
private static int uniqueID = 0;
// Struct identifier
public string Identifier { get; private set; }
// HLSL description
public string HLSLDescription { get; private set; }
// Determine the variable type
private string determineTypeIdentifier(Variable variable)
{
if (variable.IsFloat4())
return "float4";
else if (variable.IsFloat3())
return "float3";
else if (variable.IsFloat2())
return "float2";
else if (variable.IsFloat1())
return "float";
else
return "float4";
}
}
}