-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheightBlend.gd
88 lines (71 loc) · 1.97 KB
/
heightBlend.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
# This node was created by Foyezes
# x.com/Foyezes
# bsky.app/profile/foyezes.bsky.social
@tool
extends VisualShaderNodeCustom
class_name VisualShaderNodeBlend2
func _get_name():
return "HeightBlend"
func _get_category():
return "Color"
func _get_description():
return "Blend between two heightmaps or use a single heightmap with a mask"
func _get_return_icon_type():
return VisualShaderNode.PORT_TYPE_SCALAR
func _get_input_port_count():
return 5
func _get_output_port_count():
return 1
func _get_output_port_name(port):
return ""
func _get_output_port_type(port):
return VisualShaderNode.PORT_TYPE_SCALAR
func _get_input_port_type(port):
match port:
0:
return VisualShaderNode.PORT_TYPE_SCALAR
1:
return VisualShaderNode.PORT_TYPE_SCALAR
2:
return VisualShaderNode.PORT_TYPE_SCALAR
3:
return VisualShaderNode.PORT_TYPE_SCALAR
4:
return VisualShaderNode.PORT_TYPE_SCALAR
func _get_input_port_default_value(port):
match port:
1:
return 0.5
2:
return 1.0
3:
return 0.2
4:
return 1.0
func _get_input_port_name(port):
match port:
0:
return "Height 1"
1:
return "Height 2"
2:
return "Contrast"
3:
return "Height Offset"
4:
return "Mask"
func _get_global_code(mode):
return """
float heightBlend(float height1_placeholder, float height2_placeholder, float contrast_placeholder, float height_offset_in_placeholder, float mask_placeholder){
float add1 = height1_placeholder + height_offset_in_placeholder;
float subtract1 = height2_placeholder - height_offset_in_placeholder;
float add2 = subtract1 + mask_placeholder;
float max1 = max(add1, add2);
float subtract2 = max1 - add1;
float multiply1 = subtract2 * contrast_placeholder;
float result = clamp(multiply1, 0.0, 1.0);
return result;
}
"""
func _get_code(input_vars, output_vars, mode, type):
return output_vars[0] + "= heightBlend(%s, %s, %s, %s, %s);" % [input_vars[0], input_vars[1], input_vars[2], input_vars[3], input_vars[4]]