diff --git a/project.godot b/project.godot index adcd28a6..6b9a086a 100644 --- a/project.godot +++ b/project.godot @@ -197,7 +197,7 @@ quality/driver/fallback_to_gles2=true [shader_globals] -ticks_msec={ +tick_curent={ "type": "int", "value": 0 } diff --git a/scenes/bip/bip.gd b/scenes/bip/bip.gd index b4594e05..20affa3a 100644 --- a/scenes/bip/bip.gd +++ b/scenes/bip/bip.gd @@ -10,15 +10,8 @@ func set_track_visible(value: bool): $track.visible = value func set_ecm_visible(value: bool): $ecm_done.visible = value -func update(_tick_ms: int = 0): pass - - -## Задаёт цвет -func set_color(color: Color): $bip.self_modulate = color - - -## Возвращает цвет -func get_color(): return $bip.self_modulate +func update(tick_rx: int): + $bip.set_instance_shader_parameter('tick_update', tick_rx) ## Функция присваивает заданое значение видимости селектору. diff --git a/scenes/bip/bip.tscn b/scenes/bip/bip.tscn index 7bdc8775..5ccfa85a 100644 --- a/scenes/bip/bip.tscn +++ b/scenes/bip/bip.tscn @@ -6,8 +6,8 @@ [sub_resource type="ShaderMaterial" id="ShaderMaterial_qq6yq"] shader = ExtResource("2_ybnsn") -shader_parameter/tick_update = 0 -shader_parameter/time_delta = 200 +shader_parameter/tick_delta = 200 +shader_parameter/radius = 0.06 [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_xbpqf"] @@ -231,19 +231,21 @@ scale = Vector2(20, 20) texture = SubResource("PlaceholderTexture2D_xbpqf") [node name="selector" type="Sprite2D" parent="."] +visible = false material = SubResource("ShaderMaterial_fkqwb") scale = Vector2(20, 20) texture = SubResource("PlaceholderTexture2D_hqs6j") centered = false [node name="recomendation" type="Sprite2D" parent="."] +visible = false material = SubResource("ShaderMaterial_lpmq6") scale = Vector2(20, 20) texture = SubResource("PlaceholderTexture2D_hqs6j") centered = false -metadata/_edit_lock_ = true [node name="ecm_done" type="Sprite2D" parent="."] +visible = false material = SubResource("ShaderMaterial_h3oo7") position = Vector2(-5, -5) scale = Vector2(30, 30) @@ -251,6 +253,7 @@ texture = SubResource("PlaceholderTexture2D_hqs6j") centered = false [node name="track" type="Sprite2D" parent="."] +visible = false material = SubResource("ShaderMaterial_lkrha") position = Vector2(10, 10) scale = Vector2(26, 26) diff --git a/scenes/работа/работа.gd b/scenes/работа/работа.gd index 42067e4a..57f98229 100644 --- a/scenes/работа/работа.gd +++ b/scenes/работа/работа.gd @@ -162,7 +162,7 @@ func map_threat_to_bip(th: threats.Threat, bip: Control): ## Обработчик сигнала обновления цели. func on_threat_update(th): var bip = get_node('%d' % th.id) - bip.update() + bip.update(th.tick_rx) map_threat_to_bip(th, bip) diff --git a/scripts/network.gd b/scripts/network.gd index 4499294c..4a58a300 100644 --- a/scripts/network.gd +++ b/scripts/network.gd @@ -250,7 +250,7 @@ func get_tcp_data(sock: SocketTCP, peer, len_rx): func _process(_delta: float) -> void: tick = Time.get_ticks_msec() - RenderingServer.global_shader_parameter_set('ticks_msec', tick) + RenderingServer.global_shader_parameter_set('tick_curent', tick) for addr in units_udp: var unit = units[addr] match unit.process(tick): diff --git a/shaders/bip.gdshader b/shaders/bip.gdshader index 217ceae7..a58c0fa0 100644 --- a/shaders/bip.gdshader +++ b/shaders/bip.gdshader @@ -2,23 +2,19 @@ shader_type canvas_item; #include "res://shaders/tools.gdshaderinc" +global uniform int tick_curent; + /* Закрашенная окружность */ -uniform int tick_update = 0; /* Время последнего обновления, мс */ -uniform int time_delta = 200; /* Время вспышки при обновлении, мc */ -const float ds = 0.01; /* Относительное расстояние на котором выполняется сглаживание краёв */ +instance uniform int tick_update = 1000; /* Время последнего обновления, мс */ +uniform int tick_delta = 200; /* Время вспышки при обновлении, мc */ +uniform float radius = 0.060; /* Радиус */ +const float ds = 0.010; /* Относительное расстояние на котором выполняется сглаживание краёв */ const vec2 center = vec2(0.125, 0.125); /* Центр должен быть в (0.5, 0.5), но это не так */ -const float radius = 0.075 - ds * 2.0; /* Радиус должен быть 0.5, но это не так */ -const float alpha_offset = 0.5; /* Изменние скорости альфа канала */ -const float alpha_main = 1.0; -global uniform int ticks_msec; + void fragment() { - float alpha = alpha_offset; - if ((ticks_msec - tick_update) < time_delta) - { - alpha = alpha_main; - } - COLOR = texture(TEXTURE, UV); - COLOR.a = (alpha_main - alpha) * smooth_px(length(UV - center), radius, ds); + COLOR = vec4(1, 1, 1, 1); + COLOR.a = 1.5 - smoothstep(float(tick_update), float(tick_update + tick_delta), float(tick_curent)); + COLOR.a *= smooth_px(length(UV - center), radius + (COLOR.a - 0.5) / 20.0, ds); }