Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 | 25x 25x 25x 25x 12x 10x 10x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 25x 25x 2352x 2352x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 4x 4x 1x 1x 1x 4x 8x 8x 2x 2x 2x 8x | import { Color, FillGradient, Graphics, type Container } from 'pixi.js';
import {
burstParticlePositionInto,
burstParticles,
emberColor,
hsvToHex,
projectYawedInto,
scratchProjected,
type BurstParticle,
type Projected,
type Vec3,
} from './space.ts';
import {
BURST_FRAME_BUDGET,
BURST_SKIRT_FRAME_BUDGET,
burstGrainCount,
judgmentParticleMultiplier,
} from './burst-budget.ts';
import { drawReticle, sharedShapeBatch } from './draw.ts';
import { SYN_GLOW_SIZE, synGlowTexture } from './style.ts';
import {
audioDrive,
type BeMusicBomb,
type BeMusicLaneKind,
comboTier,
effectProfile,
hash01,
clampHoldSparkX,
holdSeed,
holdSparks,
resolveLaneRuns,
type BeMusicLaneFrame,
backSpinChevron,
hellChargeZigzag,
longNoteCentreLineAlpha,
resolveNoteHeight,
resolveHellChargeLook,
resolveLongNoteMarks,
} from '@be-music/player-skin-sdk';
import {
type PixiBombsContext,
type PixiLanesContext,
type PixiLongNoteContext,
type PixiNoteContext,
type ChildPool,
keyBeamGradient,
wheelArrowPoints,
} from '../pixi-kit/index.ts';
/** Per-lane-class light: note body, glow hue (0..1), and the colour the lane beam / key cap light up in. */
interface LaneLight {
body: number;
glow: number;
hue: number;
}
// Readable first, in the skin's ember palette: white keys burn warm white-gold with an ember halo, black keys run
// electric blue, scratch hot magenta.
/**
* Lane lights. `body` colours the notes: they differ in lightness as well as hue (white, deep blue, hot magenta) so the
* three lane kinds stay apart at a glance, even on a lit beam; `glow` colours beams, halos, and bursts.
*/
const SCRATCH_LIGHT: LaneLight = { body: 0xff2b8a, glow: 0xff3d9e, hue: 0.92 };
// The 24 / 48 KEY wheel stands where the scratch would, and burns the same magenta.
const LIGHTS: Record<BeMusicLaneKind, LaneLight> = {
white: { body: 0xffffff, glow: 0xff7a1e, hue: 0.07 },
// Lighter than a pure blue: a dark body melts into the note's dark rim and reads thinner than a white note.
black: { body: 0x4a86ff, glow: 0x3fb4ff, hue: 0.57 },
scratch: SCRATCH_LIGHT,
'wheel-up': SCRATCH_LIGHT,
'wheel-down': SCRATCH_LIGHT,
};
export const SYNESTHESIA_BOMB_DURATION_MS = 620;
/** Share of the bomb's life (`t`) the lock-on's centre cross shows for. */
const BOMB_CROSS_SPAN = 0.3;
/**
* Angle in radians of the bomb's centre cross at bomb life `t` (0..1), in screen space where y points down, so the
* negative result turns it counter-clockwise on screen. It makes a quarter turn over the cross's span, quick at first
* and settling as the reticle locks, so it ends square again just before it vanishes. Below full effects
* (`amount < 1`) the cross holds still.
*/
export function synesthesiaBombCrossAngle(t: number, amount: number): number {
if (amount < 1) return 0;
const progress = Math.max(0, Math.min(1, t / BOMB_CROSS_SPAN));
return -(Math.PI / 2) * (1 - (1 - progress) ** 3);
}
export function renderSynesthesiaLanes({
graphics,
lanes,
beatPhase,
nowMs,
combo,
effects,
audio,
}: PixiLanesContext): void {
const pulse = (1 - beatPhase) ** 2;
const drive = audioDrive(audio, effects);
// The judgement line burns brighter as the run builds, and cycles the spectrum once it is in the zone.
const tier = effectProfile(effects).enabled ? comboTier(combo ?? 0) : 0;
// ...and swells on every bass hit of the mix.
const heat = 1 + 0.3 * tier + 0.9 * drive.bass;
// Stepped through 17 shades so the cached beat gradient (one per colour) stays bounded.
const lineColor = tier >= 3 ? emberColor(0.55 + (0.35 * Math.round(8 * Math.sin(nowMs / 700))) / 8) : 0xff8a2a;
let gridTop = Number.POSITIVE_INFINITY;
let gridBottom = 0;
let gridLeft = Number.POSITIVE_INFINITY;
for (const lane of lanes) {
const { x, w, top, bottom } = lane;
const light = LIGHTS[lane.kind];
const laneHeight = Math.max(1, bottom - top);
gridTop = Math.min(gridTop, top);
gridBottom = Math.max(gridBottom, bottom);
gridLeft = Math.min(gridLeft, x);
// Near-black bed, so the particle world behind the playfield reads only as a faint depth cue; white-key lanes take
// a warmer, lifted bed so they read apart from the black keys and the scratch.
graphics
.rect(x, top, w, laneHeight)
.fill(lane.kind === 'white' ? { color: 0x180c06, alpha: 0.88 } : { color: 0x050201, alpha: 0.8 });
// Key beam: a column of the lane's light, near solid at the judgement line and easing out up the lane, so a press
// reads clearly while the notes still on their way down keep their contrast.
Eif (lane.beam > 0) {
const beamHeight = Math.min(laneHeight, 250);
const beamAlpha = lane.beam * lane.beam * (3 - 2 * lane.beam);
graphics
.rect(x, bottom - beamHeight, w, beamHeight)
.fill({ fill: keyBeamGradient(light.glow), alpha: beamAlpha * 0.9 });
const coreHeight = Math.min(laneHeight, 26);
graphics
.rect(x, bottom - coreHeight, w, coreHeight)
.fill({ fill: resolveColumnGradient(0xffffff), alpha: beamAlpha * 0.25 });
}
// Fill the beam edge to edge, then redraw the rail so it remains a crisp boundary.
graphics.rect(x, top, 1, laneHeight).fill({ fill: resolveColumnGradient(light.glow), alpha: 0.5 });
// Key caps: a glass sliver that lights up in the lane's colour on press.
const pressed = lane.beam > 0.6;
graphics
.rect(x + 1, bottom + 4, Math.max(2, w - 2), 10)
.fill({ color: pressed ? light.glow : 0x140804, alpha: 0.9 });
graphics.rect(x + 1, bottom + 13, Math.max(2, w - 2), 1).fill({ color: light.glow, alpha: pressed ? 1 : 0.45 });
// A wheel lane's cap carries the way it turns.
const arrow = wheelArrowPoints(lane.kind, x + w / 2, bottom + 8.5, Math.min(3.5, (w - 2) / 3));
Iif (arrow) graphics.poly(arrow).fill({ color: pressed ? 0x140804 : light.glow, alpha: 0.95 });
}
Iif (lanes.length === 0) return;
// Close each play side's grid on its right edge (each lane only draws its left hairline).
const runs = resolveLaneRuns(lanes);
for (const run of runs) {
graphics.rect(run.right - 1, gridTop, 1, Math.max(1, gridBottom - gridTop)).fill({ color: 0xff7a1e, alpha: 0.25 });
}
// Judgement line: a crisp white filament with no bloom around it — one per play side, so it never crosses the gap
// between the double-play banks, at that side's lanes' foot (a side's LIFT raises it). The beat rises above it
// instead: an ember wash fading up the lanes that leaps tall and bright on each beat and settles back before the next.
const beatAlpha = Math.min(1, (0.1 + 0.55 * pulse) * heat);
for (const run of runs) {
const lineW = run.right - run.left;
const y = lanes.reduce(
(foot, lane) => (lane.x >= run.left && lane.x < run.right ? Math.max(foot, lane.bottom) : foot),
gridTop,
);
const beatHeight = Math.min(y - gridTop, 36 + 110 * pulse * (0.7 + 0.3 * heat));
graphics
.rect(run.left, y - 3 - beatHeight, lineW, beatHeight)
.fill({ fill: beatGradient(lineColor), alpha: beatAlpha });
graphics.rect(run.left, y - 3, lineW, 3).fill({ color: 0xffd08a, alpha: 0.85 });
graphics.rect(run.left, y - 2, lineW, 1).fill(0xffffff);
}
}
export function renderSynesthesiaNote({ graphics, kind, x, w, y, whiteLaneWidth }: PixiNoteContext): void {
const bodyW = Math.max(4, w);
drawNote(graphics, x, y, bodyW, resolveNoteHeight(bodyW, whiteLaneWidth), LIGHTS[kind]);
}
/** Width (px) of one segment of a mine's broken filament, gap included. */
const MINE_SEGMENT = 6;
/** How often (per second) the mine's filament re-rolls which segments are lit. */
const MINE_FLICKER_HZ = 14;
/**
* Whether segment `segment` of the broken filament of a mine in the lane at `laneX` is lit at play time `nowMs`: about
* two in three are, re-rolled {@link MINE_FLICKER_HZ} times a second, so the filament stutters like a failing light.
*/
export function mineFilamentLit(laneX: number, segment: number, nowMs: number): boolean {
const tick = Math.floor((nowMs / 1000) * MINE_FLICKER_HZ);
return hash01(Math.round(laneX) * 131 + segment * 17 + tick * 7919) > 0.35;
}
/**
* A mine: shaped like a note so it reads in the same rhythm, but bright crimson in a throbbing red halo, with a broken,
* flickering filament where a note carries its clean white one — a note that has gone wrong, to be left alone.
*/
export function renderSynesthesiaMine({ graphics, x, w, y, nowMs, whiteLaneWidth }: PixiNoteContext): void {
const bodyW = Math.max(4, w);
const noteHeight = resolveNoteHeight(bodyW, whiteLaneWidth);
// A red halo that throbs like a warning light (twice a second), so the mine stands out of the lane at a glance.
const alarm = 0.5 + 0.5 * Math.sin((nowMs / 1000) * Math.PI * 4);
graphics
.rect(x - 4, y - noteHeight - 4, bodyW + 8, noteHeight + 8)
.fill({ color: 0xff2030, alpha: 0.18 + 0.22 * alarm });
graphics.rect(x - 1, y - noteHeight - 1, bodyW + 2, noteHeight + 2).fill({ color: 0x05010a, alpha: 0.9 });
graphics.rect(x, y - noteHeight, bodyW, noteHeight).fill(0xc4142c);
graphics.rect(x, y - noteHeight, bodyW, noteHeight).stroke({ color: 0xff6070, width: 1, alignment: 1 });
graphics.rect(x, y - noteHeight, bodyW, 2).fill({ color: 0xff8a94, alpha: 0.9 });
// The broken filament burns white-hot where a note's runs clean.
for (let segment = 0; segment * MINE_SEGMENT < bodyW; segment += 1) {
if (!mineFilamentLit(x, segment, nowMs)) continue;
const left = segment * MINE_SEGMENT;
graphics
.rect(x + left, y - Math.round(noteHeight / 2) - 1, Math.min(MINE_SEGMENT - 2, bodyW - left), 2)
.fill(0xffe0e0);
}
}
export function renderSynesthesiaLongNote({
graphics,
kind,
x,
w,
top,
bottom,
nowMs,
mode,
backSpinScratch,
state,
releasedElapsedMs,
whiteLaneWidth,
}: PixiLongNoteContext): void {
const light = LIGHTS[kind];
const marks = resolveLongNoteMarks({ mode, backSpinScratch });
const bodyX = x;
const bodyW = Math.max(4, w);
// A note is as tall as a share of its lane's width (every note as a white key's), standing on its bottom edge.
const noteHeight = resolveNoteHeight(bodyW, whiteLaneWidth);
const bodyTop = top - noteHeight;
const bodyH = Math.max(1, bottom - top);
// A hell charge note shows how it stands (`resolveHellChargeLook`): its colour, its glow and its zigzag filament's
// motion change together — HELL violet with a still zigzag before it is reached, a bright orange glow with the zigzag
// flowing into the line while it charges, a dim red with the zigzag flowing back up while it drains.
const look = marks.hellCharge ? resolveHellChargeLook(state, nowMs) : undefined;
if (look) {
if (look.glow > 0)
graphics.rect(bodyX - 3, bodyTop, bodyW + 6, bodyH).fill({ color: look.color, alpha: 0.3 * look.glow });
graphics.rect(bodyX + 1, bodyTop, bodyW - 2, bodyH).fill({ color: look.color, alpha: 0.16 + 0.3 * look.glow });
} else {
// A beam of light between head and tail: a translucent core with a bright centre filament.
graphics.rect(bodyX + 1, bodyTop, bodyW - 2, bodyH).fill({ color: light.body, alpha: 0.22 });
}
// Let go early, the filament fades out with the hold.
const line = longNoteCentreLineAlpha(releasedElapsedMs);
if (!look && line > 0) {
graphics.rect(bodyX + bodyW / 2 - 1, bodyTop, 2, bodyH).fill({ color: 0xffffff, alpha: 0.55 * line });
}
if (look) {
// A hell charge note's filament zigzags: white-hot while it charges, a light tint of its colour otherwise.
const zigzag = hellChargeZigzag(bodyX, bodyW, bodyTop, bodyTop + bodyH, { nowMs, flow: look.flow });
if (line > 0 && zigzag.length >= 4) {
graphics.moveTo(zigzag[0]!, zigzag[1]!);
for (let index = 2; index < zigzag.length; index += 2) graphics.lineTo(zigzag[index]!, zigzag[index + 1]!);
graphics.stroke({
color: look.lineColor,
width: 2,
alpha: (0.55 + 0.45 * look.glow) * line,
});
}
// The head on the judgement line glows with the note: brightest while charging, gone once it is over.
if (look.glow > 0) {
graphics
.rect(bodyX - 4, bottom - noteHeight - 4, bodyW + 8, noteHeight + 8)
.fill({ color: look.color, alpha: 0.45 * look.glow });
}
}
drawNote(graphics, bodyX, bottom, bodyW, noteHeight, light);
// An LN's tail is not judged, so it is drawn translucent: where to let go, not a note to hit. A CN / HCN tail is
// judged on release and keeps the full cap.
drawNote(graphics, bodyX, top, bodyW, noteHeight, light, marks.judgedTail ? 1 : LN_TAIL_ALPHA);
if (marks.backSpin) {
// A back-spin scratch: a dark-rimmed white chevron on the tail cap, pointing back up the lane — spin it back there.
const chevron = backSpinChevron(bodyX, bodyW, top, noteHeight);
graphics.poly(chevron).stroke({ color: 0x05010a, width: 2, alpha: 0.9 });
graphics.poly(chevron).fill(0xffffff);
}
}
/** How opaque an LN's tail cap is: clearly the end of the note, but quieter than a cap to hit. */
const LN_TAIL_ALPHA = 0.4;
/** A flat bar with a white filament on top and a dark rim — a plain rectangle that reads at a glance. */
function drawNote(
graphics: Graphics,
x: number,
y: number,
w: number,
noteHeight: number,
light: LaneLight,
alpha = 1,
): void {
// A dark rim lifts the bar off the lit lane and the beam behind it. It sits outside the body: the body's bottom edge is
// the judgement position.
graphics.rect(x - 1, y - noteHeight - 1, w + 2, noteHeight + 2).fill({ color: 0x05010a, alpha: 0.9 * alpha });
graphics.rect(x, y - noteHeight, w, noteHeight).fill({ color: light.body, alpha });
// A bright filament on top and a fainter one along the bottom: both edges of a coloured note stay distinct from the
// rim, so a blue or magenta note reads as tall as a white one (whose body is already as bright as its edges).
graphics.rect(x, y - noteHeight, w, 2).fill({ color: 0xffffff, alpha: 0.6 * alpha });
graphics.rect(x, y - 1, w, 1).fill({ color: 0xffffff, alpha: 0.35 * alpha });
}
/** Sparks per hit at combo tier 0; each tier adds {@link BURST_PARTICLES_PER_TIER}. */
const BURST_PARTICLES = 170;
const BURST_PARTICLES_PER_TIER = 24;
const BURST_PARTICLES_MAX = BURST_PARTICLES + BURST_PARTICLES_PER_TIER * 4;
/**
* Skirt grains per hit at combo tier 0 (each tier adds {@link BURST_SKIRT_PER_TIER}): fine powder that spreads along
* the judgement line and barely rises, so it thickens the burst without dusting the lanes the next notes fall down.
*/
const BURST_SKIRT = 140;
const BURST_SKIRT_PER_TIER = 16;
const BURST_SKIRT_MAX = BURST_SKIRT + BURST_SKIRT_PER_TIER * 4;
/** Seed offset so a hit's skirt flies in different directions from its sparks. */
const SKIRT_SEED = 0x5f3759df;
const BURST_FOCAL = 260;
/** Grain size (0.4..1) from which a spark leaves a hairline trail / carries a glow sprite; the rest is fine powder. */
const POWDER_TRAIL_SIZE = 0.85;
const POWDER_GLINT_SIZE = 0.94;
const SPARKS = new Map<number, BurstParticle[]>();
const SKIRTS = new Map<number, BurstParticle[]>();
function cachedBurst(cache: Map<number, BurstParticle[]>, seed: number, count: number): BurstParticle[] {
let particles = cache.get(seed);
if (particles && particles.length >= count) return particles;
// Re-seed the oldest storage once the window of recent hits fills.
if (!particles && cache.size >= 32) {
const oldest = cache.keys().next().value!;
particles = cache.get(oldest);
cache.delete(oldest);
}
particles = burstParticles(seed, count, particles);
cache.set(seed, particles);
return particles;
}
const bombMasks = new WeakMap<Container, Graphics>();
/** The shape each bomb mask was last drawn for ({@link maskShape}). */
const bombMaskShapes = new WeakMap<Graphics, string>();
/** A key for the bomb mask over lane runs `runs` from `top` to `bottom`. */
function maskShape(top: number, bottom: number, runs: readonly { left: number; right: number }[]): string {
let shape = `${top},${bottom}`;
for (const run of runs) shape += `;${run.left},${run.right}`;
return shape;
}
/**
* The Synesthesia hit: a 3D particle burst in perspective. Layered back to front —
*
* 1. a light pillar rising up the lane,
* 2. motion trails for every spark,
* 3. depth-sorted glow sparks that launch white-hot and cool into the lane's hue,
* 4. a core flash and an anamorphic streak across the line,
* 5. a lock-on reticle that snaps shut on the hit and fades.
*
* The smaller sparks fly as square voxels rather than round glows, like shattering wireframes.
* Everything is additive, so overlapping hits bloom into each other like light instead of stacking opaque shapes.
*/
export function renderSynesthesiaBombs({
layer,
pool,
bombs,
combo,
effects,
settings,
lanes,
nowMs,
}: PixiBombsContext): void {
// Keep hit effects inside each playfield, clear of the score, gauge and central BGA.
if (layer && lanes?.length) {
let mask = bombMasks.get(layer);
if (!mask) {
mask = new Graphics();
layer.addChild(mask);
layer.mask = mask;
bombMasks.set(layer, mask);
}
let top = Number.POSITIVE_INFINITY;
let bottom = Number.NEGATIVE_INFINITY;
for (const lane of lanes) {
top = Math.min(top, lane.top);
bottom = Math.max(bottom, lane.bottom);
}
bottom += 48;
const runs = resolveLaneRuns(lanes);
// The lanes rarely move, and a rebuilt mask re-triangulates and re-uploads: redraw it only when they do.
const shape = maskShape(top, bottom, runs);
if (bombMaskShapes.get(mask) !== shape) {
bombMaskShapes.set(mask, shape);
mask.clear();
for (const run of runs) {
mask.rect(run.left - 4, top, run.right - run.left + 8, bottom - top).fill(0xffffff);
}
}
}
const profile = effectProfile(effects);
renderSynesthesiaHolds(pool, lanes ?? [], nowMs, profile.enabled ? profile.amount : 0);
if (!profile.enabled) {
// Effects off: a small, plain core flash per hit.
renderPlainFlashes(pool, bombs);
return;
}
const tier = Math.min(comboTier(combo ?? 0), profile.screenWide ? 4 : 2);
// Keep colour the hero: when many hits overlap, dim the white parts (flash, pillar, streak) so additive stacking
// doesn't burn the line to white, while sparks keep most of their colour.
const crowd = 1 / Math.sqrt(Math.max(1, bombs.length / 2));
const multiplier = judgmentParticleMultiplier(settings);
const amount = profile.amount * multiplier;
const grains = burstGrainCount(
BURST_PARTICLES,
BURST_PARTICLES_PER_TIER,
tier,
amount,
bombs.length,
BURST_FRAME_BUDGET * multiplier,
);
const skirt = burstGrainCount(
BURST_SKIRT,
BURST_SKIRT_PER_TIER,
tier,
amount,
bombs.length,
BURST_SKIRT_FRAME_BUDGET * multiplier,
);
for (const bomb of bombs) {
renderBomb(pool, bomb, tier, crowd, profile.amount, grains, skirt);
}
}
/**
* Width (px) of a hold ember's bright core: its glow sprite is drawn larger, but fades out well inside its square, so
* this is the part kept inside the held note.
*/
const HOLD_EMBER_CORE = 8;
/** Sparks a held lane gives off at most, at full effects (`holdSparks`' default: one every 45 ms for 520 ms). */
const HOLD_SPARK_INTERVAL_MS = 45;
/**
* While a long note is held, its lane burns on the judgement line: a glow that breathes in the lane's colour, and a
* stream of embers rising from it for as long as the hold lasts. Additive, like the bursts, so a held lane reads as
* lit. `amount` thins the embers (reduced effects) and drops them at 0 (effects off), leaving only the glow.
*/
function renderSynesthesiaHolds(
pool: ChildPool,
lanes: readonly BeMusicLaneFrame[],
nowMs: number,
amount: number,
): void {
const glow = synGlowTexture();
for (const lane of lanes) {
if (lane.holding !== true || lane.holdStartedAtMs === undefined) continue;
const ageMs = nowMs - lane.holdStartedAtMs;
const light = LIGHTS[lane.kind];
const centerX = lane.x + lane.w / 2;
const halo = pool.acquireSprite();
halo.texture = glow;
halo.anchor.set(0.5);
halo.blendMode = 'add';
halo.width = Math.max(14, lane.w) * 1.8;
halo.height = Math.max(10, lane.w) * 1.4;
halo.position.set(centerX, lane.bottom - 2);
halo.tint = light.glow;
halo.alpha = 0.65 + 0.25 * Math.sin(ageMs / 90);
if (amount <= 0) continue;
// The embers stay on the held note, under its end and inside its width, so the end stays easy to see.
const sparks = holdSparks(ageMs, holdSeed(lane.channel, lane.holdStartedAtMs), lane.w, {
intervalMs: HOLD_SPARK_INTERVAL_MS / amount,
riseSpeed: 0.22,
maxRise: lane.holdTop === undefined ? undefined : lane.bottom - lane.holdTop - HOLD_EMBER_CORE / 2,
});
for (const spark of sparks) {
const ember = pool.acquireSprite();
ember.texture = glow;
ember.anchor.set(0.5);
ember.blendMode = 'add';
const size = spark.size * 5;
ember.width = size;
ember.height = size;
ember.position.set(
clampHoldSparkX(centerX + spark.offsetX, Math.min(size, HOLD_EMBER_CORE), lane.x, lane.w),
lane.bottom - spark.rise,
);
// White-hot when born, cooling into the lane's colour as it rises.
ember.tint = spark.alpha > 0.7 ? 0xffffff : light.glow;
ember.alpha = spark.alpha;
}
}
}
function renderPlainFlashes(pool: ChildPool, bombs: readonly BeMusicBomb[]): void {
const glow = synGlowTexture();
for (const bomb of bombs) {
const t = Math.min(1, bomb.elapsedMs / 180);
if (t >= 1) continue;
const sprite = pool.acquireSprite();
sprite.texture = glow;
sprite.anchor.set(0.5);
sprite.blendMode = 'add';
const size = Math.max(10, bomb.w) * (1.2 + t);
sprite.width = size;
sprite.height = size;
sprite.position.set(bomb.x + bomb.w / 2, bomb.y - 3);
sprite.tint = LIGHTS[bomb.kind].glow;
sprite.alpha = 0.7 * (1 - t);
}
}
const BOMB_LABELS = new Map<string, string>();
/** The bomb graphics' debug label for `channel`, made once per channel. */
function bombLabel(channel: string): string {
let label = BOMB_LABELS.get(channel);
if (label === undefined) {
label = `synesthesia-bomb[ch=${channel}]`;
BOMB_LABELS.set(channel, label);
}
return label;
}
const BOMB_HEAD = scratchProjected();
const BOMB_TAIL = scratchProjected();
const BOMB_POSITION: Vec3 = { x: 0, y: 0, z: 0 };
function renderBomb(
pool: ChildPool,
bomb: BeMusicBomb,
tier: number,
crowd: number,
amount: number,
grains: number,
skirt: number,
): void {
const t = Math.max(0, Math.min(1, bomb.elapsedMs / SYNESTHESIA_BOMB_DURATION_MS));
if (t >= 1) return;
const light = LIGHTS[bomb.kind];
const cx = bomb.x + bomb.w / 2;
const cy = bomb.y - 3;
const unit = Math.max(10, bomb.w);
const fade = 1 - t;
// Slow spin around the vertical axis gives the burst parallax as it expands.
const spin = (bomb.seed % 2 === 0 ? 1 : -1) * t * 0.9;
// The spin's cosine and sine once per bomb; every grain projects into the scratch results below without allocating.
const cosSpin = Math.cos(spin);
const sinSpin = Math.sin(spin);
const head = BOMB_HEAD;
const tail = BOMB_TAIL;
const position = BOMB_POSITION;
const effects = pool.acquireGraphics();
effects.label = bombLabel(bomb.channel);
effects.blendMode = 'add';
// 1. Light pillar.
const pillarH = unit * 5.5 * (0.6 + 0.4 * fade);
effects
.rect(bomb.x, cy - pillarH, bomb.w, pillarH)
.fill({ fill: resolveColumnGradient(light.glow), alpha: 0.55 * fade * fade * crowd });
// 2 + 3. Sparks: hairline trails and powder grains go through the shared batch (one fill per colour bucket instead of
// one per grain); the few coarse grains get a glow sprite. Everything here is additive, so draw order is free and no
// depth sort (or per-frame spark list) is needed.
const particles = cachedBurst(SPARKS, bomb.seed, Math.max(BURST_PARTICLES_MAX, grains));
const count = Math.min(particles.length, grains);
const radius = unit * 4.6 * (1 + 0.1 * tier);
const gravity = unit * 3.2;
// Fountain shaping: narrow the lateral spread so neighbouring lanes don't merge into one white band, and add an
// upward launch so sparks visibly leap off the line before gravity bends them back.
const fountainInto = (out: Projected, particle: BurstParticle, life: number): Projected => {
burstParticlePositionInto(position, particle, life, radius, gravity);
return projectYawedInto(
out,
position.x * 0.55,
position.y * 1.1 - unit * 2.8 * particle.speed * (1 - (1 - life) ** 2),
position.z * 0.8,
cosSpin,
sinSpin,
cx,
cy,
BURST_FOCAL,
);
};
const batch = sharedShapeBatch;
const glow = synGlowTexture();
for (let index = 0; index < count; index += 1) {
const particle = particles[index]!;
const life = t / particle.life;
if (life >= 1) continue;
fountainInto(head, particle, life);
if (!head.visible) continue;
// Only the coarser grains leave a short, hairline trail; the powder itself just drifts.
const trailAlpha = particle.size >= POWDER_TRAIL_SIZE ? (1 - life) * 0.45 : 0;
if (trailAlpha > 0.02) {
fountainInto(tail, particle, Math.max(0, life - 0.07));
batch.line(
effects,
hsvToHex(light.hue + particle.hueShift, Math.min(0.9, 0.35 + life * 2), 1),
trailAlpha,
Math.max(0.5, 1 * head.scale * particle.size),
tail.x,
tail.y,
head.x,
head.y,
);
}
const tint = hsvToHex(light.hue + particle.hueShift, Math.min(0.9, 0.45 + life * 1.8), 1);
const sparkAlpha = (1 - life) ** 0.8 * (0.65 + 0.35 * crowd);
// Powder: most grains are tiny squares; only the coarsest few carry a soft glint.
if (particle.size < POWDER_GLINT_SIZE) {
const side = Math.max(0.7, (0.6 + 1 * particle.size) * head.scale * (1 - life * 0.5));
batch.rect(effects, tint, sparkAlpha, head.x - side / 2, head.y - side / 2, side, side);
continue;
}
const sprite = pool.acquireSprite();
sprite.texture = glow;
sprite.anchor.set(0.5);
sprite.blendMode = 'add';
const size = (1.6 + 2.4 * particle.size) * head.scale * Math.sqrt(1 - life);
sprite.width = size;
sprite.height = size;
sprite.position.set(head.x, head.y);
// White-hot at launch, cooling into the lane's hue.
sprite.tint = tint;
sprite.alpha = sparkAlpha;
}
// 3b. Skirt: fine, dimmer powder thrown out sideways along the judgement line. It rises at most about a lane's width
// and settles back, so the burst reads fuller while the lanes above — where the next notes fall — stay clear.
const skirtParticles = cachedBurst(SKIRTS, bomb.seed ^ SKIRT_SEED, Math.max(BURST_SKIRT_MAX, skirt));
const skirtCount = Math.min(skirtParticles.length, skirt);
for (let index = 0; index < skirtCount; index += 1) {
const particle = skirtParticles[index]!;
const life = t / particle.life;
if (life >= 1) continue;
burstParticlePositionInto(position, particle, life, radius * 0.85, gravity);
projectYawedInto(
head,
position.x * 1.1,
Math.min(unit * 0.4, position.y * 0.25 - unit * 0.7 * particle.speed * (1 - (1 - life) ** 2)),
position.z * 0.9,
cosSpin,
sinSpin,
cx,
cy,
BURST_FOCAL,
);
if (!head.visible) continue;
const tint = hsvToHex(light.hue + particle.hueShift, Math.min(0.9, 0.55 + life * 1.5), 1);
const side = Math.max(0.6, (0.5 + 0.7 * particle.size) * head.scale * (1 - life * 0.5));
batch.rect(
effects,
tint,
(1 - life) ** 1.2 * (0.45 + 0.25 * crowd),
head.x - side / 2,
head.y - side / 2,
side,
side,
);
}
batch.flush();
// 4. Core flash + anamorphic streak.
const flash = Math.max(0, 1 - t * 5);
if (flash > 0) {
const core = pool.acquireSprite();
core.texture = glow;
core.anchor.set(0.5);
core.blendMode = 'add';
const coreSize = (unit * 1.3 + unit * 2 * t) * (SYN_GLOW_SIZE / 64);
core.width = coreSize;
core.height = coreSize;
core.position.set(cx, cy);
core.tint = hsvToHex(light.hue, t * 2, 1);
core.alpha = flash * 0.7 * crowd;
}
// 5. Lock-on: corner brackets snap in from wide to tight around the hit, then hold and fade.
if (t < 0.55) {
const snap = Math.min(1, t / 0.16);
const size = unit * (1.15 + 1.4 * (1 - snap) ** 3);
const lockAlpha = (t < 0.16 ? 0.95 : 0.95 * (1 - (t - 0.16) / 0.39)) * (0.6 + 0.4 * crowd);
drawReticle(effects, cx - size / 2, cy - size / 2, size, size, 0xfff2dc, lockAlpha, {
arm: size * 0.3,
width: 1.25,
cross: t < BOMB_CROSS_SPAN,
crossAngle: synesthesiaBombCrossAngle(t, amount),
});
}
const streakAlpha = amount < 1 ? 0 : fade ** 2.5;
if (streakAlpha > 0.02) {
const streak = pool.acquireSprite();
streak.texture = glow;
streak.anchor.set(0.5);
streak.blendMode = 'add';
streak.width = unit * (6 + 5 * t);
streak.height = Math.max(2, unit * 0.32 * fade);
streak.position.set(cx, cy);
streak.tint = hsvToHex(light.hue, 0.35, 1);
streak.alpha = streakAlpha * 0.6 * crowd;
}
}
const COLUMN_GRADIENTS = new Map<number, FillGradient>();
/** Vertical light column for `color`: transparent at the top, brightening toward the base. Local texture space. */
const BEAT_GRADIENTS = new Map<number, FillGradient>();
/** The beat wash above the judgement line in `color`: clear at the top, easing in to a soft glow at the line. */
function beatGradient(color: number): FillGradient {
let gradient = BEAT_GRADIENTS.get(color);
if (!gradient) {
const rgb = new Color(color);
gradient = new FillGradient({
type: 'linear',
start: { x: 0, y: 0 },
end: { x: 0, y: 1 },
textureSpace: 'local',
colorStops: [
{ offset: 0, color: rgb.setAlpha(0).toRgbaString() },
{ offset: 0.45, color: rgb.setAlpha(0.06).toRgbaString() },
{ offset: 0.8, color: rgb.setAlpha(0.22).toRgbaString() },
{ offset: 1, color: rgb.setAlpha(0.45).toRgbaString() },
],
});
BEAT_GRADIENTS.set(color, gradient);
}
return gradient;
}
function resolveColumnGradient(color: number): FillGradient {
let gradient = COLUMN_GRADIENTS.get(color);
if (!gradient) {
const rgb = new Color(color);
gradient = new FillGradient({
type: 'linear',
start: { x: 0, y: 0 },
end: { x: 0, y: 1 },
textureSpace: 'local',
colorStops: [
{ offset: 0, color: rgb.setAlpha(0).toRgbaString() },
{ offset: 0.5, color: rgb.setAlpha(0.1).toRgbaString() },
{ offset: 0.85, color: rgb.setAlpha(0.32).toRgbaString() },
{ offset: 1, color: rgb.setAlpha(0.6).toRgbaString() },
],
});
COLUMN_GRADIENTS.set(color, gradient);
}
return gradient;
}
|