Работа в процессе. Исчезает сектор

This commit is contained in:
sasha80
2023-06-07 08:41:11 +03:00
parent 4eedfc85fc
commit 7db6da0fd0
18 changed files with 324 additions and 355 deletions

18
shaders/bip.gdshader Normal file
View File

@@ -0,0 +1,18 @@
shader_type canvas_item;
uniform vec4 color: source_color = vec4(1, 1, 1, 1);
const float ds = 0.01; // Относительное расстояние на котором выполняется сглаживание краёв
const vec2 center = vec2(0.125, 0.125); // Центр должен быть в (0.5, 0.5) но по неведомой причине это не так
const float radius = 0.125 - ds * 2.0; // Радиус должен быть 0.5, но по неведомой причине это не так
const float rate = 10.0;
float smooth_px(float r, float R)
{
return 1.0 - smoothstep(R - ds, R + ds, r);
}
void fragment()
{
COLOR = vec4(1.0, 1.0, 1.0, 1.);
COLOR = color * smooth_px(length(UV - center), radius);
}

41
shaders/sector.gdshader Normal file
View File

@@ -0,0 +1,41 @@
shader_type canvas_item;
uniform vec4 color: source_color = vec4(1, 1, 1, 1);
uniform float width: hint_range(0.0, 360.0, 0.1) = 45.0;
uniform float inner_radius: hint_range(0.0, 0.125, 0.0001) = 0.1;
uniform float outer_radius: hint_range(0.0, 0.125, 0.0001) = 0.125;
const vec2 center = vec2(0.125, 0.125); // Центр должен быть в (0.5, 0.5) но по неведомой причине это не так
const float dsa = 0.0025; // Относительное расстояние на котором выполняется сглаживание краёв
const float dsr = 0.00025; // Относительное расстояние на котором выполняется сглаживание краёв
float smooth_px(float r, float R, float ds)
{
return 1.0 - smoothstep(R - ds, R + ds, r);
}
void sector(inout vec4 uv_color, vec2 uv_pos, float r0, float r1, float w, vec4 c)
{
vec2 d = uv_pos - center;
float theta = atan(d.x, d.y);
w = radians(w / 2.0);
float l = distance(center, uv_pos);
float vr = smooth_px(r0, l, dsr) - smooth_px(r1, l, dsr);
float va = smooth_px(-w, theta, dsa) - smooth_px(w, theta, dsa);
uv_color *= sqrt(va * vr) * c;
}
void rotate_vertex(inout vec2 vert, float a)
{
vert *= mat2(vec2(cos(a), sin(a)), vec2(-sin(a), cos(a)));
}
void fragment()
{
COLOR = vec4(1.0, 1.0, 1.0, 1.0);
sector(COLOR, UV, inner_radius, outer_radius, width, color);
}

View File

