-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnormalCombine.gd
130 lines (109 loc) · 2.98 KB
/
normalCombine.gd
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
# This node was created by Foyezes
# x.com/Foyezes
# bsky.app/profile/foyezes.bsky.social
@tool
extends VisualShaderNodeCustom
class_name VisualShaderNodeNormalCombine
func _get_name():
return "NormalCombine"
func _get_category():
return "Color"
func _get_description():
return "Combine normal maps"
func _get_output_port_count():
return 1
func _get_return_icon_type():
return VisualShaderNode.PORT_TYPE_VECTOR_3D
func _get_output_port_type(port):
return VisualShaderNode.PORT_TYPE_VECTOR_3D
func _get_output_port_name(port):
return ""
func _get_input_port_count():
return 2
func _get_input_port_name(port):
match port:
0:
return "Normal 1"
1:
return "Normal 2"
func _get_input_port_type(port):
match port:
0:
return VisualShaderNode.PORT_TYPE_VECTOR_3D
1:
return VisualShaderNode.PORT_TYPE_VECTOR_3D
func _get_property_count():
return 2
func _get_property_name(index):
match index:
0:
return "Method"
1:
return "Normalized"
func _get_property_options(index):
match index:
0:
return ["UDN(Fastest)", "Whiteout(Fast)", "RNM(Slow)", "Unity(Slowest)"]
1:
return ["Yes(Default)", "No"]
func _get_propert_default_index(index):
match index:
0:
return 0
1:
return 0
func _get_global_code(mode):
var method = get_option_index(0)
match method:
0:
return """
vec3 UDN(vec3 n1, vec3 n2){
return vec3(n1.rg + ((n2.rg - 0.5)), n1.z);
}
"""
1:
return """
vec3 whiteout(vec3 n1, vec3 n2){
return vec3(n1.rg + ((n2.rg - 0.5)), n1.z * n2.z);
}
"""
2:
return """
vec3 RNM(vec3 n1_in, vec3 n2_in){
vec3 n1 = n1_in * vec3(2, 2, 2) + vec3(-1, -1, 0);
vec3 n2 = n2_in * vec3(-2, -2, 2) + vec3(1, 1, -1);
return vec3(n1 * dot(n1, n2) / n1.z - n2) * 0.5 + 0.5;
}
"""
3:
return """
vec3 unity(vec3 n1_in, vec3 n2_in){
vec3 n1 = n1_in * 2.0 - 1.0;
vec3 n2 = n2_in * 2.0 - 1.0;
mat3 nBasis = mat3(
vec3(n1.z, n1.y, -n1.x),
vec3(n1.x, n1.z, -n1.y),
vec3(n1.x, n1.y, n1.z));
return vec3(n2.x * nBasis[0] + n2.y * nBasis[1] + n2.z * nBasis[2]) * 0.5 + 0.5;
}
"""
func _get_code(input_vars, output_vars, mode, type):
var method = get_option_index(0)
var normalized = get_option_index(1)
match [method, normalized]:
[0, 1]:
return output_vars[0] + "=UDN(%s, %s);" % [input_vars[0], input_vars[1]]
[0, 0]:
return output_vars[0] + "=normalize(UDN(%s, %s));" % [input_vars[0], input_vars[1]]
[1, 1]:
return output_vars[0] + "=whiteout(%s, %s);" % [input_vars[0], input_vars[1]]
[1, 0]:
return output_vars[0] + "=normalize(whiteout(%s, %s));" % [input_vars[0], input_vars[1]]
[2, 1]:
return output_vars[0] + "=RNM(%s, %s);" % [input_vars[0], input_vars[1]]
[2, 0]:
return output_vars[0] + "=normalize(RNM(%s, %s));" % [input_vars[0], input_vars[1]]
[3, 1]:
return output_vars[0] + "=unity(%s, %s);" % [input_vars[0], input_vars[1]]
[3, 0]:
return output_vars[0] + "=normalize(unity(%s, %s));" % [input_vars[0], input_vars[1]]