/
AlphaIntensity.cs
155 lines (122 loc) · 4.31 KB
/
AlphaIntensity.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using UnityEngine;
using System.IO;
using System.Collections;
using _ShaderoShaderEditorFramework;
using _ShaderoShaderEditorFramework.Utilities;
namespace _ShaderoShaderEditorFramework
{
[Node(false, "RGBA/Alpha/Alpha Intensity")]
public class AlphaIntensity : Node
{
[HideInInspector]
public const string ID = "AlphaIntensity";
[HideInInspector]
public override string GetID { get { return ID; } }
[HideInInspector]
public bool parametersOK = true;
[HideInInspector]
public float Variable = 1;
[HideInInspector]
public float InternalCount = -1;
public static int count = 1;
public static bool tag = false;
public static string code;
public static void Init()
{
tag = false;
count = 1;
}
public void Function()
{
code = "";
code = "\n";
code += "float4 AlphaIntensity(float4 txt,float fade)\n";
code += "{\n";
code += "if (txt.a < 1) txt.a = txt.a*fade;\n";
code += "return txt;\n";
code += "}\n";
code += "\n";
}
public override Node Create(Vector2 pos)
{
Function();
InternalCount = -1;
AlphaIntensity node = ScriptableObject.CreateInstance<AlphaIntensity>();
node.name = "Alpha Intensity";
node.rect = new Rect(pos.x, pos.y, 172, 240);
node.CreateInput("RGBA", "SuperFloat4");
node.CreateOutput("RGBA", "SuperFloat4");
return node;
}
protected internal override void NodeGUI()
{
Texture2D preview = ResourceManager.LoadTexture("Textures/previews/nid_alphaintensity.jpg");
GUI.DrawTexture(new Rect(2, 0, 172, 46), preview);
GUILayout.Space(50);
GUILayout.BeginHorizontal();
Inputs[0].DisplayLayout(new GUIContent("RGBA", "RGBA"));
Outputs[0].DisplayLayout(new GUIContent("RGBA", "RGBA"));
GUILayout.EndHorizontal();
parametersOK = GUILayout.Toggle(parametersOK, "Add Parameter");
if (NodeEditor._Shadero_Material != null)
{
NodeEditor._Shadero_Material.SetFloat(FinalVariable, Variable);
}
if (GUILayout.Button("Reset"))
{
Variable = 1;
}
if (GUILayout.Button("Set To Zero"))
{
Variable = 0;
}
GUILayout.Label("Fading: (0 to 6) " + Variable.ToString("0.00"));
Variable =HorizontalSlider(Variable, 0, 5);
}
private string FinalVariable;
[HideInInspector]
public int MemoCount = -1;
public override bool FixCalculate()
{
MemoCount = count;
count++;
return true;
}
public override bool Calculate()
{
tag = true;
SuperFloat4 s_in = Inputs[0].GetValue<SuperFloat4>();
SuperFloat4 s_out = new SuperFloat4();
string NodeCount = MemoCount.ToString();
string DefautTypeFade = "float";
string DefaultName = "AlphaIntensity_" + NodeCount;
string DefaultNameVariable1 = "_AlphaIntensity_Fade_" + NodeCount;
string DefaultParameters1 = ", Range(0, 6)) = " + Variable.ToString();
string VoidName = "AlphaIntensity";
string Value1 = Variable.ToString();
string PreviewVariable = s_in.Result;
FinalVariable = DefaultNameVariable1;
if (s_in.Result == null)
{
PreviewVariable = "float4(0,0,0,1)";
}
s_out.StringPreviewLines = s_in.StringPreviewNew;
if (parametersOK)
{
s_out.ValueLine = "float4 " + DefaultName + " = " + VoidName + "(" + PreviewVariable + "," + DefaultNameVariable1 + ");\n";
}
else
{
s_out.ValueLine = "float4 " + DefaultName + " = " + VoidName + "(" + PreviewVariable + "," + Value1 + ");\n";
}
s_out.StringPreviewNew = s_out.StringPreviewLines + s_out.ValueLine;
s_out.Result = DefaultName;
s_out.ParametersLines += s_in.ParametersLines;
s_out.ParametersDeclarationLines += s_in.ParametersDeclarationLines;
if (parametersOK) s_out.ParametersLines += DefaultNameVariable1 + "(\"" + DefaultNameVariable1 + "\"" + DefaultParameters1 + "\n";
if (parametersOK) s_out.ParametersDeclarationLines += DefautTypeFade + " " + DefaultNameVariable1 + ";\n";
Outputs[0].SetValue<SuperFloat4>(s_out);
return true;
}
}
}