Skip to content

Commit b9d5f5c

Browse files
committed
improve shader, move line2ds to its own node
1 parent e8604a1 commit b9d5f5c

6 files changed

Lines changed: 46 additions & 35 deletions

File tree

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://duk4r6tejiina"]
1+
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://cebf5h3c4353j"]
22

33
[sub_resource type="Shader" id="Shader_pewh7"]
44
code = "shader_type canvas_item;
5-
uniform vec3 dash_color : source_color = vec3(1.0);
65

76
void fragment() {
87
float f = smoothstep(0.0,0.5,abs(fract(UV.x*0.25-TIME)-0.5));
9-
f = max(f, 0.5);
10-
COLOR = vec4(vec3(f)*dash_color, 1.0);
8+
COLOR = vec4(vec3(0.0), f*0.5);
119
}
1210
"
1311

1412
[resource]
1513
shader = SubResource("Shader_pewh7")
16-
shader_parameter/dash_color = Color(1, 1, 1, 1)

material_maker/panels/graph_edit/graph_edit.gd

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func get_padded_node_rect(graph_node:GraphNode) -> Rect2:
313313
func _draw() -> void:
314314
if drag_cut_line.size() > 1:
315315
draw_polyline(drag_cut_line, get_theme_color("connection_knife", "GraphEdit"), 1.0)
316-
draw_active_overlays()
316+
$HighlightsOverlay.queue_redraw()
317317

318318

319319
# Misc. useful functions
@@ -1270,7 +1270,6 @@ func undoredo_command(command : Dictionary) -> void:
12701270
get_node("node_"+k).do_set_position(command.positions[k])
12711271
else:
12721272
parent_generator.get_node(k).set_position(command.positions[k])
1273-
draw_active_overlays.call_deferred()
12741273
"resize_comment":
12751274
var g = get_node_from_hier_name(command.node)
12761275
g.size = command.size
@@ -1288,6 +1287,7 @@ func undoredo_command(command : Dictionary) -> void:
12881287
_:
12891288
print("Unknown undo/redo command:")
12901289
print(command)
1290+
$HighlightsOverlay.queue_redraw.call_deferred()
12911291

12921292
func undoredo_move_node(node_name : String, old_pos : Vector2, new_pos : Vector2):
12931293
if old_pos == new_pos:
@@ -1765,32 +1765,6 @@ func color_comment_nodes() -> void:
17651765
picker.popup_hide.connect(undoredo.end_group)
17661766
picker.popup()
17671767

1768-
func draw_active_overlays() -> void:
1769-
for node in get_children():
1770-
if node is Line2D:
1771-
remove_child(node)
1772-
node.free()
1773-
if active_connections.size() and should_draw_active_overlays:
1774-
for line in active_connections:
1775-
if has_node(NodePath(line.to_node)) and has_node(NodePath(line.to_node)):
1776-
var from_node : GraphNode = get_node(NodePath(line.from_node))
1777-
var to_node : GraphNode = get_node(NodePath(line.to_node))
1778-
if from_node and to_node:
1779-
var from_pos : Vector2 = from_node.get_output_port_position(line.from_port)*zoom + from_node.position
1780-
var to_pos : Vector2 = to_node.get_input_port_position(line.to_port)*zoom + to_node.position
1781-
var line2d : Line2D = Line2D.new()
1782-
if get_viewport_rect().has_point(from_pos) or get_viewport_rect().has_point(to_pos):
1783-
var lm : ShaderMaterial = load("res://material_maker/panels/graph_edit/active_connection_overlay.tres")
1784-
line2d.texture_mode = Line2D.LINE_TEXTURE_TILE
1785-
line2d.material = lm.duplicate(true)
1786-
line2d.material.set_shader_parameter("dash_color", to_node.get_input_port_color(line.to_port))
1787-
line2d.points = _get_connection_line(from_pos, to_pos)
1788-
line2d.width = connection_lines_thickness
1789-
line2d.round_precision = 4
1790-
line2d.begin_cap_mode = Line2D.LINE_CAP_ROUND
1791-
line2d.end_cap_mode = Line2D.LINE_CAP_ROUND
1792-
add_child(line2d)
1793-
17941768
func _on_connection_drag_started(_from_node: StringName, _from_port: int, _is_output: bool) -> void:
17951769
active_connections.clear()
17961770
should_draw_active_overlays = false

