From 87f41b7014e121c1d3abfa6e5b4dc470b719c689 Mon Sep 17 00:00:00 2001 From: sasha80 Date: Wed, 19 Feb 2025 13:27:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0.=20=D0=A6=D0=B2=D0=B5=D1=82=20=D0=BE=D1=82=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BA=D0=B8=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B2=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scenes/bip/bip.gd | 4 ++++ scenes/bip/bip.tscn | 2 ++ shaders/bip.gdshader | 12 ++++-------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/scenes/bip/bip.gd b/scenes/bip/bip.gd index a7138eb..9ff16ce 100644 --- a/scenes/bip/bip.gd +++ b/scenes/bip/bip.gd @@ -13,6 +13,10 @@ func set_ecm_visible(value: bool): $ecm_done.visible = value func update(): $bip.material.set('shader_parameter/tick_update', float(Time.get_ticks_msec()/1000)) +## Задаёт цвет +func set_color(color: Color): $bip.material.set('shader_parameter/color', Vector3(color.r, color.g, color.b)) + + ## Функция присваивает заданое значение видимости селектору. func set_sel_visible(value: bool): selected = value diff --git a/scenes/bip/bip.tscn b/scenes/bip/bip.tscn index c296aff..861cc7f 100644 --- a/scenes/bip/bip.tscn +++ b/scenes/bip/bip.tscn @@ -7,6 +7,7 @@ [sub_resource type="ShaderMaterial" id="ShaderMaterial_2dulj"] shader = ExtResource("2_rt0la") shader_parameter/tick_update = 0.0 +shader_parameter/color = Color(0.972549, 0.12549, 0.411765, 1) [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_w5pye"] @@ -233,6 +234,7 @@ layout_mode = 0 offset_right = 1.0 offset_bottom = 1.0 scale = Vector2(20, 20) +action_mode = 0 button_mask = 3 texture_normal = SubResource("PlaceholderTexture2D_w5pye") stretch_mode = 3 diff --git a/shaders/bip.gdshader b/shaders/bip.gdshader index 17eb231..b617d0f 100644 --- a/shaders/bip.gdshader +++ b/shaders/bip.gdshader @@ -4,9 +4,7 @@ shader_type canvas_item; /* Закрашенная окружность */ uniform float tick_update = 0.0; /* Время последнего обновления, мс */ -const float red_channel = 0.972549; -const float green_channel = 0.12549; -const float blue_channel = 0.411765; +uniform vec3 color : source_color = vec3(0.972549, 0.12549, 0.411765); const float time_delta = 0.5; /* Время вспышки при обновлении, c */ const float ds = 0.01; /* Относительное расстояние на котором выполняется сглаживание краёв */ const vec2 center = vec2(0.125, 0.125); /* Центр должен быть в (0.5, 0.5), но это не так */ @@ -16,12 +14,10 @@ const float alpha_main = 1.0; void fragment() { - float time_now = TIME; float alpha = 0.0; - if ((time_now - tick_update) < time_delta) + if ((TIME - tick_update) < time_delta) { - alpha = time_delta - (time_now - tick_update) * alpha_offset; + alpha = time_delta - (TIME - tick_update) * alpha_offset; } - vec4 color = vec4(red_channel, green_channel, blue_channel, alpha_main - alpha); - COLOR = color * smooth_px(length(UV - center), radius, ds); + COLOR = vec4(color, alpha_main - alpha) * smooth_px(length(UV - center), radius, ds); }