diff --git a/data/мп550-работа-эскиз.png b/data/мп550-работа-эскиз.png index b63eb853..18e1faea 100644 Binary files a/data/мп550-работа-эскиз.png and b/data/мп550-работа-эскиз.png differ diff --git a/shaders/shader_edu.tres b/shaders/shader_edu.tres new file mode 100644 index 00000000..888725a6 --- /dev/null +++ b/shaders/shader_edu.tres @@ -0,0 +1,338 @@ +[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://s6xe8igevnv2"] + +[sub_resource type="Shader" id="1"] +code = "shader_type canvas_item; + +const float M_PI = 3.141592653589793; +/*const vec3 blue1 = vec3(0.42, 0.51, 0.55); +const vec3 blue2 = vec3(0.11, 0.21, 0.25); +const vec3 blue3 = vec3(0.35, 0.76, 0.83); +const vec3 blue4 = vec3(0.953, 0.969, 0.89); +const vec3 red = vec3(1.00, 0.38, 0.227); + +uniform vec4 blue1: source_color = vec4(0.4, 0.3, 0.3, 1.0); +uniform vec4 blue2: source_color = vec4(0.6, 0.5, 0.5, 1.0); +uniform vec4 blue3: source_color = vec4(0.8, 0.7, 0.7, 1.0); +uniform vec4 blue4: source_color = vec4(1.0, 0.9, 0.9, 1.0); +uniform vec4 red: source_color = vec4(1.0, 0.5, 0.3, 1.0); */ + +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 blue2: source_color = vec4(0.11, 0.21, 0.25, 1.0); +uniform vec4 blue3: source_color = vec4(0.35, 0.76, 0.83, 1.0); +uniform vec4 blue4: source_color = vec4(0.953, 0.969, 0.89, 1.0); +uniform vec4 red: source_color = vec4(1.00, 0.38, 0.227, 1.0); + +uniform float line_width = 2.0; +uniform float sec_forward = 180.0; +uniform float sec_back = 0.0; +uniform float sec_left = 90.0; +uniform float sec_right = 300.0; +uniform float d0 = 520.0; +uniform float d1 = 1120.0; +uniform float d2 = 1160.0; +uniform float d3 = 100.0; +uniform float d4 = 180.0; +uniform float d5 = 650.0; +uniform float d6 = 800.0; +uniform float d7 = 950.0; +uniform vec2 pc0 = vec2(0, 0); +uniform vec2 pc1 = vec2(0, 0); +uniform vec2 pc2 = vec2(0, 0); +uniform float ap_ant_w = 12.0; +uniform vec2 tr0 = vec2(0, 0); +uniform vec2 tr1 = vec2(0, 0); +uniform vec2 tr2 = vec2(0, 0); + +// Массивы не работают +// uniform int band_ants[3]; // количество антенн, радиус внутренний, радиус внешний, подстройка по углу + +float SMOOTH(float r, float R) +{ + return 1.0 - smoothstep(R - 1.0, R + 1.0, 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 * M_PI / 180.0), - sin(theta0 * M_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) / M_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) +{ + 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) / M_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; +} + + +void bip1(inout vec3 color, vec2 uv, vec2 center, float r, vec3 c, float a) +{ + color += c * SMOOTH(length(uv - center), r) * 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, int cnt, float r0, float r1, vec3 c0, vec3 c1, float a, float adj) +{ + float da = 180.0f / float(cnt); + c0 *= a; + c1 *= a; + for (int i = -cnt; i <= cnt; i ++) + { + float v = float(i & 1); + vec3 col = v * c0 + (1.0f - v) * c1; + sector(c, uv, p0, float(i) * da + adj, da, r0, r1, col); + } +} + + +void circle_thin(inout vec3 color, vec2 uv, vec2 p, float r, float w, vec3 c, float a) +{ + float d = distance(uv, p); + float v0 = r - w; + float v1 = r + w; + color += a * sqrt(smoothstep(v1, v0, d) * smoothstep(v0, v1, d) * c); +} + + +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 r = sqrt(dot(d, d)); + 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; + float r = sqrt(dot(d, d)); + vec2 p = radius * vec2(cos(theta0 * M_PI / 180.0), - sin(theta0 * M_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); +} + + +void fragment() +{ + ivec2 isz = textureSize(TEXTURE, 0); + vec2 uv = UV * vec2(float(isz.x), float(isz.y)); + vec3 rs = vec3(d2, d1, d0) / 2.0f; + COLOR = texture(TEXTURE, UV); + + // РТО + //circle_thin(COLOR.rgb, uv, pc0, d0 / 2.0, line_width, blue1.rgb, 1.0); + //circle_thin(COLOR.rgb, uv, pc0, d1 / 2.0, line_width, blue1.rgb, 1.0); + //circle_thin(COLOR.rgb, uv, pc0, d2 / 2.0, line_width, blue1.rgb, 1.0); + //circle_thin(COLOR.rgb, uv, pc0, d5 / 2.0, line_width, blue1.rgb, 0.5); + //circle_thin(COLOR.rgb, uv, pc0, d6 / 2.0, line_width, blue1.rgb, 0.5); + //circle_thin(COLOR.rgb, uv, pc0, d7 / 2.0, line_width, blue1.rgb, 0.5); + + //line_r(COLOR.rgb, uv, pc0, 45, 580, blue1.rgb, 1.0); + //line_r(COLOR.rgb, uv, pc0, 135, 580, blue1.rgb, 1.0); + //line_r(COLOR.rgb, uv, pc0, 225, 580, blue1.rgb, 1.0); + //line_r(COLOR.rgb, uv, pc0, 315, 580, blue1.rgb, 1.0); + + //sector(COLOR.rgb, uv, pc0, sec_forward, ap_ant_w, 280, 580, red.rgb); + //sector(COLOR.rgb, uv, pc0, sec_back, ap_ant_w, 280, 580, red.rgb); + //sector(COLOR.rgb, uv, pc0, sec_left, ap_ant_w, 280, 580, red.rgb); + //sector(COLOR.rgb, uv, pc0, sec_right, ap_ant_w, 280, 580, red.rgb); + + //antenas(COLOR.rgb, uv, pc0, ants_count, d6 / 2.0, d7 / 2.0, blue0.rgb, blue1.rgb, 0.3, 7.5); + antenas(COLOR.rgb, uv, pc0, 2, 220, 280, blue1.rgb, blue0.rgb, 0.4, 0); + antenas(COLOR.rgb, uv, pc0, 2, 280, 340, blue0.rgb, blue1.rgb, 0.4, 0); + antenas(COLOR.rgb, uv, pc0, 2, 340, 400, blue1.rgb, blue0.rgb, 0.4, 0); + antenas(COLOR.rgb, uv, pc0, 2, 400, 460, blue0.rgb, blue1.rgb, 0.4, 0); + antenas(COLOR.rgb, uv, pc0, 2, 460, 520, blue1.rgb, blue0.rgb, 0.4, 0); + antenas(COLOR.rgb, uv, pc0, 2, 520, 580, blue0.rgb, blue1.rgb, 0.4, 0); + + 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); + + // Массивы не работают + //for (int i = 0; i < 3; i ++) + //{ + // int cnt = int(band_ants[i].x); + // float r0 = band_ants[i].y; + // float r1 = band_ants[i].z; + // float adj = band_ants[i].w; + // antenas(COLOR.rgb, uv, pc0, cnt, r0, r1, blue0.rgb, blue1.rgb, 0.3, adj); + //} + + // Качка + 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); + bip1(COLOR.rgb, uv, pc2, 13.0, blue1.rgb, 1.0); +} +" + +[resource] +shader = SubResource("1") +shader_parameter/blue0 = Color(0.378, 0.4272, 0.45, 1) +shader_parameter/blue1 = Color(0.336, 0.3808, 0.4, 1) +shader_parameter/blue2 = Color(0.11, 0.21, 0.25, 1) +shader_parameter/blue3 = Color(0.35, 0.76, 0.83, 1) +shader_parameter/blue4 = Color(0.953, 0.969, 0.89, 1) +shader_parameter/red = Color(1, 0.38, 0.227, 1) +shader_parameter/line_width = 2.0 +shader_parameter/sec_forward = 0.0 +shader_parameter/sec_back = 90.0 +shader_parameter/sec_left = 180.0 +shader_parameter/sec_right = 270.0 +shader_parameter/d0 = 520.0 +shader_parameter/d1 = 1110.0 +shader_parameter/d2 = 1150.0 +shader_parameter/d3 = 100.0 +shader_parameter/d4 = 180.0 +shader_parameter/d5 = 650.0 +shader_parameter/d6 = 800.0 +shader_parameter/d7 = 950.0 +shader_parameter/pc0 = Vector2(600, 600) +shader_parameter/pc1 = Vector2(120, 1090) +shader_parameter/pc2 = Vector2(90, 1110) +shader_parameter/ap_ant_w = 12.0 +shader_parameter/tr0 = Vector2(300, 400) +shader_parameter/tr1 = Vector2(500, 1000) +shader_parameter/tr2 = Vector2(1020, 240)