material_maker/panels/graph_edit/graph_edit.tscn

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
[gd_scene load_steps=8 format=3 uid="uid://dy1u50we7gtru"]
1+
[gd_scene load_steps=9 format=3 uid="uid://dy1u50we7gtru"]
22

33
[ext_resource type="Script" uid="uid://dkp4w3at1o6cm" path="res://material_maker/panels/graph_edit/graph_edit.gd" id="1"]
44
[ext_resource type="Texture2D" uid="uid://c0j4px4n72di5" path="res://material_maker/icons/icons.tres" id="2"]
55
[ext_resource type="Script" uid="uid://bne3k0g56crmy" path="res://material_maker/tools/undo_redo/undo_redo.gd" id="3"]
66
[ext_resource type="PackedScene" uid="uid://buj231c2gxm4o" path="res://material_maker/widgets/desc_button/desc_button.tscn" id="4"]
7+
[ext_resource type="Script" uid="uid://dlah77kjy12l6" path="res://material_maker/panels/graph_edit/highlights_overlay.gd" id="5_u5byk"]
78

89
[sub_resource type="AtlasTexture" id="3"]
910
atlas = ExtResource("2")
@@ -85,6 +86,12 @@ layout_mode = 2
8586
[node name="UndoRedo" type="Node" parent="."]
8687
script = ExtResource("3")
8788

89+
[node name="HighlightsOverlay" type="Control" parent="."]
90+
anchors_preset = 0
91+
offset_right = 40.0
92+
offset_bottom = 40.0
93+
script = ExtResource("5_u5byk")
94+
8895
[connection signal="begin_node_move" from="." to="." method="_on_begin_node_move"]
8996
[connection signal="connection_drag_ended" from="." to="." method="_on_connection_drag_ended"]
9097
[connection signal="connection_drag_started" from="." to="." method="_on_connection_drag_started"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
extends Control
2+
3+
func _ready() -> void:
4+
owner.child_order_changed.connect(_move_above_connections.call_deferred)
5+
6+
func _move_above_connections() -> void:
7+
owner.move_child(self, owner.get_node("_connection_layer").get_index()+1)
8+
9+
func _draw() -> void:
10+
var zoom : float = owner.zoom
11+
for node in get_children():
12+
if node is Line2D:
13+
remove_child(node)
14+
node.free()
15+
if owner.active_connections.size() and owner.should_draw_active_overlays:
16+
for line in owner.active_connections:
17+
if owner.has_node(NodePath(line.to_node)) and owner.has_node(NodePath(line.to_node)):
18+
var from_node : GraphNode = owner.get_node(NodePath(line.from_node))
19+
var to_node : GraphNode = owner.get_node(NodePath(line.to_node))
20+
if from_node and to_node:
21+
var from_pos := from_node.get_output_port_position(line.from_port)*zoom + from_node.position
22+
var to_pos := to_node.get_input_port_position(line.to_port)*zoom + to_node.position
23+
var line2d : Line2D = Line2D.new()
24+
if get_viewport_rect().has_point(from_pos) or get_viewport_rect().has_point(to_pos):
25+
line2d.texture_mode = Line2D.LINE_TEXTURE_TILE
26+
line2d.material = load("res://material_maker/panels/graph_edit/active_connection_overlay.tres")
27+
line2d.points = owner._get_connection_line(from_pos, to_pos)
28+
line2d.width = owner.connection_lines_thickness
29+
line2d.round_precision = 4
30+
line2d.begin_cap_mode = Line2D.LINE_CAP_ROUND
31+
line2d.end_cap_mode = Line2D.LINE_CAP_ROUND
32+
add_child(line2d)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://dlah77kjy12l6

parse_args.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[gd_scene load_steps=3 format=3 uid="uid://bwfnpjyf1wqiu"]
22

33
[ext_resource type="Script" uid="uid://bcslbmkx1lijb" path="res://parse_args.gd" id="1_or0h6"]
4-
[ext_resource type="Material" uid="uid://duk4r6tejiina" path="res://material_maker/panels/graph_edit/active_connection_overlay.tres" id="2_ai1me"]
4+
[ext_resource type="Material" uid="uid://cebf5h3c4353j" path="res://material_maker/panels/graph_edit/active_connection_overlay.tres" id="2_ai1me"]
55

66
[node name="ParseArgs" type="Node"]
77
script = ExtResource("1_or0h6")

0 commit comments

Comments
 (0)