-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderiveZ.gd
80 lines (60 loc) · 1.64 KB
/
deriveZ.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
# This node was created by Foyezes
# x.com/Foyezes
# bsky.app/profile/foyezes.bsky.social
@tool
extends VisualShaderNodeCustom
class_name VisualShaderNodeDeriveZ
func _get_name():
return "DeriveZ"
func _get_category():
return "Color"
func _get_description():
return "Get the Z channel of a normal map from X & Y channels"
func _get_output_port_count():
return 1
func _get_input_port_count():
return 2
func _get_return_icon_type():
return VisualShaderNode.PORT_TYPE_VECTOR_3D
func _get_output_port_name(port):
return "result"
func _get_output_port_type(port):
return VisualShaderNode.PORT_TYPE_VECTOR_3D
func _get_input_port_name(port):
match port:
0:
return "x"
1:
return "y"
func _get_input_port_type(port):
match port:
0:
return VisualShaderNode.PORT_TYPE_SCALAR
1:
return VisualShaderNode.PORT_TYPE_SCALAR
func _get_property_count():
return 1
func _get_property_name(index):
match index:
0:
return "Normalized"
func _get_property_options(index):
match index:
0:
return ["No(Default)", "Yes"]
func _get_global_code(mode):
return """
vec3 deriveZ(float x_in, float y_in){
vec2 normalXY = vec2(x_in * 2.0 - 1.0, y_in * 2.0 - 1.0);
float z = sqrt(max(1.0 - dot(normalXY, normalXY), 0.0));
vec3 normal = vec3(normalXY.x, normalXY.y, z);
return normal;
}
"""
func _get_code(input_vars, output_vars, mode, type):
var normalize = get_option_index(0)
match normalize:
0:
return output_vars[0] + "=deriveZ(%s, %s) * 0.5 + 0.5;" % [input_vars[0], input_vars[1]]
1:
return output_vars[0] + "=normalize(deriveZ(%s, %s)) * 0.5 + 0.5;" % [input_vars[0], input_vars[1]]