@@ -9,11 +9,11 @@ uniform vec2 pc2;
uniform vec2 tr0;
uniform vec2 tr1;
uniform vec2 tr2;
uniform float sec_var = 0.0;
uniform float ap_ant_w = 12.0;
uniform vec4 ap_ant_col;
uniform float strob_dir = 0.0;
uniform float strob_dir_width = 12.0;
uniform vec4 strob_color;
#define ANTENNAS_GRID_SIZE 7
const float ANTENNAS_GRID_SIZE = 7.0;
const float line_width = 2.0;
const float ant_band_count_0 = 2.0;
@@ -40,10 +40,9 @@ const float ant_band_r1_4 = 450.0;
const float ant_band_r1_5 = 500.0;
const float ant_band_r1_6 = 550.0;
const float d4 = 90.0;
const float ap_ant_alpha = 0.3;
const vec4 blue0 = vec4(0.38, 0.47, 0.51, 1.0);
const vec4 blue1 = vec4(0.39, 0.44, 0.50, 1.0);
const vec4 blue0 = vec4(0.38, 0.47, 0.51, 0.4);
const vec4 blue1 = vec4(0.39, 0.44, 0.50, 0.4);
float SMOOTH(float r, float R)
@@ -52,7 +51,7 @@ float SMOOTH(float r, float R)
}
void sector(inout vec3 c, vec2 uv, vec2 center, float a, float da, float r0, float r1, vec3 color, float alpha)
void sector(inout vec4 c, vec2 uv, vec2 center, float a, float da, float r0, float r1, vec4 color)
{
float l = distance(center, uv);
vec2 d = uv - center;
@@ -63,24 +62,18 @@ void sector(inout vec3 c, vec2 uv, vec2 center, float a, float da, float r0, flo
float a1 = radians(a + da);
float va = SMOOTH(a0 * sf, theta) - SMOOTH(a1 * sf, theta);
float vr = SMOOTH(r0, l) - SMOOTH(r1, l);
c += color * sqrt(va * vr) * alpha;
c.rgb += color.rgb * sqrt(va * vr) * color.a;
}
void bip1(inout vec3 color, vec2 uv, vec2 center, float r, vec3 c, float a)
{
color += c * SMOOTH(length(uv - center), r) * a;
}
void antenas(inout vec3 c, vec2 uv, vec2 p0, float cnt, float r0, float r1, vec3 c0, vec3 c1, float a)
void antenas(inout vec4 c, vec2 uv, vec2 p0, float cnt, float r0, float r1, vec4 c0, vec4 c1)
{
float da = 180.0f / float(cnt);
for (int i = int(-cnt); i <= int(cnt); i ++)
{
float v = float(i & 1);
vec3 col = v * c0 + (1.0f - v) * c1;
sector(c, uv, p0, float(i) * da, da, r0, r1, col, a);
vec4 col = v * c0 + (1.0f - v) * c1;
sector(c, uv, p0, float(i) * da, da, r0, r1, col);
}
}
@@ -94,12 +87,12 @@ void circle_thin(inout vec3 color, vec2 uv, vec2 p, float r, float w, vec3 c, fl
}
void line_r(inout vec3 color, vec2 uv, vec2 center, float theta0, float radius, vec3 c, float a)
void line_r(inout vec4 color, vec2 uv, vec2 center, float theta0, float radius, vec4 c)
{
vec2 d = uv - center;
vec2 p = radius * vec2(cos(theta0 * PI / 180.0), - sin(theta0 * PI / 180.0));
float l = length(d - p * clamp(dot(d, p) / dot(p, p), 0.0, 1.0));
color += c * SMOOTH(l, 1.0);
color.rgb += c.rgb * SMOOTH(l, 1.0) * c.a;
}
@@ -121,30 +114,14 @@ void fragment()
vec2 uv = UV * vec2(float(isz.x), float(isz.y)); // координаты текущей точки в пикселях
COLOR = vec4(0, 0, 0, 1.0); //texture(TEXTURE, UV); // Цвет текущей точки
// Сектор направления
sector(COLOR.rgb, uv, pc0, get_ang_atack(450.0 - sec_var), ap_ant_w, float(ant_band_r0_0), float(ant_band_r1_6), ap_ant_col.rgb, ap_ant_alpha);
// Сетка антенн
antenas(COLOR.rgb, uv, pc0, ant_band_count_0, ant_band_r0_0, ant_band_r1_0, blue1.rgb, blue0.rgb, 0.4);
antenas(COLOR.rgb, uv, pc0, ant_band_count_1, ant_band_r0_1, ant_band_r1_1, blue0.rgb, blue1.rgb, 0.4);
antenas(COLOR.rgb, uv, pc0, ant_band_count_2, ant_band_r0_2, ant_band_r1_2, blue1.rgb, blue0.rgb, 0.4);
antenas(COLOR.rgb, uv, pc0, ant_band_count_3, ant_band_r0_3, ant_band_r1_3, blue0.rgb, blue1.rgb, 0.4);
antenas(COLOR.rgb, uv, pc0, ant_band_count_4, ant_band_r0_4, ant_band_r1_4, blue1.rgb, blue0.rgb, 0.4);
antenas(COLOR.rgb, uv, pc0, ant_band_count_5, ant_band_r0_5, ant_band_r1_5, blue0.rgb, blue1.rgb, 0.4);
antenas(COLOR.rgb, uv, pc0, ant_band_count_6, ant_band_r0_6, ant_band_r1_6, blue1.rgb, blue0.rgb, 0.4);
// Цели
bip1(COLOR.rgb, uv, tr0, 13.0, blue1.rgb, 1.0);
bip1(COLOR.rgb, uv, tr1, 13.0, blue1.rgb, 1.0);
bip1(COLOR.rgb, uv, tr2, 13.0, blue1.rgb, 1.0);
// Качка
circle_thin(COLOR.rgb, uv, pc1, d4, line_width, blue1.rgb, 1.0);
line_r(COLOR.rgb, uv, pc1, 0, d4, blue1.rgb, 1.0);
line_r(COLOR.rgb, uv, pc1, 90, d4, blue1.rgb, 1.0);
line_r(COLOR.rgb, uv, pc1, 180, d4, blue1.rgb, 1.0);
line_r(COLOR.rgb, uv, pc1, 270, d4, blue1.rgb, 1.0);
bip1(COLOR.rgb, uv, pc2, 13.0, blue1.rgb, 1.0);
antenas(COLOR, uv, pc0, ant_band_count_0, ant_band_r0_0, ant_band_r1_0, blue1, blue0);
antenas(COLOR, uv, pc0, ant_band_count_1, ant_band_r0_1, ant_band_r1_1, blue0, blue1);
antenas(COLOR, uv, pc0, ant_band_count_2, ant_band_r0_2, ant_band_r1_2, blue1, blue0);
antenas(COLOR, uv, pc0, ant_band_count_3, ant_band_r0_3, ant_band_r1_3, blue0, blue1);
antenas(COLOR, uv, pc0, ant_band_count_4, ant_band_r0_4, ant_band_r1_4, blue1, blue0);
antenas(COLOR, uv, pc0, ant_band_count_5, ant_band_r0_5, ant_band_r1_5, blue0, blue1);
antenas(COLOR, uv, pc0, ant_band_count_6, ant_band_r0_6, ant_band_r1_6, blue1, blue0);
}
"
@@ -156,6 +133,6 @@ shader_parameter/pc2 = Vector2(100, 1065)
shader_parameter/tr0 = Vector2(600, 1000)
shader_parameter/tr1 = Vector2(1000, 600)
shader_parameter/tr2 = Vector2(300, 400)
shader_parameter/sec_var = 0.0
shader_parameter/ap_ant_w = 12.0
shader_parameter/ap_ant_col = null
shader_parameter/strob_dir = 0.0
shader_parameter/strob_dir_width = 12.0
shader_parameter/strob_color = null