Работа в процессе

This commit is contained in:
sasha80
2023-05-12 15:01:49 +03:00
parent 0b7e45bc34
commit 263ff45713
7 changed files with 165 additions and 266 deletions

View File

@@ -3,10 +3,6 @@
[sub_resource type="Shader" id="1"]
code = "shader_type canvas_item;
uniform vec4 blue0: source_color = vec4(0.38, 0.47, 0.51, 1.0);
uniform vec4 blue1: source_color = vec4(0.39, 0.44, 0.50, 1.0);
uniform vec4 red: source_color = vec4(1.00, 0.38, 0.227, 1.0);
uniform float d4 = 180.0;
uniform vec2 pc0;
uniform vec2 pc1;
uniform vec2 pc2;
@@ -15,6 +11,7 @@ uniform vec2 tr1;
uniform vec2 tr2;
uniform float sec_var = 0.0;
uniform float ap_ant_w = 12.0;
uniform vec4 ap_ant_col;
#define ANTENNAS_GRID_SIZE 7
@@ -42,6 +39,11 @@ const float ant_band_r1_3 = 400.0;
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);
float SMOOTH(float r, float R)
@@ -50,45 +52,7 @@ float SMOOTH(float r, float R)
}
float RANGE(float a, float b, float x)
{
return step(a, x) * (1.0 - step(b, x));
}
float RS(float a, float b, float x)
{
return smoothstep(a - 1.0, a + 1.0, x) * (1.0 - smoothstep(b - 1.0, b + 1.0, x));
}
vec2 modulate_move(float a, float b, float c, float d, float time)
{
return vec2(a * cos(time) + b * cos(2.0 * time), c * sin(time) + d * sin(2.0 * time));
}
vec3 radar_scan_line(vec2 uv, vec2 center, float time, float radius, vec3 color)
{
//angle of the line
float theta0 = time * 90.0;
vec2 d = uv - center;
float r = sqrt(dot(d, d));
if (r < radius)
{
//compute the distance to the line theta=theta0
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));
//compute gradient based on angle difference to theta0
float theta = mod(180.0 * atan(d.y, d.x) / PI + theta0, 360.0);
float gradient = clamp(1.0 - theta / 90.0, 0.0, 1.0);
return color * SMOOTH(l, 1.0) + 0.5 * gradient * color;
}
else return vec3(0, 0, 0);
}
void sector(inout vec3 c, vec2 uv, vec2 center, float a, float da, float r0, float r1, vec3 color)
void sector(inout vec3 c, vec2 uv, vec2 center, float a, float da, float r0, float r1, vec3 color, float alpha)
{
float l = distance(center, uv);
vec2 d = uv - center;
@@ -99,110 +63,7 @@ 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);
}
void rotate_uv(inout vec2 uv, float a)
{
float mid = 0.5;
uv.x = cos(a) * (uv.x - mid) + sin(a) * (uv.y - mid) + mid;
uv.y = cos(a) * (uv.x - mid) - sin(a) * (uv.x - mid) + mid;
}
void sector2(inout vec3 c, vec2 uv, vec2 center, float a, float da, float r0, float r1, vec3 color)
{
rotate_uv(uv, 0.0);
float l = distance(center, uv);
vec2 d = uv - center;
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(a0 * sf, theta) - SMOOTH(a1 * sf, theta);
float vr = SMOOTH(r0, l) - SMOOTH(r1, l);
c += color * sqrt(va * vr);
}
void circle(inout vec3 c, vec2 uv, vec2 p0, float radius, float width, vec3 color)
{
float r = length(uv - p0);
c += (SMOOTH(r - width / 2.0, radius) - SMOOTH(r + width / 2.0, radius)) * color;
}
float circle2(vec2 uv, vec2 center, float radius, float width, float opening)
{
vec2 d = uv - center;
float r = sqrt(dot(d, d));
d = normalize(d);
if (abs(d.y) > opening)
return SMOOTH(r - width / 2.0, radius) - SMOOTH(r + width / 2.0, radius);
else
return 0.0;
}
float circle3(vec2 uv, vec2 center, float radius, float width)
{
vec2 d = uv - center;
float r = sqrt(dot(d, d));
d = normalize(d);
float theta = 180.0 * (atan(d.y, d.x) / PI);
return smoothstep(2.0, 2.1, abs(mod(theta + 2.0, 45.0) - 2.0))
* mix(0.5, 1.0, step(45.0, abs(mod(theta, 180.0) - 90.0)))
* (SMOOTH(r - width / 2.0, radius) - SMOOTH(r + width / 2.0, radius));
}
float triangles(vec2 uv, vec2 center, float radius)
{
vec2 d = uv - center;
return RS(-8.0, 0.0, d.x - radius) * (1.0 - smoothstep(7.0 + d.x - radius, 9.0 + d.x - radius, abs(d.y)))
+ RS( 0.0, 8.0, d.x + radius) * (1.0 - smoothstep(7.0 - d.x - radius, 9.0 - d.x - radius, abs(d.y)))
+ RS(-8.0, 0.0, d.y - radius) * (1.0 - smoothstep(7.0 + d.y - radius, 9.0 + d.y - radius, abs(d.x)))
+ RS( 0.0, 8.0, d.y + radius) * (1.0 - smoothstep(7.0 - d.y - radius, 9.0 - d.y - radius, abs(d.x)));
}
float _cross(vec2 uv, vec2 center, float radius)
{
vec2 d = uv - center;
int x = int(d.x);
int y = int(d.y);
float r = sqrt(dot(d, d));
if ((r < radius) && ((x == y) || (x == -y)))
return 1.0;
else return 0.0;
}
void cross_lines(inout vec3 color, vec2 uv, vec2 pc, float r0, float w, vec3 c)
{
vec2 d = uv - pc;
int x = int(d.x);
int y = int(d.y);
float r = sqrt(dot(d, d));
if ((r < r0) && ((x == y) || (x == -y)))
color += c;
color += vec3(0, 0, 0);
}
float dots(vec2 uv, vec2 center, float radius)
{
vec2 d = uv - center;
float r = sqrt(dot(d, d));
if (r <= 2.5)
return 1.0;
if ((r <= radius) && ((abs(d.y + 0.5) <= 1.0) && (mod(d.x + 1.0, 50.0) < 2.0)))
return 1.0;
else if ((abs(d.y + 0.5) <= 1.0) && (r >= 50.0) && (r < 115.0))
return 0.5;
else
return 0.0;
c += color * sqrt(va * vr) * alpha;
}
@@ -212,32 +73,14 @@ void bip1(inout vec3 color, vec2 uv, vec2 center, float r, vec3 c, float a)
}
float bip2(vec2 uv, float time, vec2 center)
{
float r = length(uv - center);
float R = 8.0 + mod(87.0 * time, 80.0);
return (0.5 - 0.5 * cos(30.0 * time)) * SMOOTH(r, 5.0)
+ SMOOTH(6.0, r) - SMOOTH(8.0, r)
+ smoothstep(max(8.0, R - 20.0), R, r) - SMOOTH(R,r);
}
vec3 circle_h(inout vec3 c, vec2 uv, vec2 c0, float r, vec3 color)
{
return 1.0 * color;
}
void antenas(inout vec3 c, vec2 uv, vec2 p0, float cnt, float r0, float r1, vec3 c0, vec3 c1, float a)
{
float da = 180.0f / float(cnt);
c0 *= a;
c1 *= a;
for (int i = int(-cnt); i <= int(cnt); i ++)
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);
sector(c, uv, p0, float(i) * da, da, r0, r1, col, a);
}
}
@@ -251,17 +94,6 @@ void circle_thin(inout vec3 color, vec2 uv, vec2 p, float r, float w, vec3 c, fl
}
void line(inout vec3 color, vec2 uv, vec2 p0, vec2 p1, vec3 c, float a)
{
vec2 d = uv - p0;
float radius = distance(p0, p1);
float theta0 = acos(dot(normalize(p0), normalize(p1)));
vec2 p = radius * vec2(cos(theta0), -sin(theta0));
float l = length(d - p * clamp(dot(d, p) / dot(p, p), 0.0, 1.0));
color += c * SMOOTH(l, 1.0);
}
void line_r(inout vec3 color, vec2 uv, vec2 center, float theta0, float radius, vec3 c, float a)
{
vec2 d = uv - center;
@@ -290,7 +122,7 @@ void fragment()
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), red.rgb);
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);
@@ -307,21 +139,17 @@ void fragment()
bip1(COLOR.rgb, uv, tr2, 13.0, blue1.rgb, 1.0);
// Качка
circle_thin(COLOR.rgb, uv, pc1, d4 / 2.0, line_width, blue1.rgb, 1.0);
line_r(COLOR.rgb, uv, pc1, 0, d4 / 2.0, blue1.rgb, 1.0);
line_r(COLOR.rgb, uv, pc1, 90, d4 / 2.0, blue1.rgb, 1.0);
line_r(COLOR.rgb, uv, pc1, 180, d4 / 2.0, blue1.rgb, 1.0);
line_r(COLOR.rgb, uv, pc1, 270, d4 / 2.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);
}
"
[resource]
shader = SubResource("1")
shader_parameter/blue0 = Color(0.38, 0.47, 0.51, 1)
shader_parameter/blue1 = Color(0.39, 0.44, 0.5, 1)
shader_parameter/red = Color(1, 0.38, 0.227, 1)
shader_parameter/d4 = 180.0
shader_parameter/pc0 = Vector2(610, 600)
shader_parameter/pc1 = Vector2(110, 1070)
shader_parameter/pc2 = Vector2(100, 1065)
@@ -330,3 +158,4 @@ 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