diff --git a/client/inventory_grid.gdshader b/client/inventory_grid.gdshader new file mode 100644 index 0000000..2649773 --- /dev/null +++ b/client/inventory_grid.gdshader @@ -0,0 +1,248 @@ +shader_type canvas_item; +render_mode blend_premul_alpha; + +// Port of Aetheria's UI/Inventory Grid shader to Godot 4 gl_compatibility (OpenGL 3.3). +// Evaluates analytical corner-folded texel boxes for hull/hardpoint silhouettes, L-brackets, +// hairline rules, and 2D Euclidean SDF thermal conduits with RoundUnion fillets. +// +// data_tex (3W x H, filter_nearest): +// 3x + 0 : cell/item fill & armor tint (RGBA) +// 3x + 1 : border/bracket/pipe accent color (RGBA) +// 3x + 2 : R = 8-bit neighbor mismatch mask (N,E,S,W,NE,SE,SW,NW) +// G = flags (bit0=present, bit1=item, bit2=hover, bit3=damaged/stripped, bit4=compatible, bit5=border_radiator) +// B = 4-bit N/E/S/W thermal conductivity pipe mask +// A = hit-pulse flash intensity (0..1) +// temp_tex (W x H, filter_linear): +// R = normalized temperature [20C..200C -> 0..1] +// G = thermal plateau / overheat stress [0..0.5 optimal, 0.5..1.0 overheating] +// B = active cell mask + +uniform sampler2D data_tex : filter_nearest, repeat_disable; +uniform sampler2D temp_tex : filter_linear, repeat_disable; + +uniform vec2 grid_size = vec2(4.0, 5.0); +uniform vec2 rect_size = vec2(180.0, 225.0); +uniform float thermal_mode : hint_range(0.0, 1.0) = 0.0; + +// Look parameters in Aetheria texel units +uniform float icon_texel = 1.51515; +uniform float bg_texel = 1.0; +uniform float rule_inset = 1.5; +uniform float rule_width = 1.0; +uniform float arm_texels = 1.25; +uniform float fill_inset = 2.6; +uniform float softness = 1.0; +uniform float rule_alpha = 0.34; +uniform float bracket_alpha = 1.0; +uniform float fill_alpha = 0.14; + +// Thermal pipe SDF parameters (in cell fractions, edge ramp in pixels) +uniform float blob_radius = 0.1272; +uniform float pipe_half_width = 0.1261; +uniform float fillet = 0.1172; +uniform float pipe_soft = 1.212; + +const float FAR = 1000.0; + +float box_profile(float x, float lo, float hi, float soft) { + if (hi < lo) { + return 0.0; + } + float outside = max(max(lo - x, x - hi), 0.0); + return clamp(1.0 - outside / soft, 0.0, 1.0); +} + +float eval_layer(vec2 p, float cell_px, float texel, uint mask, bool is_item, bool is_icon, float aa_px) { + float t = min(texel, cell_px / 8.0); + bool left = p.x < cell_px * 0.5; + bool top = p.y >= cell_px * 0.5; + float max_t = max(cell_px * 0.5 / t, 4.0); + float x = clamp((left ? p.x : cell_px - p.x) / t, 0.5, max_t); + float y = clamp((top ? cell_px - p.y : p.y) / t, 0.5, max_t); + + uint v_shift = top ? 0u : 2u; + uint h_shift = left ? 3u : 1u; + uint d_shift = top ? (left ? 7u : 4u) : (left ? 6u : 5u); + bool v = ((mask >> v_shift) & 1u) != 0u; + bool h = ((mask >> h_shift) & 1u) != 0u; + bool d = ((mask >> d_shift) & 1u) != 0u; + bool concave = !v && !h && d; + + float soft = clamp(softness * aa_px / max(t, 0.25), 0.15, 2.0); + float fill_lo = fill_inset + 0.5; + float fx = h ? box_profile(x, fill_lo, FAR, soft) : 1.0; + float fy = v ? box_profile(y, fill_lo, FAR, soft) : 1.0; + float f = fx * fy; + if (concave) { + f -= box_profile(x, -FAR, fill_inset - 0.5, soft) * box_profile(y, -FAR, fill_inset - 0.5, soft); + } + f = clamp(f, 0.0, 1.0); + if (!is_icon) { + return f; + } + + float a = is_item ? fill_alpha * f : 0.0; + float ri = rule_inset; + float rlo = ri - (rule_width - 1.0) * 0.5; + float rhi = ri + (rule_width - 1.0) * 0.5; + float rx = box_profile(x, rlo, rhi, soft); + float ry = box_profile(y, rlo, rhi, soft); + float arms = arm_texels >= 1.0 ? 1.0 : 0.0; + + if (v) { + a += rule_alpha * ry * (h ? box_profile(x, ri, FAR, soft) : 1.0); + } + if (h) { + a += rule_alpha * rx * (v ? box_profile(y, ri + 1.0, FAR, soft) : 1.0); + } + if (v && h) { + a += (bracket_alpha - rule_alpha) * (ry * box_profile(x, ri, ri + arm_texels, soft) + arms * rx * box_profile(y, ri + 1.0, ri + arm_texels, soft)); + } else if (concave) { + a += bracket_alpha * (ry * box_profile(x, ri - arm_texels, ri, soft) + arms * rx * box_profile(y, ri - arm_texels, ri - 1.0, soft)); + } else if (!v && !h) { + // Faint cell subdivision hairline across matched internal cell boundaries + float sub_x = box_profile(x, 0.0, 0.65, soft); + float sub_y = box_profile(y, 0.0, 0.65, soft); + a += 0.14 * max(sub_x, sub_y); + } + return clamp(a, 0.0, 1.0); +} + +float round_union(float a, float b, float r) { + vec2 u = max(vec2(r - a, r - b), vec2(0.0)); + return max(r, min(a, b)) - length(u); +} + +float eval_pipes(vec2 p, float cell_px, uint cond, float aa_px) { + vec2 q = p / cell_px - 0.5; + float d = length(q) - blob_radius; + vec2 dirs[4]; + dirs[0] = vec2(0.0, 1.0); + dirs[1] = vec2(1.0, 0.0); + dirs[2] = vec2(0.0, -1.0); + dirs[3] = vec2(-1.0, 0.0); + + float bars[4]; + for (int b = 0; b < 4; b++) { + float along = dot(q, dirs[b]); + float perp = abs(dot(q, vec2(dirs[b].y, -dirs[b].x))); + bool connected = ((cond >> uint(b)) & 1u) != 0u; + bars[b] = !connected + ? FAR + : (along >= 0.0 ? perp - pipe_half_width : length(vec2(perp, along)) - pipe_half_width); + d = min(d, bars[b]); + } + for (int c = 0; c < 4; c++) { + int n = (c + 1) % 4; + if (bars[c] < FAR && bars[n] < FAR && dot(q, dirs[c] + dirs[n]) > 0.0) { + d = min(d, round_union(bars[c], bars[n], fillet)); + } + } + return clamp(0.5 - d * cell_px / max(pipe_soft * aa_px, 0.25), 0.0, 1.0); +} + +vec3 thermal_ramp(float t) { + vec3 c0 = vec3(0.11, 0.18, 0.24); // ambient cool slate + vec3 c1 = vec3(0.24, 0.48, 0.34); // warm olive + vec3 c2 = vec3(0.86, 0.64, 0.18); // optimal plateau amber-gold + vec3 c3 = vec3(0.92, 0.28, 0.14); // hot crimson-orange + vec3 c4 = vec3(1.00, 0.85, 0.58); // critical incandescent + if (t < 0.25) return mix(c0, c1, t / 0.25); + if (t < 0.55) return mix(c1, c2, (t - 0.25) / 0.30); + if (t < 0.85) return mix(c2, c3, (t - 0.55) / 0.30); + return mix(c3, c4, (t - 0.85) / 0.15); +} + +void fragment() { + vec2 safe_grid = max(grid_size, vec2(1.0)); + vec2 cell_wh = rect_size / safe_grid; + float S = min(cell_wh.x, cell_wh.y); + vec2 grid_px = safe_grid * S; + vec2 origin = (rect_size - grid_px) * 0.5; + vec2 local_px = UV * rect_size - origin; + + vec2 cellf = floor(local_px / S); + if (cellf.x < 0.0 || cellf.y < 0.0 || cellf.x >= safe_grid.x || cellf.y >= safe_grid.y) { + COLOR = vec4(0.0); + } else { + vec2 p_godot = local_px - cellf * S; + // Flip Y inside cell to match Aetheria's y-up Layer / Pipes convention + vec2 p = vec2(p_godot.x, S - p_godot.y); + + float tex_w = safe_grid.x * 3.0; + float ty = (cellf.y + 0.5) / safe_grid.y; + vec4 cell_fill = textureLod(data_tex, vec2((cellf.x * 3.0 + 0.5) / tex_w, ty), 0.0); + vec4 border_accent = textureLod(data_tex, vec2((cellf.x * 3.0 + 1.5) / tex_w, ty), 0.0); + vec4 meta = textureLod(data_tex, vec2((cellf.x * 3.0 + 2.5) / tex_w, ty), 0.0); + + uint mask = uint(round(meta.r * 255.0)); + uint flags = uint(round(meta.g * 255.0)); + uint cond = uint(round(meta.b * 255.0)); + float hit_pulse = meta.a; + + if ((flags & 1u) == 0u) { + COLOR = vec4(0.0); + } else { + bool is_item = (flags & 2u) != 0u; + bool is_hover = (flags & 4u) != 0u; + bool is_damaged = (flags & 8u) != 0u; + bool is_compatible = (flags & 16u) != 0u; + + float aa_px = clamp(fwidth(UV.x) * rect_size.x, 0.2, 2.0); + + vec4 temp_sample = texture(temp_tex, local_px / grid_px); + float norm_temp = temp_sample.r; + float plateau_stress = temp_sample.g; + vec3 heat_col = thermal_ramp(norm_temp); + + float a_bg = eval_layer(p, S, bg_texel, mask, false, false, aa_px) * cell_fill.a; + float a_rules = eval_layer(p, S, icon_texel, mask, is_item, true, aa_px); + float a_pipes = eval_pipes(p, S, cond, aa_px); + + // Intact vs stripped (Armor == 0) interior fill + vec3 base_rgb = mix(cell_fill.rgb, heat_col, mix(0.24, 0.84, thermal_mode)); + if (is_damaged) { + // Diagonal fracture/exposed-core hatching at 45 deg + float hatch_coord = (p_godot.x + p_godot.y) / max(S * 0.22, 4.0); + float hatch_dist = abs(fract(hatch_coord) - 0.5); + float hatch = 1.0 - smoothstep(0.10, 0.22, hatch_dist); + base_rgb = mix(base_rgb * 0.55, vec3(0.82, 0.20, 0.14), hatch * 0.65); + } + + // Thermal plateau glow over hot cells + float overheat_glow = max(plateau_stress - 0.5, 0.0) * 2.0; + base_rgb += heat_col * (0.12 * norm_temp + 0.22 * overheat_glow); + + if (is_hover) { + base_rgb = mix(base_rgb, vec3(0.95, 0.94, 0.88), 0.16); + } + + // Active hit-pulse impact flash + vec3 flash_col = vec3(1.0, 0.76, 0.38); + base_rgb = mix(base_rgb, flash_col, hit_pulse * 0.85); + + vec3 accent_rgb = border_accent.rgb; + if (is_damaged) { + accent_rgb = mix(accent_rgb, vec3(0.92, 0.26, 0.18), 0.70); + } + if (is_compatible) { + float pulse = 0.72 + 0.28 * sin(TIME * 6.5); + accent_rgb = mix(accent_rgb, vec3(0.96, 0.82, 0.30), pulse); + a_rules = clamp(a_rules * 1.35, 0.0, 1.0); + } + if (is_hover) { + accent_rgb = mix(accent_rgb, vec3(1.0), 0.35); + a_rules = clamp(a_rules * 1.25, 0.0, 1.0); + } + accent_rgb = mix(accent_rgb, flash_col, hit_pulse * 0.90); + + float icon_alpha = mix(a_rules * border_accent.a, max(a_rules * 0.26, a_pipes), thermal_mode); + vec3 pipe_rgb = mix(accent_rgb, heat_col * 1.2 + vec3(0.14), 0.72); + vec3 icon_rgb = mix(accent_rgb, pipe_rgb, thermal_mode * clamp(a_pipes * 1.2, 0.0, 1.0)); + + vec3 out_rgb = icon_rgb * icon_alpha + base_rgb * a_bg * (1.0 - icon_alpha); + float out_a = clamp(icon_alpha + a_bg * (1.0 - icon_alpha), 0.0, 1.0); + COLOR = vec4(out_rgb, out_a); + } + } +} diff --git a/client/panel_chrome.gdshader b/client/panel_chrome.gdshader new file mode 100644 index 0000000..b178469 --- /dev/null +++ b/client/panel_chrome.gdshader @@ -0,0 +1,80 @@ +shader_type canvas_item; +render_mode blend_premul_alpha; + +// Resolution-independent industrial panel chrome using the same analytical corner-folded +// Box / L-bracket + hairline border + inset fill math as inventory_grid.gdshader (1x1 cell). +// Stays razor-sharp at 720p, 1080p, 1440p, and 4K. + +uniform vec2 rect_size = vec2(320.0, 160.0); +uniform float corner_len = 12.0; +uniform float border_px = 1.5; +uniform float fill_inset = 2.0; +uniform float rule_inset = 1.5; +uniform float rule_alpha = 0.55; +uniform float bracket_alpha = 1.0; +uniform float top_bar_px = 2.0; +uniform float scanline_strength = 0.045; + +uniform vec4 bg_color : source_color = vec4(0.075, 0.086, 0.075, 0.88); +uniform vec4 border_color : source_color = vec4(0.243, 0.275, 0.220, 1.0); +uniform vec4 accent_color : source_color = vec4(0.878, 0.541, 0.290, 1.0); + +const float FAR = 10000.0; + +float box_profile(float x, float lo, float hi, float soft) { + if (hi < lo) { + return 0.0; + } + float outside = max(max(lo - x, x - hi), 0.0); + return clamp(1.0 - outside / max(soft, 0.05), 0.0, 1.0); +} + +void fragment() { + vec2 size = max(rect_size, vec2(4.0)); + vec2 p = UV * size; + float aa = clamp(fwidth(UV.x) * size.x, 0.2, 2.0); + + // Fold into nearest corner quadrant (1x1 cell, all 4 cardinal edges active) + bool left = p.x < size.x * 0.5; + bool top = p.y < size.y * 0.5; + float x = max(left ? p.x : size.x - p.x, 0.5 * aa); + float y = max(top ? p.y : size.y - p.y, 0.5 * aa); + + // Inset background fill + float fx = box_profile(x, fill_inset, FAR, aa); + float fy = box_profile(y, fill_inset, FAR, aa); + float fill_mask = fx * fy; + + // Hairline border and corner L-brackets + float ri = rule_inset; + float half_w = max(border_px - 1.0, 0.0) * 0.5; + float rlo = ri - half_w * aa; + float rhi = ri + half_w * aa; + float rx = box_profile(x, rlo, rhi, aa); + float ry = box_profile(y, rlo, rhi, aa); + + float rule_mask = max(ry * box_profile(x, rlo, FAR, aa), rx * box_profile(y, rlo, FAR, aa)); + float clen = min(corner_len, min(size.x, size.y) * 0.35); + float bracket_mask = max(ry * box_profile(x, rlo, ri + clen, aa), rx * box_profile(y, rlo, ri + clen, aa)); + + // Subtle top-bar & micro-scanline accent inside the fill + float top_bar = box_profile(p.y, fill_inset + 0.5, fill_inset + 0.5 + top_bar_px, aa) * fx; + float scan = 1.0 - scanline_strength * (0.5 + 0.5 * sin(p.y * 2.0943951)); + + vec3 fill_rgb = mix(bg_color.rgb * scan, accent_color.rgb, top_bar * 0.24); + float fill_a = fill_mask * bg_color.a; + + float edge_rule = clamp(rule_mask - bracket_mask, 0.0, 1.0) * rule_alpha * border_color.a; + float edge_bracket = bracket_mask * bracket_alpha * accent_color.a; + + vec3 rgb = fill_rgb * fill_a; + float alpha = fill_a; + + rgb = border_color.rgb * edge_rule + rgb * (1.0 - edge_rule); + alpha = edge_rule + alpha * (1.0 - edge_rule); + + rgb = accent_color.rgb * edge_bracket + rgb * (1.0 - edge_bracket); + alpha = edge_bracket + alpha * (1.0 - edge_bracket); + + COLOR = vec4(rgb, clamp(alpha, 0.0, 1.0)); +} diff --git a/src/RustToDust.Core/GridChassis.cs b/src/RustToDust.Core/GridChassis.cs index ee88072..233ddec 100644 --- a/src/RustToDust.Core/GridChassis.cs +++ b/src/RustToDust.Core/GridChassis.cs @@ -175,6 +175,9 @@ namespace RustToDust.Core public float CoreHp { get; private set; } public float MaxCoreHp { get; private set; } public bool IsDestroyed => CoreHp <= 0f; + public int HitSequence { get; private set; } + public int LastHitX { get; private set; } + public int LastHitY { get; private set; } public static bool CanFit(HardpointSpec hp, ModuleSpec mod) => mod.Kind == hp.Kind && mod.Width <= hp.Width && mod.Height <= hp.Height; @@ -451,6 +454,10 @@ namespace RustToDust.Core CoreHp = MathF.Max(0f, CoreHp - spill); } + HitSequence++; + LastHitX = cx; + LastHitY = cy; + return new HitResult(cx, cy, absorbed, spill, IsDestroyed); }