[gd_scene load_steps=14 format=3 uid="uid://nl1vklubr5kr"]

[ext_resource type="Script" uid="uid://y4l1v8eqayr0" path="res://scenes/bip/bip.gd" id="1_h7l70"]
[ext_resource type="Shader" uid="uid://n6xe6w76iw3v" path="res://shaders/bip.gdshader" id="2_ybnsn"]
[ext_resource type="Shader" uid="uid://da53rd1r7al8l" path="res://shaders/tracked.gdshader" id="3_2a1qb"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_qq6yq"]
shader = ExtResource("2_ybnsn")
shader_parameter/tick_delta = 200

[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_xbpqf"]

[sub_resource type="Shader" id="Shader_60ho7"]
code = "shader_type canvas_item;

uniform vec4 color: source_color = vec4(1, 1, 1, 1);
uniform vec4 color_up: source_color = vec4(1, 1, 1, 1); /* Цвет вспышки при обновлении */
const float ds = 0.01;                                  /* Относительное расстояние на котором выполняется сглаживание краёв */
const float dsr = 10.0; 
const vec2 center = vec2(0.5, 0.5);                 /* Центр должен быть в (0.5, 0.5), но это не так */
const float radius = 0.075 - ds * 2.0;                  /* Радиус должен быть 0.5, но это не так */

uniform float speed:  hint_range(-1024.0, 1024.0) = 0.0;                           /* Время вспышки при обновлении, c */
uniform int ant_band_count_0 = 3;

const float ant_band_r0_0 = 0.27

;

const float ant_band_r1_0 = 0.47;

float smooth_px(float r, float R, float dss)
{
	return 1.0 - smoothstep(R - dss, R + dss, r);
}

void sector(inout vec4 c, vec2 uv, vec2 cnt, float a, float da, float r0, float r1, vec4 col)
{
	float l = distance(cnt, uv);
	vec2 d = uv - cnt;
	float sf = 500.0;
	float theta = atan(d.x, d.y) * sf;
	da /= 2.0;
	float a0 = radians(a - da);
	float a1 = radians(a + da);
	float va = smooth_px(a0 * sf, theta, dsr) - smooth_px(a1 * sf, theta, dsr);
	float vr = smooth_px(r0, l, ds) - smooth_px(r1, l, ds);
    float rgb = sqrt(va * vr);
	c.rgb += col.rgb * rgb * col.a;
    c.a += rgb * col.a;
}


void antenas(inout vec4 c, vec2 uv, vec2 p0, int cnt, float r0, float r1, vec4 c0, vec4 c1)
{
	float da = 180.0f / float(cnt);
    for (int i = -cnt; i <= cnt; i ++)
	{
		float v = float(i & 1);
		vec4 col = v * c0 + (1.0f - v) * c1;
		sector(c, uv, p0, float(i) * da, da, r0, r1, col);
	}
}

vec2 rotateUVmatrinx(vec2 uv, vec2 pivot, float rotation)
{
    mat2 rotation_matrix=mat2(  vec2(sin(rotation),-cos(rotation)),
                                vec2(cos(rotation),sin(rotation))
                                );
    uv -= pivot;
    uv *= rotation_matrix;
    uv += pivot;
    return uv;
}


void vertex()
{   
    float dir = 0.0;
    dir += speed * TIME;
    VERTEX = rotateUVmatrinx(VERTEX, center, radians(dir));
}



void fragment()
{
    
    ivec2 isz = textureSize(TEXTURE, 0);
    vec2 uv = UV * vec2(float(isz.x), float(isz.y));     // координаты текущей точки в пикселях
    COLOR = vec4(0, 0, 0, 0.0); //texture(TEXTURE, UV);  // Цвет текущей точки

    // Сетка антенн
    antenas(COLOR, uv, center, ant_band_count_0, ant_band_r0_0, ant_band_r1_0, color, color_up);
}
"

[sub_resource type="ShaderMaterial" id="ShaderMaterial_fkqwb"]
shader = SubResource("Shader_60ho7")
shader_parameter/color = Color(1, 1, 1, 0.968627)
shader_parameter/color_up = Color(1, 1, 1, 0)
shader_parameter/speed = -118.48
shader_parameter/ant_band_count_0 = 3

[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_hqs6j"]

[sub_resource type="Shader" id="Shader_81bae"]
code = "shader_type canvas_item;

uniform vec4 color: source_color = vec4(1, 1, 1, 1);
uniform vec4 color_up: source_color = vec4(1, 1, 1, 1); /* Цвет вспышки при обновлении */
const float ds = 0.01425;                                  /* Относительное расстояние на котором выполняется сглаживание краёв */
const float dsr = 12.125; 
const vec2 center = vec2(0.5, 0.5);                 /* Центр должен быть в (0.5, 0.5), но это не так */
const float radius = 0.075 - ds * 2.0;                  /* Радиус должен быть 0.5, но это не так */

uniform float speed:  hint_range(0.0, 1024.0) = 0.0;                           /* Время вспышки при обновлении, c */
uniform int ant_band_count_0 = 3;

uniform float ant_band_r0_0 = 0.3;

uniform float ant_band_r1_0 = 0.4;

float smooth_px(float r, float R, float dss)
{
	return 1.0 - smoothstep(R - dss, R + dss, r);
}

void sector(inout vec4 c, vec2 uv, vec2 cnt, float a, float da, float r0, float r1, vec4 col)
{
	float l = distance(cnt, uv);
	vec2 d = uv - cnt;
	float sf = 500.0;
	float theta = atan(d.x, d.y) * sf;
	da /= 2.0;
	float a0 = radians(a - da);
	float a1 = radians(a + da);
	float va = smooth_px(a0 * sf, theta, dsr) - smooth_px(a1 * sf, theta, dsr);
	float vr = smooth_px(r0, l, ds) - smooth_px(r1, l, ds);
    float rgb = sqrt(va * vr);
	c.rgb += col.rgb * rgb * col.a;
    c.a += rgb * col.a;
}


void antenas(inout vec4 c, vec2 uv, vec2 p0, int cnt, float r0, float r1, vec4 c0, vec4 c1)
{
	float da = 180.0f / float(cnt);
    for (int i = -cnt; i <= cnt; i ++)
	{
		float v = float(i & 1);
		vec4 col = v * c0 + (1.0f - v) * c1;
		sector(c, uv, p0, float(i) * da, da, r0, r1, col);
	}
}

vec2 rotateUVmatrinx(vec2 uv, vec2 pivot, float rotation)
{
    mat2 rotation_matrix=mat2(  vec2(sin(rotation),-cos(rotation)),
                                vec2(cos(rotation),sin(rotation))
                                );
    uv -= pivot;
    uv *= rotation_matrix;
    uv += pivot;
    return uv;
}


void vertex()
{   
    float dir = 0.0;
    dir += speed * TIME;
    VERTEX = rotateUVmatrinx(VERTEX, center, radians(dir));
}



void fragment()
{
    
    ivec2 isz = textureSize(TEXTURE, 0);
    vec2 uv = UV * vec2(float(isz.x), float(isz.y));     // координаты текущей точки в пикселях
    COLOR = vec4(0, 0, 0, 0.0); //texture(TEXTURE, UV);  // Цвет текущей точки

    // Сетка антенн
    antenas(COLOR, uv, center, ant_band_count_0, ant_band_r0_0, ant_band_r1_0, color, color_up);
}
"

[sub_resource type="ShaderMaterial" id="ShaderMaterial_h3oo7"]
shader = SubResource("Shader_81bae")
shader_parameter/color = Color(1, 0, 0, 1)
shader_parameter/color_up = Color(1, 1, 1, 0)
shader_parameter/speed = 85.808
shader_parameter/ant_band_count_0 = 4
shader_parameter/ant_band_r0_0 = 0.3
shader_parameter/ant_band_r1_0 = 0.45

[sub_resource type="ShaderMaterial" id="ShaderMaterial_lkrha"]
shader = ExtResource("3_2a1qb")
shader_parameter/point_1 = Vector2(0.125, 0)
shader_parameter/point_2 = Vector2(0.125, 0.036)
shader_parameter/point_3 = Vector2(0, 0.125)
shader_parameter/point_4 = Vector2(0.036, 0.125)
shader_parameter/point_5 = Vector2(0.214, 0.125)
shader_parameter/point_6 = Vector2(0.25, 0.125)
shader_parameter/point_7 = Vector2(0.125, 0.214)
shader_parameter/point_8 = Vector2(0.125, 0.25)
shader_parameter/len = 0.179
shader_parameter/speed = 63.0

[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_svd33"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_lpmq6"]
shader = SubResource("Shader_81bae")
shader_parameter/color = Color(0.0784314, 0.501961, 0.701961, 0.917647)
shader_parameter/color_up = Color(1, 1, 1, 0)
shader_parameter/speed = 158.179
shader_parameter/ant_band_count_0 = 9
shader_parameter/ant_band_r0_0 = 0.27
shader_parameter/ant_band_r1_0 = 0.45

[node name="threat" type="Control"]
layout_mode = 3
anchors_preset = 0
offset_left = -12.0
offset_top = -12.0
offset_right = 12.0
offset_bottom = 12.0
script = ExtResource("1_h7l70")

[node name="bip" type="Sprite2D" parent="."]
material = SubResource("ShaderMaterial_qq6yq")
position = Vector2(12, 12)
scale = Vector2(14, 14)
texture = SubResource("PlaceholderTexture2D_xbpqf")

[node name="selector" type="Sprite2D" parent="."]
visible = false
material = SubResource("ShaderMaterial_fkqwb")
position = Vector2(-1, -1)
scale = Vector2(26, 26)
texture = SubResource("PlaceholderTexture2D_hqs6j")
offset = Vector2(0.5, 0.5)

[node name="ecm_done" type="Sprite2D" parent="."]
visible = false
material = SubResource("ShaderMaterial_h3oo7")
position = Vector2(-2, -2)
scale = Vector2(28, 28)
texture = SubResource("PlaceholderTexture2D_hqs6j")
offset = Vector2(0.5, 0.5)

[node name="track" type="Sprite2D" parent="."]
visible = false
material = SubResource("ShaderMaterial_lkrha")
position = Vector2(12, 12)
scale = Vector2(34, 34)
texture = SubResource("PlaceholderTexture2D_svd33")

[node name="recomendation" type="Sprite2D" parent="."]
visible = false
material = SubResource("ShaderMaterial_lpmq6")
scale = Vector2(24, 24)
texture = SubResource("PlaceholderTexture2D_hqs6j")
offset = Vector2(0.5, 0.5)

[connection signal="gui_input" from="." to="." method="_on_bip_gui_input"]
