authoravatarclover caruso<git@paperclover.net>2026-12-01 15:46:09-08:00
committeravatarclover caruso<git@paperclover.net>2026-12-01 15:49:39-08:00
logf80b0ebc6787471689dc60d888ce6ebb3bcf5b8f
treea2af7f0a847455910433499600f1f26db0ac3b64
parent4d054f69bca32d2db45fd0b038b40afd6834054b
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Wave 26 integration: restore particles/ submodules and update accuracy ledger + compatibility.md


5 files changed, 1141 insertions(+), 2465 deletions(-)

compatibility.md+15-15
......@@ -11,7 +11,7 @@ Fission currently supports **125** tool types across 2D/3D compositing, all with
1111| **Supported Tools** | **125** |
1212| **Modifiers & Animation** | **8** |
1313| **Accuracy across [paper clover](https://paperclover.net)'s compositions** | **99.5%** |
14| **Supported Tool Accuracy** | **99.5%** |
14| **Supported Tool Accuracy** | **99.7%** |
1515| **Supported Tools with 100% Accuracy** | **46** |
1616| **Coverage of Fusion's Built-in Tools** | **28.0%** |
1717| **Coverage of All Fuses on Reactor** | **0.5%** |
......@@ -22,10 +22,10 @@ Fission currently supports **125** tool types across 2D/3D compositing, all with
2222| --- | --- | --- |
2323| `Background` | ✅ 100.0% | — |
2424| `FastNoise` | ✅ 100.0% | — |
25| `Plasma` | 98.1% | — |
25| `Plasma` | 99.9% | — |
2626| `TextPlus` | 99.4% | — |
2727| `Loader` | ✅ 100.0% | — |
28| `DaySky` | 98.9% | — |
28| `DaySky` | 99.9% | — |
2929| `Fuse.CheckerPieceGenerator` | ✅ 100.0% | — |
3030
3131## Compositing & Blending
......@@ -77,7 +77,7 @@ Fission currently supports **125** tool types across 2D/3D compositing, all with
7777| `Fuse.XGlow` | 99.2%–99.8% | Octave-capped in `Fast` mode. |
7878| `ErodeDilate` | ✅ 100.0% | — |
7979| `RemoveNoise` | ✅ 100.0% | — |
80| `FilmGrain` | 96.2% | Stochastic per-frame PRNG seed differs from Fusion. |
80| `FilmGrain` | 96.3% | Stochastic per-frame PRNG seed differs from Fusion. |
8181| `Fuse.Outline` | 99.5%–99.9% | — |
8282| `Fuse.XfChroma` | 99.5%–99.9% | — |
8383| `Fuse.AlphaWeightedNoise` | Visual* | Stochastic per-pixel PRNG seed differs from Lua `math.random`. |
......@@ -133,15 +133,15 @@ Fission currently supports **125** tool types across 2D/3D compositing, all with
133133
134134| Tool | Accuracy | Notes |
135135| --- | --- | --- |
136| `pRender` | 98.4% | 2D mode only (no 3D particle renderer); stochastic PRNG seed differs. |
137| `pEmitter` | 98.2% | Stochastic PRNG seed differs; cold starts >600 frames window-simulate. |
138| `pPointForce` | 98.5% | — |
139| `pDirectionalForce` | 98.5% | — |
140| `pTurbulence` | 98.6% | — |
141| `pDrag` | 98.6% | — |
136| `pRender` | 99.7% | 2D mode only (no 3D particle renderer); stochastic PRNG seed differs. |
137| `pEmitter` | 99.8% | Stochastic PRNG seed differs; cold starts >600 frames window-simulate. |
138| `pPointForce` | 99.8% | — |
139| `pDirectionalForce` | 99.8% | — |
140| `pTurbulence` | 99.8% | — |
141| `pDrag` | 99.8% | — |
142142| `pKill` | 99.1% | — |
143143| `pMerge` | 99.7% | — |
144| `pBounce` | 98.6% | — |
144| `pBounce` | 99.8% | — |
145145
146146## 3D Pipeline
147147
......@@ -155,16 +155,16 @@ Each 3D tool's accuracy is measured by rendering it inside a lit `Merge3D` + `Ca
155155| `Transform3D` | 99.4% | — |
156156| `ImagePlane3D` | 99.2% | — |
157157| `Shape3D` | 99.9% | — |
158| `Cube3D` | 98.6% | — |
158| `Cube3D` | 99.9% | — |
159159| `SurfaceFBXMesh` | Visual* | Static mesh only (no skeletal skinning/morph animation). |
160| `Text3D` | 97.9% | Bevels not implemented. |
160| `Text3D` | 98.5% | Bevels not implemented. |
161161| `LightAmbient` | ✅ 100.0% | — |
162162| `LightDirectional` | 99.9% | Up to 4 directional lights per scene; shadow maps pending (`#46`). |
163163| `LightPoint` | 99.9% | — |
164164| `LightSpot` | 99.6% | Spot shadow maps pending (`#46`). |
165| `MtlBlinn` | 99.2% | — |
165| `MtlBlinn` | 99.6% | — |
166166| `MtlCookTorrance` | 98.9% | — |
167| `MtlPhong` | 98.9% | — |
167| `MtlPhong` | 99.4% | — |
168168| `Texture2DOperator` | 99.3% | — |
169169| `TextureTransformOperator` | 99.6% | — |
170170| `BumpMap` | 99.2% | — |
crates/engine/src/particles.rs+2-1879
......@@ -4,6 +4,8 @@
44//! `pDrag` / `pFriction`, `pKill`, `pBounce`, `pMerge`, and `pRender` (2D mode).
55
66mod plan;
7mod raster;
8mod sim;
79#[cfg(test)]
810mod tests;
911
......@@ -309,1885 +311,6 @@ pub fn render_particles_2d(
309311}
310312
311313/// Per-frame particle emission, regions, forces, collisions, and simulation stepping.
312mod sim {
313 use std::collections::HashSet;
314
315 use model::{Comp, ExprEngine, Node};
316
317 use super::plan::ParticlePlan;
318 use super::{
319 MAX_PARTICLES, POINT_FORCE_SCALE, Particle, SimState, SplitMix64, TURBULENCE_SCALE,
320 VELOCITY_SCALE,
321 };
322
323 /// Advances the particle simulation by a single integer frame `frame`.
324 pub(super) fn step_simulation(
325 state: &mut SimState,
326 comp: &Comp,
327 plan: &ParticlePlan,
328 frame: i64,
329 expr: &ExprEngine,
330 ) {
331 let t = frame as f64;
332
333 // 1. Apply forces & kills to existing live particles, then integrate motion and age.
334 if !state.particles.is_empty() {
335 for (mod_id, scope) in &plan.modifiers {
336 let Some(node) = comp.nodes.get(mod_id.0) else {
337 continue;
338 };
339 apply_modifier(&mut state.particles, comp, node, scope, t, expr);
340 }
341
342 for p in &mut state.particles {
343 if !p.alive {
344 continue;
345 }
346 p.pos[0] += p.vel[0];
347 p.pos[1] += p.vel[1];
348 p.pos[2] += p.vel[2];
349 p.rot_z += p.spin_z;
350 p.age += 1.0;
351 if p.age >= p.lifespan {
352 p.alive = false;
353 }
354 }
355 state.particles.retain(|p| p.alive);
356 }
357
358 // 2. Emit new particles for `frame` (born with `age = 0.0` at their spawn region).
359 let first_new = state.particles.len();
360 for &(emitter_id, emitter_hash) in &plan.emitters {
361 if state.particles.len() >= MAX_PARTICLES {
362 break;
363 }
364 let Some(node) = comp.nodes.get(emitter_id.0) else {
365 continue;
366 };
367 emit_particles(state, comp, node, emitter_hash, frame, t, expr);
368 }
369
370 // A newborn is damped by friction and then integrated once on its birth frame; other forces
371 // only start acting next frame.
372 for (mod_id, scope) in &plan.modifiers {
373 let Some(node) = comp.nodes.get(mod_id.0) else {
374 continue;
375 };
376 if matches!(node.kind.as_str(), "pDrag" | "pFriction") {
377 apply_modifier(&mut state.particles[first_new..], comp, node, scope, t, expr);
378 }
379 }
380 for p in &mut state.particles[first_new..] {
381 for axis in 0..3 {
382 p.pos[axis] += p.vel[axis];
383 }
384 p.rot_z += p.spin_z;
385 }
386 }
387
388 fn emit_particles(
389 state: &mut SimState,
390 comp: &Comp,
391 node: &Node,
392 emitter_hash: u64,
393 frame: i64,
394 t: f64,
395 expr: &ExprEngine,
396 ) {
397 let seed = comp.eval_number(node, "RandomSeed", t, 0.0, expr).round() as i64;
398 let mut rng = SplitMix64::from_parts(seed, frame, &node.name);
399
400 let number = comp.eval_number(node, "Number", t, 10.0, expr).max(0.0);
401 let number_var = comp
402 .eval_number(node, "NumberVariance", t, 0.0, expr)
403 .max(0.0);
404
405 let rate = (number + rng.signed() * number_var).max(0.0);
406 let accum = state.emit_accum.entry(emitter_hash).or_insert(0.0);
407 *accum += rate;
408 let mut emit_count = accum.floor() as usize;
409 *accum -= emit_count as f64;
410
411 if emit_count == 0 {
412 return;
413 }
414 let remaining_cap = MAX_PARTICLES.saturating_sub(state.particles.len());
415 if emit_count > remaining_cap {
416 emit_count = remaining_cap;
417 }
418
419 let lifespan_base = comp.eval_number(node, "Lifespan", t, 100.0, expr).max(1.0);
420 let lifespan_var = comp
421 .eval_number(node, "LifespanVariance", t, 0.0, expr)
422 .max(0.0);
423 let pos_var = comp
424 .eval_number(node, "PositionVariance", t, 0.0, expr)
425 .max(0.0);
426
427 let vel_base = comp.eval_number(node, "Velocity", t, 0.0, expr);
428 let vel_var = comp
429 .eval_number(node, "VelocityVariance", t, 0.0, expr)
430 .max(0.0);
431 let angle_base = comp.eval_number(node, "Angle", t, 0.0, expr);
432 let angle_var = comp
433 .eval_number(node, "AngleVariance", t, 0.0, expr)
434 .max(0.0);
435 let angle_z_base = comp.eval_number(node, "AngleZ", t, 0.0, expr);
436 let angle_z_var = comp
437 .eval_number(node, "AngleZVariance", t, 0.0, expr)
438 .max(0.0);
439
440 let rot_z_base = comp.eval_number(node, "RotationZ", t, 0.0, expr);
441 let rot_z_var = comp
442 .eval_number(node, "RotationZVariance", t, 0.0, expr)
443 .max(0.0);
444 let spin_z_base = comp.eval_number(node, "SpinZ", t, 0.0, expr);
445 let spin_z_var = comp
446 .eval_number(node, "SpinZVariance", t, 0.0, expr)
447 .max(0.0);
448
449 let base_r = comp.eval_number(node, "ParticleStyle.Red", t, 1.0, expr);
450 let base_g = comp.eval_number(node, "ParticleStyle.Green", t, 1.0, expr);
451 let base_b = comp.eval_number(node, "ParticleStyle.Blue", t, 1.0, expr);
452 let base_a = comp.eval_number(node, "ParticleStyle.Alpha", t, 1.0, expr);
453
454 let red_lo_off = comp.eval_number(node, "ParticleStyle.RedLow", t, 0.0, expr);
455 let red_hi_off = comp.eval_number(node, "ParticleStyle.RedHigh", t, 0.0, expr);
456 let green_lo_off = comp.eval_number(node, "ParticleStyle.GreenLow", t, 0.0, expr);
457 let green_hi_off = comp.eval_number(node, "ParticleStyle.GreenHigh", t, 0.0, expr);
458 let blue_lo_off = comp.eval_number(node, "ParticleStyle.BlueLow", t, 0.0, expr);
459 let blue_hi_off = comp.eval_number(node, "ParticleStyle.BlueHigh", t, 0.0, expr);
460 let alpha_lo_off = comp.eval_number(node, "ParticleStyle.AlphaLow", t, 0.0, expr);
461 let alpha_hi_off = comp.eval_number(node, "ParticleStyle.AlphaHigh", t, 0.0, expr);
462
463 let color_var = comp.eval_number(node, "ParticleStyle.ColorVariance", t, 0.0, expr) > 0.5
464 || red_lo_off.abs() > 1e-9
465 || red_hi_off.abs() > 1e-9
466 || green_lo_off.abs() > 1e-9
467 || green_hi_off.abs() > 1e-9
468 || blue_lo_off.abs() > 1e-9
469 || blue_hi_off.abs() > 1e-9
470 || alpha_lo_off.abs() > 1e-9
471 || alpha_hi_off.abs() > 1e-9;
472
473 let r_lo = (base_r + red_lo_off).clamp(0.0, 1.0);
474 let r_hi = (base_r + red_hi_off).clamp(0.0, 1.0);
475 let g_lo = (base_g + green_lo_off).clamp(0.0, 1.0);
476 let g_hi = (base_g + green_hi_off).clamp(0.0, 1.0);
477 let b_lo = (base_b + blue_lo_off).clamp(0.0, 1.0);
478 let b_hi = (base_b + blue_hi_off).clamp(0.0, 1.0);
479 let a_lo = (base_a + alpha_lo_off).clamp(0.0, 1.0);
480 let a_hi = (base_a + alpha_hi_off).clamp(0.0, 1.0);
481
482 // Fusion's ParticleStyle.Size defaults to 0.1 across all styles.
483 let size_base = comp
484 .eval_number(node, "ParticleStyle.Size", t, 0.1, expr)
485 .max(0.0);
486 let size_var = comp
487 .eval_number(node, "ParticleStyle.SizeVariance", t, 0.0, expr)
488 .max(0.0);
489
490 let region = RegionSpec::from_node(comp, node, t, expr);
491 state.particles.reserve(emit_count);
492
493 for _ in 0..emit_count {
494 let mut pos = region.sample(&mut rng);
495 if pos_var > 0.0 {
496 pos[0] += rng.signed() * pos_var;
497 pos[1] += rng.signed() * pos_var;
498 pos[2] += rng.signed() * pos_var;
499 }
500
501 let speed = (vel_base + rng.signed() * vel_var) * VELOCITY_SCALE;
502 let ang = (angle_base + rng.signed() * angle_var).to_radians();
503 let ang_z = (angle_z_base + rng.signed() * angle_z_var).to_radians();
504 let cos_z = ang_z.cos();
505 let vel = [
506 speed * ang.cos() * cos_z,
507 speed * ang.sin() * cos_z,
508 speed * ang_z.sin(),
509 ];
510
511 let rot_z = rot_z_base + rng.signed() * rot_z_var;
512 let spin_z = spin_z_base + rng.signed() * spin_z_var;
513 let lifespan = (lifespan_base + rng.signed() * lifespan_var).max(1.0);
514 let size = (size_base + rng.signed() * size_var).max(0.0);
515
516 let color = if color_var {
517 [
518 rng.range(r_lo, r_hi) as f32,
519 rng.range(g_lo, g_hi) as f32,
520 rng.range(b_lo, b_hi) as f32,
521 rng.range(a_lo, a_hi) as f32,
522 ]
523 } else {
524 [
525 base_r.clamp(0.0, 1.0) as f32,
526 base_g.clamp(0.0, 1.0) as f32,
527 base_b.clamp(0.0, 1.0) as f32,
528 base_a.clamp(0.0, 1.0) as f32,
529 ]
530 };
531
532 state.particles.push(Particle {
533 emitter_hash,
534 pos,
535 vel,
536 rot_z,
537 spin_z,
538 age: 0.0,
539 lifespan,
540 size,
541 color,
542 alive: true,
543 });
544 }
545 }
546
547 #[derive(Clone, Copy)]
548 pub(super) enum RegionSpec {
549 Point {
550 center: [f64; 3],
551 },
552 Rect {
553 center: [f64; 3],
554 width: f64,
555 height: f64,
556 },
557 Sphere {
558 center: [f64; 3],
559 radius: f64,
560 },
561 Cube {
562 center: [f64; 3],
563 width: f64,
564 height: f64,
565 depth: f64,
566 },
567 Line {
568 start: [f64; 3],
569 end: [f64; 3],
570 },
571 All,
572 }
573
574 impl RegionSpec {
575 pub(super) fn from_node(comp: &Comp, node: &Node, t: f64, expr: &ExprEngine) -> Self {
576 let region_name = node.static_str("Region").unwrap_or("SphereRgn");
577 match region_name {
578 "RectRgn" => Self::Rect {
579 center: [
580 comp.eval_number(node, "RectRgn.Translate.X", t, 0.0, expr),
581 comp.eval_number(node, "RectRgn.Translate.Y", t, 0.0, expr),
582 comp.eval_number(node, "RectRgn.Translate.Z", t, 0.0, expr),
583 ],
584 width: comp.eval_number(node, "RectRgn.Width", t, 0.1, expr).abs(),
585 height: comp.eval_number(node, "RectRgn.Height", t, 0.1, expr).abs(),
586 },
587 "SphereRgn" => Self::Sphere {
588 center: [
589 comp.eval_number(node, "SphereRgn.Translate.X", t, 0.0, expr),
590 comp.eval_number(node, "SphereRgn.Translate.Y", t, 0.0, expr),
591 comp.eval_number(node, "SphereRgn.Translate.Z", t, 0.0, expr),
592 ],
593 radius: comp.eval_number(node, "SphereRgn.Size", t, 0.1, expr).abs() * 0.5,
594 },
595 "CubeRgn" => Self::Cube {
596 center: [
597 comp.eval_number(node, "CubeRgn.Translate.X", t, 0.0, expr),
598 comp.eval_number(node, "CubeRgn.Translate.Y", t, 0.0, expr),
599 comp.eval_number(node, "CubeRgn.Translate.Z", t, 0.0, expr),
600 ],
601 width: comp.eval_number(node, "CubeRgn.Width", t, 0.1, expr).abs(),
602 height: comp.eval_number(node, "CubeRgn.Height", t, 0.1, expr).abs(),
603 depth: comp.eval_number(node, "CubeRgn.Depth", t, 0.1, expr).abs(),
604 },
605 "LineRgn" => {
606 let tx = comp.eval_number(node, "LineRgn.Translate.X", t, 0.0, expr);
607 let ty = comp.eval_number(node, "LineRgn.Translate.Y", t, 0.0, expr);
608 let tz = comp.eval_number(node, "LineRgn.Translate.Z", t, 0.0, expr);
609 Self::Line {
610 start: [
611 tx + comp.eval_number(node, "LineRgn.Start.X", t, -0.5, expr),
612 ty + comp.eval_number(node, "LineRgn.Start.Y", t, 0.0, expr),
613 tz + comp.eval_number(node, "LineRgn.Start.Z", t, 0.0, expr),
614 ],
615 end: [
616 tx + comp.eval_number(node, "LineRgn.End.X", t, 0.5, expr),
617 ty + comp.eval_number(node, "LineRgn.End.Y", t, 0.0, expr),
618 tz + comp.eval_number(node, "LineRgn.End.Z", t, 0.0, expr),
619 ],
620 }
621 }
622 "AllRgn" | "All" => Self::All,
623 _ => Self::Point {
624 center: [
625 comp.eval_number(node, "Point.Translate.X", t, 0.0, expr),
626 comp.eval_number(node, "Point.Translate.Y", t, 0.0, expr),
627 comp.eval_number(node, "Point.Translate.Z", t, 0.0, expr),
628 ],
629 },
630 }
631 }
632
633 fn sample(&self, rng: &mut SplitMix64) -> [f64; 3] {
634 match *self {
635 Self::Point { center } => center,
636 Self::Rect {
637 center,
638 width,
639 height,
640 } => [
641 center[0] + (rng.next_f64() - 0.5) * width,
642 center[1] + (rng.next_f64() - 0.5) * height,
643 center[2],
644 ],
645 Self::Sphere { center, radius } => {
646 let u = rng.next_f64();
647 let v = rng.next_f64();
648 let w = rng.next_f64();
649 let theta = u * std::f64::consts::TAU;
650 let cos_phi = 2.0 * v - 1.0;
651 let sin_phi = (1.0 - cos_phi * cos_phi).max(0.0).sqrt();
652 let r = radius * w.cbrt();
653 [
654 center[0] + r * sin_phi * theta.cos(),
655 center[1] + r * sin_phi * theta.sin(),
656 center[2] + r * cos_phi,
657 ]
658 }
659 Self::Cube {
660 center,
661 width,
662 height,
663 depth,
664 } => [
665 center[0] + (rng.next_f64() - 0.5) * width,
666 center[1] + (rng.next_f64() - 0.5) * height,
667 center[2] + (rng.next_f64() - 0.5) * depth,
668 ],
669 Self::Line { start, end } => {
670 let u = rng.next_f64();
671 [
672 start[0] + (end[0] - start[0]) * u,
673 start[1] + (end[1] - start[1]) * u,
674 start[2] + (end[2] - start[2]) * u,
675 ]
676 }
677 Self::All => [0.0, 0.0, 0.0],
678 }
679 }
680
681 fn contains(&self, p: [f64; 3]) -> bool {
682 match *self {
683 Self::All => true,
684 Self::Point { center } => {
685 let dx = p[0] - center[0];
686 let dy = p[1] - center[1];
687 let dz = p[2] - center[2];
688 dx * dx + dy * dy + dz * dz <= 1e-4
689 }
690 Self::Rect {
691 center,
692 width,
693 height,
694 } => {
695 (p[0] - center[0]).abs() <= width * 0.5
696 && (p[1] - center[1]).abs() <= height * 0.5
697 }
698 Self::Sphere { center, radius } => {
699 let dx = p[0] - center[0];
700 let dy = p[1] - center[1];
701 let dz = p[2] - center[2];
702 dx * dx + dy * dy + dz * dz <= radius * radius
703 }
704 Self::Cube {
705 center,
706 width,
707 height,
708 depth,
709 } => {
710 (p[0] - center[0]).abs() <= width * 0.5
711 && (p[1] - center[1]).abs() <= height * 0.5
712 && (p[2] - center[2]).abs() <= depth * 0.5
713 }
714 Self::Line { start, end } => {
715 let vx = end[0] - start[0];
716 let vy = end[1] - start[1];
717 let vz = end[2] - start[2];
718 let len_sq = vx * vx + vy * vy + vz * vz;
719 let u = if len_sq > 1e-9 {
720 (((p[0] - start[0]) * vx + (p[1] - start[1]) * vy + (p[2] - start[2]) * vz)
721 / len_sq)
722 .clamp(0.0, 1.0)
723 } else {
724 0.0
725 };
726 let cx = start[0] + vx * u;
727 let cy = start[1] + vy * u;
728 let cz = start[2] + vz * u;
729 let dx = p[0] - cx;
730 let dy = p[1] - cy;
731 let dz = p[2] - cz;
732 dx * dx + dy * dy + dz * dz <= 1e-3
733 }
734 }
735 }
736
737 /// Parses a `pBounce` region (supports `LineRgn`, `RectRgn`, `CubeRgn`, `SphereRgn`,
738 /// `MeshRegion`, and `Transform3DOp.Translate` fallback).
739 fn from_bounce_node(comp: &Comp, node: &Node, t: f64, expr: &ExprEngine) -> Self {
740 let tx = comp.eval_number(node, "Transform3DOp.Translate.X", t, 0.0, expr);
741 let ty = comp.eval_number(node, "Transform3DOp.Translate.Y", t, 0.0, expr);
742 let tz = comp.eval_number(node, "Transform3DOp.Translate.Z", t, 0.0, expr);
743 match node.static_str("Region") {
744 Some("RectRgn") => Self::Rect {
745 center: [
746 comp.eval_number(node, "RectRgn.Translate.X", t, tx, expr),
747 comp.eval_number(node, "RectRgn.Translate.Y", t, ty, expr),
748 comp.eval_number(node, "RectRgn.Translate.Z", t, tz, expr),
749 ],
750 width: comp.eval_number(node, "RectRgn.Width", t, 0.1, expr).abs(),
751 height: comp.eval_number(node, "RectRgn.Height", t, 0.1, expr).abs(),
752 },
753 Some("SphereRgn") => Self::Sphere {
754 center: [
755 comp.eval_number(node, "SphereRgn.Translate.X", t, tx, expr),
756 comp.eval_number(node, "SphereRgn.Translate.Y", t, ty, expr),
757 comp.eval_number(node, "SphereRgn.Translate.Z", t, tz, expr),
758 ],
759 radius: comp.eval_number(node, "SphereRgn.Size", t, 0.5, expr).abs() * 0.5,
760 },
761 Some("CubeRgn") => Self::Cube {
762 center: [
763 comp.eval_number(node, "CubeRgn.Translate.X", t, tx, expr),
764 comp.eval_number(node, "CubeRgn.Translate.Y", t, ty, expr),
765 comp.eval_number(node, "CubeRgn.Translate.Z", t, tz, expr),
766 ],
767 width: comp.eval_number(node, "CubeRgn.Width", t, 0.1, expr).abs(),
768 height: comp.eval_number(node, "CubeRgn.Height", t, 0.1, expr).abs(),
769 depth: comp.eval_number(node, "CubeRgn.Depth", t, 0.1, expr).abs(),
770 },
771 Some("LineRgn") => {
772 let lx = comp.eval_number(node, "LineRgn.Translate.X", t, tx, expr);
773 let ly = comp.eval_number(node, "LineRgn.Translate.Y", t, ty, expr);
774 let lz = comp.eval_number(node, "LineRgn.Translate.Z", t, tz, expr);
775 Self::Line {
776 start: [
777 lx + comp.eval_number(node, "LineRgn.Start.X", t, -0.5, expr),
778 ly + comp.eval_number(node, "LineRgn.Start.Y", t, 0.0, expr),
779 lz + comp.eval_number(node, "LineRgn.Start.Z", t, 0.0, expr),
780 ],
781 end: [
782 lx + comp.eval_number(node, "LineRgn.End.X", t, 0.5, expr),
783 ly + comp.eval_number(node, "LineRgn.End.Y", t, 0.0, expr),
784 lz + comp.eval_number(node, "LineRgn.End.Z", t, 0.0, expr),
785 ],
786 }
787 }
788 Some("MeshRegion") | None => Self::Point { center: [tx, ty, tz] },
789 _ => Self::from_node(comp, node, t, expr),
790 }
791 }
792
793 /// Checks whether a particle stepping `pos -> pos + vel` collides with this bounce region.
794 /// Returns `(contact_pos, outward_unit_normal)` when a reflection should occur.
795 fn bounce_collision(&self, pos: [f64; 3], vel: [f64; 3]) -> Option<([f64; 3], [f64; 3])> {
796 let next = [pos[0] + vel[0], pos[1] + vel[1], pos[2] + vel[2]];
797 match *self {
798 Self::Line { start, end } => {
799 let sx = end[0] - start[0];
800 let sy = end[1] - start[1];
801 let len_sq = sx * sx + sy * sy;
802 let len = len_sq.sqrt();
803 if len < 1e-9 {
804 return None;
805 }
806 let mut n = [-sy / len, sx / len, 0.0];
807 let d0 = (pos[0] - start[0]) * n[0] + (pos[1] - start[1]) * n[1];
808 let d1 = (next[0] - start[0]) * n[0] + (next[1] - start[1]) * n[1];
809 let crosses = (d0 * d1 <= 0.0 && (d0.abs() > 1e-12 || d1.abs() > 1e-12))
810 || d1.abs() <= 1e-4;
811 if !crosses {
812 return None;
813 }
814 let alpha = if (d0 - d1).abs() > 1e-12 {
815 (d0 / (d0 - d1)).clamp(0.0, 1.0)
816 } else {
817 1.0
818 };
819 let hit = [
820 pos[0] + vel[0] * alpha,
821 pos[1] + vel[1] * alpha,
822 pos[2] + vel[2] * alpha,
823 ];
824 let u = ((hit[0] - start[0]) * sx + (hit[1] - start[1]) * sy) / len_sq;
825 if !(-1e-4..=1.0 + 1e-4).contains(&u) {
826 return None;
827 }
828 let vn = vel[0] * n[0] + vel[1] * n[1];
829 if vn > 0.0 {
830 n[0] = -n[0];
831 n[1] = -n[1];
832 }
833 if vel[0] * n[0] + vel[1] * n[1] >= -1e-12 {
834 return None;
835 }
836 Some(([hit[0] + n[0] * 1e-5, hit[1] + n[1] * 1e-5, hit[2]], n))
837 }
838 Self::Sphere { center, radius } => {
839 if radius < 1e-6 {
840 return None;
841 }
842 let dp = [pos[0] - center[0], pos[1] - center[1], pos[2] - center[2]];
843 let dn = [next[0] - center[0], next[1] - center[1], next[2] - center[2]];
844 let r_pos = (dp[0] * dp[0] + dp[1] * dp[1] + dp[2] * dp[2]).sqrt();
845 let r_next = (dn[0] * dn[0] + dn[1] * dn[1] + dn[2] * dn[2]).sqrt();
846 if r_pos > radius && r_next > radius {
847 return None;
848 }
849 let ref_v = if r_pos > 1e-9 {
850 dp
851 } else if r_next > 1e-9 {
852 dn
853 } else {
854 [0.0, 1.0, 0.0]
855 };
856 let r_len = (ref_v[0] * ref_v[0] + ref_v[1] * ref_v[1] + ref_v[2] * ref_v[2])
857 .sqrt()
858 .max(1e-9);
859 let mut n = [ref_v[0] / r_len, ref_v[1] / r_len, ref_v[2] / r_len];
860 if r_pos < radius && r_next >= radius {
861 n = [-n[0], -n[1], -n[2]];
862 let pushed = [
863 center[0] - n[0] * (radius - 1e-5).max(0.0),
864 center[1] - n[1] * (radius - 1e-5).max(0.0),
865 center[2] - n[2] * (radius - 1e-5).max(0.0),
866 ];
867 return Some((pushed, n));
868 }
869 let pushed = [
870 center[0] + n[0] * (radius + 1e-5),
871 center[1] + n[1] * (radius + 1e-5),
872 center[2] + n[2] * (radius + 1e-5),
873 ];
874 Some((pushed, n))
875 }
876 Self::Rect {
877 center,
878 width,
879 height,
880 } => {
881 let hx = width * 0.5;
882 let hy = height * 0.5;
883 if hy < 1e-6 {
884 let line = Self::Line {
885 start: [center[0] - hx, center[1], center[2]],
886 end: [center[0] + hx, center[1], center[2]],
887 };
888 return line.bounce_collision(pos, vel);
889 }
890 if hx < 1e-6 {
891 let line = Self::Line {
892 start: [center[0], center[1] - hy, center[2]],
893 end: [center[0], center[1] + hy, center[2]],
894 };
895 return line.bounce_collision(pos, vel);
896 }
897 bounce_aabb(pos, vel, center, [hx, hy, 1e6], false)
898 }
899 Self::Cube {
900 center,
901 width,
902 height,
903 depth,
904 } => bounce_aabb(pos, vel, center, [width * 0.5, height * 0.5, depth * 0.5], true),
905 Self::Point { center } => {
906 let cy = center[1];
907 let d0 = pos[1] - cy;
908 let d1 = next[1] - cy;
909 if d0 * d1 <= 0.0 || d1.abs() <= 1e-5 {
910 let ny = if vel[1] < 0.0 {
911 1.0
912 } else if vel[1] > 0.0 {
913 -1.0
914 } else {
915 return None;
916 };
917 let alpha = if (d0 - d1).abs() > 1e-12 {
918 (d0 / (d0 - d1)).clamp(0.0, 1.0)
919 } else {
920 1.0
921 };
922 let hit = [
923 pos[0] + vel[0] * alpha,
924 cy + ny * 1e-5,
925 pos[2] + vel[2] * alpha,
926 ];
927 return Some((hit, [0.0, ny, 0.0]));
928 }
929 None
930 }
931 Self::All => None,
932 }
933 }
934 }
935
936 /// Slab-method segment-vs-AABB bounce helper (2D when `check_z == false`, 3D when `check_z == true`).
937 fn bounce_aabb(
938 pos: [f64; 3],
939 vel: [f64; 3],
940 center: [f64; 3],
941 half: [f64; 3],
942 check_z: bool,
943 ) -> Option<([f64; 3], [f64; 3])> {
944 let axes = if check_z { 3 } else { 2 };
945 let mut inside_pos = true;
946 for a in 0..axes {
947 if (pos[a] - center[a]).abs() > half[a] {
948 inside_pos = false;
949 break;
950 }
951 }
952
953 if inside_pos {
954 let mut best_axis = 0usize;
955 let mut best_pen = f64::INFINITY;
956 let mut best_sign = 1.0f64;
957 for a in 0..axes {
958 let delta = pos[a] - center[a];
959 let pen = half[a] - delta.abs();
960 if pen < best_pen {
961 best_pen = pen;
962 best_axis = a;
963 best_sign = if delta >= 0.0 { 1.0 } else { -1.0 };
964 }
965 }
966 let mut n = [0.0; 3];
967 n[best_axis] = best_sign;
968 let mut pushed = pos;
969 pushed[best_axis] = center[best_axis] + best_sign * (half[best_axis] + 1e-5);
970 return Some((pushed, n));
971 }
972
973 let mut t_min = 0.0_f64;
974 let mut t_max = 1.0_f64;
975 let mut hit_axis = 0usize;
976 let mut hit_sign = 1.0_f64;
977
978 for a in 0..axes {
979 let min_b = center[a] - half[a];
980 let max_b = center[a] + half[a];
981 if vel[a].abs() < 1e-12 {
982 if pos[a] < min_b || pos[a] > max_b {
983 return None;
984 }
985 } else {
986 let inv = 1.0 / vel[a];
987 let mut t1 = (min_b - pos[a]) * inv;
988 let mut t2 = (max_b - pos[a]) * inv;
989 let mut s = -1.0;
990 if t1 > t2 {
991 std::mem::swap(&mut t1, &mut t2);
992 s = 1.0;
993 }
994 if t1 > t_min {
995 t_min = t1;
996 hit_axis = a;
997 hit_sign = s;
998 }
999 t_max = t_max.min(t2);
1000 if t_min > t_max {
1001 return None;
1002 }
1003 }
1004 }
1005
1006 let mut n = [0.0; 3];
1007 n[hit_axis] = hit_sign;
1008 let hit = [
1009 pos[0] + vel[0] * t_min + n[0] * 1e-5,
1010 pos[1] + vel[1] * t_min + n[1] * 1e-5,
1011 pos[2] + vel[2] * t_min + n[2] * 1e-5,
1012 ];
1013 Some((hit, n))
1014 }
1015
1016 fn apply_modifier(
1017 particles: &mut [Particle],
1018 comp: &Comp,
1019 node: &Node,
1020 scope: &HashSet<u64>,
1021 t: f64,
1022 expr: &ExprEngine,
1023 ) {
1024 match node.kind.as_str() {
1025 "pPointForce" => {
1026 let strength = comp.eval_number(node, "Strength", t, 0.1, expr);
1027 if strength.abs() < 1e-12 {
1028 return;
1029 }
1030 let power = comp.eval_number(node, "Power", t, 2.0, expr);
1031 let tx = comp.eval_number(node, "Translate.X", t, 0.0, expr);
1032 let ty = comp.eval_number(node, "Translate.Y", t, 0.0, expr);
1033 let tz = comp.eval_number(node, "Translate.Z", t, 0.0, expr);
1034
1035 for p in particles.iter_mut() {
1036 if !p.alive || !scope.contains(&p.emitter_hash) {
1037 continue;
1038 }
1039 let dx = tx - p.pos[0];
1040 let dy = ty - p.pos[1];
1041 let dz = tz - p.pos[2];
1042 let dist = (dx * dx + dy * dy + dz * dz).sqrt();
1043 if dist < 1e-7 {
1044 continue;
1045 }
1046 let falloff = dist.max(0.005).powf(power);
1047 let mag = (strength * POINT_FORCE_SCALE / falloff).clamp(-0.25, 0.25);
1048 let inv_d = 1.0 / dist;
1049 p.vel[0] += dx * inv_d * mag;
1050 p.vel[1] += dy * inv_d * mag;
1051 p.vel[2] += dz * inv_d * mag;
1052 }
1053 }
1054 "pDirectionalForce" => {
1055 let strength = comp.eval_number(node, "Strength", t, 0.1, expr);
1056 if strength.abs() < 1e-12 {
1057 return;
1058 }
1059 let dir = comp
1060 .eval_number(node, "Direction", t, -90.0, expr)
1061 .to_radians();
1062 let dir_z = comp
1063 .eval_number(node, "DirectionZ", t, 0.0, expr)
1064 .to_radians();
1065 let mag = strength * VELOCITY_SCALE * VELOCITY_SCALE;
1066 let ax = mag * dir.cos() * dir_z.cos();
1067 let ay = mag * dir.sin() * dir_z.cos();
1068 let az = mag * dir_z.sin();
1069
1070 for p in particles.iter_mut() {
1071 if !p.alive || !scope.contains(&p.emitter_hash) {
1072 continue;
1073 }
1074 p.vel[0] += ax;
1075 p.vel[1] += ay;
1076 p.vel[2] += az;
1077 }
1078 }
1079 "pDrag" | "pFriction" => {
1080 let vel_fric = if node.kind == "pFriction" || !node.inputs.contains_key("Drag") {
1081 comp.eval_number(node, "VelocityFriction", t, 0.05, expr)
1082 } else {
1083 comp.eval_number(node, "Drag", t, 0.05, expr)
1084 };
1085 let damp = (1.0 - vel_fric).clamp(0.0, 1.0);
1086 let spin_damp = if node.kind == "pFriction" || node.inputs.contains_key("SpinFriction") {
1087 (1.0 - comp.eval_number(node, "SpinFriction", t, 0.05, expr)).clamp(0.0, 1.0)
1088 } else {
1089 1.0
1090 };
1091 for p in particles.iter_mut() {
1092 if !p.alive || !scope.contains(&p.emitter_hash) {
1093 continue;
1094 }
1095 p.vel[0] *= damp;
1096 p.vel[1] *= damp;
1097 p.vel[2] *= damp;
1098 p.spin_z *= spin_damp;
1099 }
1100 }
1101 "pTurbulence" => {
1102 let sx = comp.eval_number(node, "XStrength", t, 0.1, expr);
1103 let sy = comp.eval_number(node, "YStrength", t, 0.1, expr);
1104 let sz = comp.eval_number(node, "ZStrength", t, 0.1, expr);
1105 if sx.abs() < 1e-12 && sy.abs() < 1e-12 && sz.abs() < 1e-12 {
1106 return;
1107 }
1108 let density = comp.eval_number(node, "Density", t, 10.0, expr).max(0.01);
1109 let seed = comp.eval_number(node, "RandomSeed", t, 0.0, expr).round() as u64;
1110 let time_shift = t * 0.03;
1111
1112 for p in particles.iter_mut() {
1113 if !p.alive || !scope.contains(&p.emitter_hash) {
1114 continue;
1115 }
1116 let qx = p.pos[0] * density + time_shift;
1117 let qy = p.pos[1] * density - time_shift * 0.7;
1118 let qz = p.pos[2] * density;
1119 let nx = value_noise_3d(qx, qy, qz, seed);
1120 let ny =
1121 value_noise_3d(qx + 31.7, qy + 17.3, qz + 47.1, seed ^ 0x517C_C1B7_2722_0A95);
1122 let nz =
1123 value_noise_3d(qx - 19.4, qy + 53.9, qz - 11.2, seed ^ 0x9E37_79B9_7F4A_7C15);
1124 p.vel[0] += nx * sx * TURBULENCE_SCALE;
1125 p.vel[1] += ny * sy * TURBULENCE_SCALE;
1126 p.vel[2] += nz * sz * TURBULENCE_SCALE;
1127 }
1128 }
1129 "pKill" => {
1130 let region = if node.static_str("Region").is_some() {
1131 RegionSpec::from_node(comp, node, t, expr)
1132 } else {
1133 RegionSpec::All
1134 };
1135 let kill_outside = matches!(
1136 node.static_str("RegionMode"),
1137 Some("Outside") | Some("Leaving")
1138 );
1139 for p in particles.iter_mut() {
1140 if !p.alive || !scope.contains(&p.emitter_hash) {
1141 continue;
1142 }
1143 let inside = region.contains(p.pos);
1144 if (!kill_outside && inside) || (kill_outside && !inside) {
1145 p.alive = false;
1146 }
1147 }
1148 }
1149 "pBounce" => {
1150 let region = RegionSpec::from_bounce_node(comp, node, t, expr);
1151 let elasticity = comp.eval_number(node, "Elasticity", t, 1.0, expr).clamp(0.0, 2.0);
1152 let variance = comp.eval_number(node, "Variance", t, 0.0, expr).max(0.0);
1153 let friction = comp.eval_number(node, "Friction", t, 0.0, expr).clamp(0.0, 1.0);
1154 let roughness = comp.eval_number(node, "Roughness", t, 0.0, expr).max(0.0);
1155 let spin = comp.eval_number(node, "Spin", t, 0.0, expr);
1156 let seed = comp.eval_number(node, "RandomSeed", t, 0.0, expr).round() as i64;
1157 let mut rng = SplitMix64::from_parts(seed, t.round() as i64, &node.name);
1158
1159 for p in particles.iter_mut() {
1160 if !p.alive || !scope.contains(&p.emitter_hash) {
1161 continue;
1162 }
1163 let Some((pushed_pos, n)) = region.bounce_collision(p.pos, p.vel) else {
1164 continue;
1165 };
1166 let vn = p.vel[0] * n[0] + p.vel[1] * n[1] + p.vel[2] * n[2];
1167 if vn < 0.0 {
1168 let e = (elasticity * (1.0 + rng.signed() * variance)).clamp(0.0, 2.0);
1169 let t_damp = (1.0 - friction).clamp(0.0, 1.0);
1170 let vnx = vn * n[0];
1171 let vny = vn * n[1];
1172 let vnz = vn * n[2];
1173 let vtx = p.vel[0] - vnx;
1174 let vty = p.vel[1] - vny;
1175 let vtz = p.vel[2] - vnz;
1176 p.vel[0] = vtx * t_damp - vnx * e;
1177 p.vel[1] = vty * t_damp - vny * e;
1178 p.vel[2] = vtz * t_damp - vnz * e;
1179 if roughness > 1e-6 {
1180 let scatter = roughness * 0.01 * vn.abs();
1181 p.vel[0] += rng.signed() * scatter;
1182 p.vel[1] += rng.signed() * scatter;
1183 p.vel[2] += rng.signed() * scatter;
1184 }
1185 if spin.abs() > 1e-9 {
1186 p.spin_z += spin * (1.0 + 0.5 * rng.signed());
1187 }
1188 p.pos = pushed_pos;
1189 }
1190 }
1191 }
1192 _ => {}
1193 }
1194 }
1195
1196 /// Smooth deterministic 3D value noise in `[-1.0, 1.0]`.
1197 fn value_noise_3d(x: f64, y: f64, z: f64, seed: u64) -> f64 {
1198 let xi = x.floor() as i64;
1199 let yi = y.floor() as i64;
1200 let zi = z.floor() as i64;
1201 let xf = x - xi as f64;
1202 let yf = y - yi as f64;
1203 let zf = z - zi as f64;
1204
1205 let u = xf * xf * (3.0 - 2.0 * xf);
1206 let v = yf * yf * (3.0 - 2.0 * yf);
1207 let w = zf * zf * (3.0 - 2.0 * zf);
1208
1209 let n000 = lattice_hash(xi, yi, zi, seed);
1210 let n100 = lattice_hash(xi + 1, yi, zi, seed);
1211 let n010 = lattice_hash(xi, yi + 1, zi, seed);
1212 let n110 = lattice_hash(xi + 1, yi + 1, zi, seed);
1213 let n001 = lattice_hash(xi, yi, zi + 1, seed);
1214 let n101 = lattice_hash(xi + 1, yi, zi + 1, seed);
1215 let n011 = lattice_hash(xi, yi + 1, zi + 1, seed);
1216 let n111 = lattice_hash(xi + 1, yi + 1, zi + 1, seed);
1217
1218 let nx00 = n000 + (n100 - n000) * u;
1219 let nx10 = n010 + (n110 - n010) * u;
1220 let nx01 = n001 + (n101 - n001) * u;
1221 let nx11 = n011 + (n111 - n011) * u;
1222
1223 let nxy0 = nx00 + (nx10 - nx00) * v;
1224 let nxy1 = nx01 + (nx11 - nx01) * v;
1225
1226 nxy0 + (nxy1 - nxy0) * w
1227 }
1228
1229 #[inline]
1230 fn lattice_hash(x: i64, y: i64, z: i64, seed: u64) -> f64 {
1231 let mut h = seed
1232 ^ (x as u64).wrapping_mul(0x9E37_79B9_7F4A_7C15)
1233 ^ (y as u64).wrapping_mul(0xBF58_476D_1CE4_E5B9)
1234 ^ (z as u64).wrapping_mul(0x94D0_49BB_1331_11EB);
1235 h = (h ^ (h >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9);
1236 h = (h ^ (h >> 27)).wrapping_mul(0x94D0_49BB_1331_11EB);
1237 h ^= h >> 31;
1238 let unit = (h >> 11) as f64 * (1.0 / ((1u64 << 53) as f64));
1239 unit * 2.0 - 1.0
1240 }
1241}
1242
1243/// Optimized 2D particle rasterization (points, separable Gaussian blobs, NGons, and bitmap sprites).
1244mod raster {
1245 use std::collections::HashMap;
1246
1247 use model::{Comp, ExprEngine, Gradient, Node, NodeId};
1248
1249 use super::{
1250 BLOB_SIGMA_PER_SIZE, CAMERA_DISTANCE, Particle, ParticleStyleKind, SpriteImage,
1251 };
1252
1253 const INV_255: f32 = 1.0 / 255.0;
1254
1255 pub(super) struct DrawCmd {
1256 min_x: usize,
1257 max_x: usize,
1258 min_y: usize,
1259 max_y: usize,
1260 color: [f32; 4],
1261 shape: DrawShape,
1262 }
1263
1264 enum DrawShape {
1265 Point,
1266 Blob {
1267 cx: f64,
1268 cy: f64,
1269 inv_two_sigma_sq: f64,
1270 },
1271 NGon {
1272 cx: f64,
1273 cy: f64,
1274 inv_two_sigma_sq: f64,
1275 inv_half_period: f64,
1276 spike_period: f64,
1277 phase: f64,
1278 sharpness: f64,
1279 },
1280 Bitmap {
1281 emitter_idx: usize,
1282 cx: f64,
1283 cy: f64,
1284 draw_w: f64,
1285 draw_h: f64,
1286 rot_z_deg: f64,
1287 },
1288 }
1289
1290 struct EmitterRenderProps<'a> {
1291 emitter_hash: u64,
1292 style: ParticleStyleKind,
1293 /// Owned 1x1 tiny-background sprite, if applicable.
1294 tiny_sprite: Option<([f64; 2], SpriteImage)>,
1295 /// External sprite reference + nominal dimensions when not a tiny background.
1296 ext_sprite: Option<(&'a SpriteImage, [f64; 2])>,
1297 ngon_sides: f64,
1298 size_over_life: Option<&'a model::BezierSpline>,
1299 fade_in: f64,
1300 fade_out: f64,
1301 color_over_life: Option<Gradient>,
1302 }
1303
1304 impl<'a> EmitterRenderProps<'a> {
1305 #[inline]
1306 fn resolved_sprite(&self) -> Option<(&SpriteImage, [f64; 2])> {
1307 match &self.tiny_sprite {
1308 Some((nominal, sprite)) => Some((sprite, *nominal)),
1309 None => self.ext_sprite,
1310 }
1311 }
1312 }
1313
1314 fn collect_emitter_render_props<'a>(
1315 comp: &'a Comp,
1316 emitter_nodes: &HashMap<u64, NodeId>,
1317 time: f64,
1318 expr: &ExprEngine,
1319 sprites: &'a HashMap<NodeId, SpriteImage>,
1320 ) -> Vec<EmitterRenderProps<'a>> {
1321 let mut list = Vec::with_capacity(emitter_nodes.len());
1322 for (&emitter_hash, &emitter_id) in emitter_nodes {
1323 let Some(node) = comp.nodes.get(emitter_id.0) else {
1324 continue;
1325 };
1326 let style = match node.static_str("Style") {
1327 Some("ParticleStyleBitmap") => ParticleStyleKind::Bitmap,
1328 Some("ParticleStyleBlob") => ParticleStyleKind::Blob,
1329 Some("ParticleStyleNGon") => ParticleStyleKind::NGon,
1330 Some("ParticleStyleBrush") => ParticleStyleKind::Brush,
1331 _ => ParticleStyleKind::Point,
1332 };
1333 let size_over_life = node
1334 .inputs
1335 .get("ParticleStyle.SizeOverLife")
1336 .and_then(|b| b.source_op.as_deref())
1337 .and_then(|src| comp.splines.get(src));
1338 let fade_in = comp
1339 .eval_number(node, "ParticleStyle.FadeIn", time, 0.0, expr)
1340 .clamp(0.0, 1.0);
1341 let fade_out = comp
1342 .eval_number(node, "ParticleStyle.FadeOut", time, 1.0, expr)
1343 .clamp(0.0, 1.0);
1344 let color_over_life_on =
1345 comp.eval_number(node, "ParticleStyle.ColorOverLifeControls", time, 0.0, expr)
1346 > 0.5;
1347 let color_over_life = if color_over_life_on {
1348 comp.eval_gradient(node, "ParticleStyle.ColorOverLife", time)
1349 } else {
1350 None
1351 };
1352 let tiny_sprite = tiny_background_sprite(comp, node, time, expr);
1353 let ext_sprite = if tiny_sprite.is_none() && style == ParticleStyleKind::Bitmap {
1354 sprites
1355 .get(&emitter_id)
1356 .filter(|s| {
1357 s.size[0] > 0
1358 && s.size[1] > 0
1359 && s.rgba.len()
1360 >= (s.size[0] as usize)
1361 .saturating_mul(s.size[1] as usize)
1362 .saturating_mul(4)
1363 })
1364 .map(|s| (s, [s.size[0] as f64, s.size[1] as f64]))
1365 } else {
1366 None
1367 };
1368 list.push(EmitterRenderProps {
1369 emitter_hash,
1370 style,
1371 tiny_sprite,
1372 ext_sprite,
1373 ngon_sides: comp
1374 .eval_number(node, "ParticleStyleNGon.NGonSides", time, 5.0, expr)
1375 .round()
1376 .max(3.0),
1377 size_over_life,
1378 fade_in,
1379 fade_out,
1380 color_over_life,
1381 });
1382 }
1383 list
1384 }
1385
1386 /// Solid sprite for a `Background` tool narrower than 16 px.
1387 fn tiny_background_sprite(
1388 comp: &Comp,
1389 emitter: &Node,
1390 t: f64,
1391 expr: &ExprEngine,
1392 ) -> Option<([f64; 2], SpriteImage)> {
1393 let src = emitter
1394 .connected_node("ParticleStyleBitmap.DropToolsHere")
1395 .and_then(|name| comp.find_node(name))
1396 .map(|id| &comp.nodes[id.0])
1397 .filter(|n| n.kind == "Background")?;
1398 let w = comp.eval_number(src, "Width", t, 0.0, expr);
1399 let h = comp.eval_number(src, "Height", t, 0.0, expr);
1400 if !(w >= 1.0 && h >= 1.0 && (w < 16.0 || h < 16.0)) {
1401 return None;
1402 }
1403 let channel =
1404 |name: &str, default: f64| comp.eval_number(src, name, t, default, expr).clamp(0.0, 1.0);
1405 let a = channel("TopLeftAlpha", 1.0);
1406 let px = |c: f64| (c * a * 255.0 + 0.5) as u8;
1407 let rgba = vec![
1408 px(channel("TopLeftRed", 0.0)),
1409 px(channel("TopLeftGreen", 0.0)),
1410 px(channel("TopLeftBlue", 0.0)),
1411 (a * 255.0 + 0.5) as u8,
1412 ];
1413 Some(([w, h], SpriteImage { size: [1, 1], rgba }))
1414 }
1415
1416 /// Clamps a floating-point `[lo, hi]` interval to `[0, limit - 1]`, returning `None` if empty.
1417 #[inline]
1418 fn clip_bounds(lo: f64, hi: f64, limit: usize) -> Option<(usize, usize)> {
1419 if limit == 0 || !lo.is_finite() || !hi.is_finite() {
1420 return None;
1421 }
1422 let max_i = (limit - 1) as isize;
1423 let a = lo.floor() as isize;
1424 let b = hi.ceil() as isize;
1425 if b < 0 || a > max_i {
1426 return None;
1427 }
1428 let min_u = a.max(0) as usize;
1429 let max_u = b.min(max_i) as usize;
1430 (min_u <= max_u).then_some((min_u, max_u))
1431 }
1432
1433 #[allow(clippy::too_many_arguments)]
1434 pub(super) fn rasterize_particles(
1435 out: &mut [u8],
1436 scratch_accum: &mut Vec<f32>,
1437 scratch_cmds: &mut Vec<DrawCmd>,
1438 dims: [u32; 2],
1439 px_scale: f64,
1440 comp: &Comp,
1441 emitter_nodes: &HashMap<u64, NodeId>,
1442 particles: &[Particle],
1443 time: f64,
1444 expr: &ExprEngine,
1445 sprites: &HashMap<NodeId, SpriteImage>,
1446 ) {
1447 if particles.is_empty() {
1448 return;
1449 }
1450
1451 let w = dims[0] as usize;
1452 let h = dims[1] as usize;
1453 if w == 0 || h == 0 {
1454 return;
1455 }
1456 let w_f = w as f64;
1457 let h_f = h as f64;
1458
1459 let props_list = collect_emitter_render_props(comp, emitter_nodes, time, expr, sprites);
1460 if props_list.is_empty() {
1461 return;
1462 }
1463
1464 scratch_cmds.clear();
1465 if scratch_cmds.capacity() < particles.len() {
1466 scratch_cmds.reserve(particles.len() - scratch_cmds.capacity());
1467 }
1468
1469 let mut dirty_y0 = h;
1470 let mut dirty_y1 = 0usize;
1471 let mut last_hash = u64::MAX;
1472 let mut last_idx = usize::MAX;
1473
1474 for p in particles {
1475 if !p.alive {
1476 continue;
1477 }
1478 let props_idx = if p.emitter_hash == last_hash && last_idx < props_list.len() {
1479 last_idx
1480 } else {
1481 let Some(idx) = props_list.iter().position(|pr| pr.emitter_hash == p.emitter_hash)
1482 else {
1483 continue;
1484 };
1485 last_hash = p.emitter_hash;
1486 last_idx = idx;
1487 idx
1488 };
1489 let props = &props_list[props_idx];
1490
1491 let life_frac = (p.age / p.lifespan.max(1.0)).clamp(0.0, 1.0);
1492 let size_mult = props
1493 .size_over_life
1494 .map(|sp| (2.0 * sp.eval(life_frac)).max(0.0))
1495 .unwrap_or(1.0);
1496 let depth_scale = CAMERA_DISTANCE / (CAMERA_DISTANCE + p.pos[2]);
1497 if !(depth_scale > 0.0) {
1498 continue;
1499 }
1500 let size_world = p.size * size_mult * depth_scale;
1501 if size_world <= 1e-6 {
1502 continue;
1503 }
1504
1505 let mut fade = 1.0f64;
1506 if props.fade_in > 1e-6 && life_frac < props.fade_in {
1507 fade *= life_frac / props.fade_in;
1508 }
1509 if props.fade_out < 1.0 - 1e-6 && life_frac > props.fade_out {
1510 fade *= ((1.0 - life_frac) / (1.0 - props.fade_out)).max(0.0);
1511 }
1512
1513 let mut cr = p.color[0];
1514 let mut cg = p.color[1];
1515 let mut cb = p.color[2];
1516 let mut ca = p.color[3] * fade as f32;
1517 if let Some(grad) = &props.color_over_life {
1518 let g = grad.sample(life_frac);
1519 cr *= g[0];
1520 cg *= g[1];
1521 cb *= g[2];
1522 ca *= g[3];
1523 }
1524 ca = ca.clamp(0.0, 1.0);
1525 if ca <= 1e-4 {
1526 continue;
1527 }
1528
1529 let cx = (p.pos[0] * depth_scale + 0.5) * w_f;
1530 let cy = h_f * 0.5 - p.pos[1] * depth_scale * w_f;
1531
1532 if props.style == ParticleStyleKind::Bitmap {
1533 if let Some((_, nominal)) = props.resolved_sprite() {
1534 let draw_w = size_world * nominal[0] * px_scale;
1535 let draw_h = size_world * nominal[1] * px_scale;
1536 if draw_w < 0.5 || draw_h < 0.5 {
1537 continue;
1538 }
1539 let hw = draw_w * 0.5;
1540 let hh = draw_h * 0.5;
1541 let (rx, ry) = if p.rot_z.abs() <= 1e-6 {
1542 (hw + 1.0, hh + 1.0)
1543 } else {
1544 let theta = p.rot_z.to_radians();
1545 let ca_t = theta.cos().abs();
1546 let sa_t = theta.sin().abs();
1547 (hw * ca_t + hh * sa_t + 1.0, hw * sa_t + hh * ca_t + 1.0)
1548 };
1549 let Some((min_x, max_x)) = clip_bounds(cx - rx, cx + rx, w) else {
1550 continue;
1551 };
1552 let Some((min_y, max_y)) = clip_bounds(cy - ry, cy + ry, h) else {
1553 continue;
1554 };
1555 dirty_y0 = dirty_y0.min(min_y);
1556 dirty_y1 = dirty_y1.max(max_y + 1);
1557 scratch_cmds.push(DrawCmd {
1558 min_x,
1559 max_x,
1560 min_y,
1561 max_y,
1562 color: [cr, cg, cb, ca],
1563 shape: DrawShape::Bitmap {
1564 emitter_idx: props_idx,
1565 cx,
1566 cy,
1567 draw_w,
1568 draw_h,
1569 rot_z_deg: p.rot_z,
1570 },
1571 });
1572 continue;
1573 }
1574 }
1575
1576 match props.style {
1577 ParticleStyleKind::Point => {
1578 let ix = cx.floor() as isize;
1579 let iy = cy.floor() as isize;
1580 if ix < 0 || iy < 0 || ix >= w as isize || iy >= h as isize {
1581 continue;
1582 }
1583 let ux = ix as usize;
1584 let uy = iy as usize;
1585 dirty_y0 = dirty_y0.min(uy);
1586 dirty_y1 = dirty_y1.max(uy + 1);
1587 scratch_cmds.push(DrawCmd {
1588 min_x: ux,
1589 max_x: ux,
1590 min_y: uy,
1591 max_y: uy,
1592 color: [cr, cg, cb, ca],
1593 shape: DrawShape::Point,
1594 });
1595 }
1596 ParticleStyleKind::Blob | ParticleStyleKind::Bitmap => {
1597 let sigma = BLOB_SIGMA_PER_SIZE * size_world * px_scale;
1598 if sigma <= 1e-6 {
1599 continue;
1600 }
1601 let inv_two_sigma_sq = 0.5 / (sigma * sigma);
1602 let bound = (4.0 * sigma).min((((ca as f64) * 1.0e5).ln().max(0.0) / inv_two_sigma_sq).sqrt());
1603 let Some((min_x, max_x)) = clip_bounds(cx - bound, cx + bound, w) else {
1604 continue;
1605 };
1606 let Some((min_y, max_y)) = clip_bounds(cy - bound, cy + bound, h) else {
1607 continue;
1608 };
1609 dirty_y0 = dirty_y0.min(min_y);
1610 dirty_y1 = dirty_y1.max(max_y + 1);
1611 scratch_cmds.push(DrawCmd {
1612 min_x,
1613 max_x,
1614 min_y,
1615 max_y,
1616 color: [cr, cg, cb, ca],
1617 shape: DrawShape::Blob {
1618 cx,
1619 cy,
1620 inv_two_sigma_sq,
1621 },
1622 });
1623 }
1624 ParticleStyleKind::NGon => {
1625 let sigma = BLOB_SIGMA_PER_SIZE * size_world * px_scale;
1626 if sigma <= 1e-6 {
1627 continue;
1628 }
1629 let inv_two_sigma_sq = 0.5 / (sigma * sigma);
1630 let bound = (4.0 * sigma).min((((ca as f64) * 1.0e5).ln().max(0.0) / inv_two_sigma_sq).sqrt());
1631 let Some((min_x, max_x)) = clip_bounds(cx - bound, cx + bound, w) else {
1632 continue;
1633 };
1634 let Some((min_y, max_y)) = clip_bounds(cy - bound, cy + bound, h) else {
1635 continue;
1636 };
1637 let sides = props.ngon_sides;
1638 let spike_period = std::f64::consts::TAU / sides;
1639 let phase = std::f64::consts::FRAC_PI_2 + p.rot_z.to_radians();
1640 let sharpness = 4.5 * (3.0 / sides).powf(2.8);
1641 dirty_y0 = dirty_y0.min(min_y);
1642 dirty_y1 = dirty_y1.max(max_y + 1);
1643 scratch_cmds.push(DrawCmd {
1644 min_x,
1645 max_x,
1646 min_y,
1647 max_y,
1648 color: [cr, cg, cb, ca],
1649 shape: DrawShape::NGon {
1650 cx,
1651 cy,
1652 inv_two_sigma_sq,
1653 inv_half_period: 2.0 / spike_period,
1654 spike_period,
1655 phase,
1656 sharpness,
1657 },
1658 });
1659 }
1660 ParticleStyleKind::Brush => {}
1661 }
1662 }
1663
1664 if scratch_cmds.is_empty() || dirty_y0 >= dirty_y1 {
1665 return;
1666 }
1667
1668 let needed_floats = w * h * 4;
1669 if scratch_accum.len() < needed_floats {
1670 scratch_accum.resize(needed_floats, 0.0);
1671 }
1672
1673 rasterize_bands(
1674 out,
1675 &mut scratch_accum[..needed_floats],
1676 w,
1677 dirty_y0,
1678 dirty_y1,
1679 scratch_cmds,
1680 &props_list,
1681 );
1682 }
1683
1684 fn rasterize_bands(
1685 out: &mut [u8],
1686 accum: &mut [f32],
1687 w: usize,
1688 dirty_y0: usize,
1689 dirty_y1: usize,
1690 cmds: &[DrawCmd],
1691 props_list: &[EmitterRenderProps<'_>],
1692 ) {
1693 #[cfg(not(target_arch = "wasm32"))]
1694 {
1695 let dirty_rows = dirty_y1 - dirty_y0;
1696 let dirty_pixels = dirty_rows * w;
1697 if dirty_pixels >= 120_000 && dirty_rows >= 32 && cmds.len() >= 16 {
1698 let workers = std::thread::available_parallelism()
1699 .map(|n| n.get())
1700 .unwrap_or(1)
1701 .min(8)
1702 .min(dirty_rows / 16);
1703 if workers > 1 {
1704 let stride = w * 4;
1705 let rows_per_band = dirty_rows.div_ceil(workers);
1706 let accum_dirty = &mut accum[dirty_y0 * stride..dirty_y1 * stride];
1707 let out_dirty = &mut out[dirty_y0 * stride..dirty_y1 * stride];
1708 std::thread::scope(|scope| {
1709 let mut a_rest = accum_dirty;
1710 let mut o_rest = out_dirty;
1711 let mut band_y0 = dirty_y0;
1712 while band_y0 < dirty_y1 {
1713 let take_rows = rows_per_band.min(dirty_y1 - band_y0);
1714 let take_elems = take_rows * stride;
1715 let (a_band, a_next) = a_rest.split_at_mut(take_elems);
1716 let (o_band, o_next) = o_rest.split_at_mut(take_elems);
1717 a_rest = a_next;
1718 o_rest = o_next;
1719 let band_y1 = band_y0 + take_rows;
1720 scope.spawn(move || {
1721 rasterize_single_band(
1722 o_band,
1723 a_band,
1724 w,
1725 band_y0,
1726 band_y1,
1727 cmds,
1728 props_list,
1729 );
1730 });
1731 band_y0 = band_y1;
1732 }
1733 });
1734 return;
1735 }
1736 }
1737 }
1738
1739 let stride = w * 4;
1740 let start = dirty_y0 * stride;
1741 let end = dirty_y1 * stride;
1742 rasterize_single_band(
1743 &mut out[start..end],
1744 &mut accum[start..end],
1745 w,
1746 dirty_y0,
1747 dirty_y1,
1748 cmds,
1749 props_list,
1750 );
1751 }
1752
1753 fn rasterize_single_band(
1754 out_band: &mut [u8],
1755 accum_band: &mut [f32],
1756 w: usize,
1757 band_y0: usize,
1758 band_y1: usize,
1759 cmds: &[DrawCmd],
1760 props_list: &[EmitterRenderProps<'_>],
1761 ) {
1762 let stride = w * 4;
1763 let mut wx_heap: Vec<f32> = Vec::new();
1764 let mut wx_stack = [0.0f32; 64];
1765
1766 for cmd in cmds {
1767 if cmd.max_y < band_y0 || cmd.min_y >= band_y1 {
1768 continue;
1769 }
1770 let y_lo = cmd.min_y.max(band_y0);
1771 let y_hi = cmd.max_y.min(band_y1 - 1);
1772 let x_lo = cmd.min_x;
1773 let x_hi = cmd.max_x;
1774
1775 match cmd.shape {
1776 DrawShape::Point => {
1777 let pa = cmd.color[3];
1778 let off = (y_lo - band_y0) * stride + x_lo * 4;
1779 let dst = &mut accum_band[off..off + 4];
1780 if pa >= 1.0 - 1e-5 {
1781 dst[0] = cmd.color[0];
1782 dst[1] = cmd.color[1];
1783 dst[2] = cmd.color[2];
1784 dst[3] = 1.0;
1785 } else {
1786 let inv_a = 1.0 - pa;
1787 dst[0] = cmd.color[0] * pa + dst[0] * inv_a;
1788 dst[1] = cmd.color[1] * pa + dst[1] * inv_a;
1789 dst[2] = cmd.color[2] * pa + dst[2] * inv_a;
1790 dst[3] = pa + dst[3] * inv_a;
1791 }
1792 }
1793 DrawShape::Blob {
1794 cx,
1795 cy,
1796 inv_two_sigma_sq,
1797 } => {
1798 let span_x = x_hi - x_lo + 1;
1799 let wx: &mut [f32] = if span_x <= wx_stack.len() {
1800 &mut wx_stack[..span_x]
1801 } else {
1802 wx_heap.resize(span_x, 0.0);
1803 &mut wx_heap[..span_x]
1804 };
1805 for (i, w_slot) in wx.iter_mut().enumerate() {
1806 let dx = (x_lo + i) as f64 + 0.5 - cx;
1807 *w_slot = (-(dx * dx) * inv_two_sigma_sq).exp() as f32;
1808 }
1809
1810 let sa = cmd.color[3];
1811 let sr = cmd.color[0] * sa;
1812 let sg = cmd.color[1] * sa;
1813 let sb = cmd.color[2] * sa;
1814 let row_x_start = x_lo * 4;
1815 let row_x_end = (x_hi + 1) * 4;
1816
1817 for py in y_lo..=y_hi {
1818 let dy = py as f64 + 0.5 - cy;
1819 let wy = (-(dy * dy) * inv_two_sigma_sq).exp() as f32;
1820 let row_a = sa * wy;
1821 if row_a <= 1e-5 {
1822 continue;
1823 }
1824 let row_r = sr * wy;
1825 let row_g = sg * wy;
1826 let row_b = sb * wy;
1827 let row_off = (py - band_y0) * stride;
1828 let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end];
1829 for (dst, &gx) in row_pixels.chunks_exact_mut(4).zip(wx.iter()) {
1830 let pa = row_a * gx;
1831 if pa <= 1e-5 {
1832 continue;
1833 }
1834 let inv_a = 1.0 - pa;
1835 dst[0] = row_r * gx + dst[0] * inv_a;
1836 dst[1] = row_g * gx + dst[1] * inv_a;
1837 dst[2] = row_b * gx + dst[2] * inv_a;
1838 dst[3] = pa + dst[3] * inv_a;
1839 }
1840 }
1841 }
1842 DrawShape::NGon {
1843 cx,
1844 cy,
1845 inv_two_sigma_sq,
1846 inv_half_period,
1847 spike_period,
1848 phase,
1849 sharpness,
1850 } => {
1851 let span_x = x_hi - x_lo + 1;
1852 let wx: &mut [f32] = if span_x <= wx_stack.len() {
1853 &mut wx_stack[..span_x]
1854 } else {
1855 wx_heap.resize(span_x, 0.0);
1856 &mut wx_heap[..span_x]
1857 };
1858 for (i, w_slot) in wx.iter_mut().enumerate() {
1859 let dx = (x_lo + i) as f64 + 0.5 - cx;
1860 *w_slot = (-(dx * dx) * inv_two_sigma_sq).exp() as f32;
1861 }
1862
1863 let sa = cmd.color[3];
1864 let cr = cmd.color[0];
1865 let cg = cmd.color[1];
1866 let cb = cmd.color[2];
1867 let row_x_start = x_lo * 4;
1868 let row_x_end = (x_hi + 1) * 4;
1869
1870 for py in y_lo..=y_hi {
1871 let dy = py as f64 + 0.5 - cy;
1872 let wy = (-(dy * dy) * inv_two_sigma_sq).exp() as f32;
1873 let row_a = sa * wy;
1874 if row_a <= 1e-5 {
1875 continue;
1876 }
1877 let row_off = (py - band_y0) * stride;
1878 let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end];
1879 for (i, dst) in row_pixels.chunks_exact_mut(4).enumerate() {
1880 let env_a = row_a * wx[i];
1881 if env_a <= 1e-5 {
1882 continue;
1883 }
1884 let dx = (x_lo + i) as f64 + 0.5 - cx;
1885 let angle = (-dy).atan2(dx) - phase;
1886 let off = angle.rem_euclid(spike_period);
1887 let to_spike = off.min(spike_period - off);
1888 let shape_w = (1.0 - to_spike * inv_half_period).powf(sharpness) as f32;
1889 let pa = env_a * shape_w;
1890 if pa <= 1e-5 {
1891 continue;
1892 }
1893 let inv_a = 1.0 - pa;
1894 dst[0] = cr * pa + dst[0] * inv_a;
1895 dst[1] = cg * pa + dst[1] * inv_a;
1896 dst[2] = cb * pa + dst[2] * inv_a;
1897 dst[3] = pa + dst[3] * inv_a;
1898 }
1899 }
1900 }
1901 DrawShape::Bitmap {
1902 emitter_idx,
1903 cx,
1904 cy,
1905 draw_w,
1906 draw_h,
1907 rot_z_deg,
1908 } => {
1909 let Some((sprite, _)) = props_list[emitter_idx].resolved_sprite() else {
1910 continue;
1911 };
1912 draw_bitmap_band(
1913 accum_band,
1914 stride,
1915 band_y0,
1916 y_lo,
1917 y_hi,
1918 x_lo,
1919 x_hi,
1920 cx,
1921 cy,
1922 draw_w,
1923 draw_h,
1924 rot_z_deg,
1925 cmd.color,
1926 sprite,
1927 );
1928 }
1929 }
1930 }
1931
1932 // Pack premultiplied f32 -> u8 and simultaneously reset `accum_band` to 0.0
1933 // while the cache lines are hot so `scratch_accum` stays zeroed for the next frame.
1934 for (dst, src) in out_band.iter_mut().zip(accum_band.iter_mut()) {
1935 let v = *src;
1936 *src = 0.0;
1937 *dst = (v.clamp(0.0, 1.0) * 255.0 + 0.5) as u8;
1938 }
1939 }
1940
1941 #[allow(clippy::too_many_arguments)]
1942 #[inline]
1943 fn draw_bitmap_band(
1944 accum_band: &mut [f32],
1945 stride: usize,
1946 band_y0: usize,
1947 y_lo: usize,
1948 y_hi: usize,
1949 x_lo: usize,
1950 x_hi: usize,
1951 cx: f64,
1952 cy: f64,
1953 draw_w: f64,
1954 draw_h: f64,
1955 rot_z_deg: f64,
1956 tint: [f32; 4],
1957 sprite: &SpriteImage,
1958 ) {
1959 let inv_dw = 1.0 / draw_w;
1960 let inv_dh = 1.0 / draw_h;
1961 let edge_u = inv_dw * 0.5;
1962 let edge_v = inv_dh * 0.5;
1963 let inv_2edge_u = 1.0 / (2.0 * edge_u);
1964 let inv_2edge_v = 1.0 / (2.0 * edge_v);
1965 let sw_i = sprite.size[0] as usize;
1966 let sh_i = sprite.size[1] as usize;
1967 let row_x_start = x_lo * 4;
1968 let row_x_end = (x_hi + 1) * 4;
1969
1970 // Fast path: axis-aligned (unrotated) sprite.
1971 if rot_z_deg.abs() <= 1e-6 {
1972 let u0 = (x_lo as f64 + 0.5 - cx) * inv_dw + 0.5;
1973 if sw_i == 1 && sh_i == 1 {
1974 let s0 = sprite.rgba[0] as f32 * INV_255 * tint[0] * tint[3];
1975 let s1 = sprite.rgba[1] as f32 * INV_255 * tint[1] * tint[3];
1976 let s2 = sprite.rgba[2] as f32 * INV_255 * tint[2] * tint[3];
1977 let s3 = sprite.rgba[3] as f32 * INV_255 * tint[3];
1978 if s3 <= 1e-5 {
1979 return;
1980 }
1981 for py in y_lo..=y_hi {
1982 let v = (py as f64 + 0.5 - cy) * inv_dh + 0.5;
1983 if v <= -edge_v || v >= 1.0 + edge_v {
1984 continue;
1985 }
1986 let cov_v = ((v + edge_v) * inv_2edge_v)
1987 .min((1.0 + edge_v - v) * inv_2edge_v)
1988 .clamp(0.0, 1.0);
1989 if cov_v <= 1e-4 {
1990 continue;
1991 }
1992 let cov_vf = cov_v as f32;
1993 let row_off = (py - band_y0) * stride;
1994 let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end];
1995 let mut u = u0;
1996 for dst in row_pixels.chunks_exact_mut(4) {
1997 if u > -edge_u && u < 1.0 + edge_u {
1998 let cov_u = ((u + edge_u) * inv_2edge_u)
1999 .min((1.0 + edge_u - u) * inv_2edge_u)
2000 .clamp(0.0, 1.0);
2001 let cov = cov_u as f32 * cov_vf;
2002 if cov > 1e-4 {
2003 let pa = s3 * cov;
2004 if pa > 1e-5 {
2005 let inv_a = 1.0 - pa;
2006 dst[0] = s0 * cov + dst[0] * inv_a;
2007 dst[1] = s1 * cov + dst[1] * inv_a;
2008 dst[2] = s2 * cov + dst[2] * inv_a;
2009 dst[3] = pa + dst[3] * inv_a;
2010 }
2011 }
2012 }
2013 u += inv_dw;
2014 }
2015 }
2016 return;
2017 }
2018
2019 let sw_f = sw_i as f64;
2020 let sh_f = sh_i as f64;
2021 let sw_max = (sw_i - 1) as f64;
2022 let sh_max = (sh_i - 1) as f64;
2023 let tr = tint[0] * INV_255;
2024 let tg = tint[1] * INV_255;
2025 let tb = tint[2] * INV_255;
2026 let ta = tint[3] * INV_255;
2027
2028 for py in y_lo..=y_hi {
2029 let v = (py as f64 + 0.5 - cy) * inv_dh + 0.5;
2030 if v <= -edge_v || v >= 1.0 + edge_v {
2031 continue;
2032 }
2033 let cov_v = ((v + edge_v) * inv_2edge_v)
2034 .min((1.0 + edge_v - v) * inv_2edge_v)
2035 .clamp(0.0, 1.0);
2036 if cov_v <= 1e-4 {
2037 continue;
2038 }
2039 let fy = (v.clamp(0.0, 1.0) * sh_f - 0.5).clamp(0.0, sh_max);
2040 let y0 = fy.floor() as usize;
2041 let y1 = (y0 + 1).min(sh_i - 1);
2042 let ty = (fy - y0 as f64) as f32;
2043 let one_minus_ty = 1.0 - ty;
2044 let row0 = y0 * sw_i;
2045 let row1 = y1 * sw_i;
2046 let cov_vf = cov_v as f32;
2047
2048 let row_off = (py - band_y0) * stride;
2049 let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end];
2050 let mut u = u0;
2051 for dst in row_pixels.chunks_exact_mut(4) {
2052 if u > -edge_u && u < 1.0 + edge_u {
2053 let cov_u = ((u + edge_u) * inv_2edge_u)
2054 .min((1.0 + edge_u - u) * inv_2edge_u)
2055 .clamp(0.0, 1.0);
2056 let cov = cov_u as f32 * cov_vf;
2057 if cov > 1e-4 {
2058 let fx = (u.clamp(0.0, 1.0) * sw_f - 0.5).clamp(0.0, sw_max);
2059 let x0 = fx.floor() as usize;
2060 let x1 = (x0 + 1).min(sw_i - 1);
2061 let tx = (fx - x0 as f64) as f32;
2062 let omt = 1.0 - tx;
2063
2064 let w00 = omt * one_minus_ty;
2065 let w10 = tx * one_minus_ty;
2066 let w01 = omt * ty;
2067 let w11 = tx * ty;
2068
2069 let i00 = (row0 + x0) * 4;
2070 let i10 = (row0 + x1) * 4;
2071 let i01 = (row1 + x0) * 4;
2072 let i11 = (row1 + x1) * 4;
2073
2074 let s_a = sprite.rgba[i00 + 3] as f32 * w00
2075 + sprite.rgba[i10 + 3] as f32 * w10
2076 + sprite.rgba[i01 + 3] as f32 * w01
2077 + sprite.rgba[i11 + 3] as f32 * w11;
2078 let pa = s_a * ta * cov;
2079 if pa > 1e-5 {
2080 let s_r = sprite.rgba[i00] as f32 * w00
2081 + sprite.rgba[i10] as f32 * w10
2082 + sprite.rgba[i01] as f32 * w01
2083 + sprite.rgba[i11] as f32 * w11;
2084 let s_g = sprite.rgba[i00 + 1] as f32 * w00
2085 + sprite.rgba[i10 + 1] as f32 * w10
2086 + sprite.rgba[i01 + 1] as f32 * w01
2087 + sprite.rgba[i11 + 1] as f32 * w11;
2088 let s_b = sprite.rgba[i00 + 2] as f32 * w00
2089 + sprite.rgba[i10 + 2] as f32 * w10
2090 + sprite.rgba[i01 + 2] as f32 * w01
2091 + sprite.rgba[i11 + 2] as f32 * w11;
2092 let inv_a = 1.0 - pa;
2093 dst[0] = s_r * (tr * cov * tint[3]) + dst[0] * inv_a;
2094 dst[1] = s_g * (tg * cov * tint[3]) + dst[1] * inv_a;
2095 dst[2] = s_b * (tb * cov * tint[3]) + dst[2] * inv_a;
2096 dst[3] = pa + dst[3] * inv_a;
2097 }
2098 }
2099 }
2100 u += inv_dw;
2101 }
2102 }
2103 return;
2104 }
2105
2106 // General rotated bitmap path with incremental scanline UV stepping.
2107 let theta = rot_z_deg.to_radians();
2108 let cos_t = theta.cos();
2109 let sin_t = theta.sin();
2110 let du_dx = cos_t * inv_dw;
2111 let dv_dx = sin_t * inv_dh;
2112 let dx0 = (x_lo as f64 + 0.5) - cx;
2113 let sw_f = sw_i as f64;
2114 let sh_f = sh_i as f64;
2115 let sw_max = (sw_i - 1) as f64;
2116 let sh_max = (sh_i - 1) as f64;
2117 let tr = tint[0] * tint[3] * INV_255;
2118 let tg = tint[1] * tint[3] * INV_255;
2119 let tb = tint[2] * tint[3] * INV_255;
2120 let ta = tint[3] * INV_255;
2121
2122 for py in y_lo..=y_hi {
2123 let dy = (py as f64 + 0.5) - cy;
2124 let mut u = (dx0 * cos_t - dy * sin_t) * inv_dw + 0.5;
2125 let mut v = (dx0 * sin_t + dy * cos_t) * inv_dh + 0.5;
2126 let row_off = (py - band_y0) * stride;
2127 let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end];
2128
2129 for dst in row_pixels.chunks_exact_mut(4) {
2130 if u > -edge_u && u < 1.0 + edge_u && v > -edge_v && v < 1.0 + edge_v {
2131 let cov_u = ((u + edge_u) * inv_2edge_u)
2132 .min((1.0 + edge_u - u) * inv_2edge_u)
2133 .clamp(0.0, 1.0);
2134 let cov_v = ((v + edge_v) * inv_2edge_v)
2135 .min((1.0 + edge_v - v) * inv_2edge_v)
2136 .clamp(0.0, 1.0);
2137 let cov = (cov_u * cov_v) as f32;
2138 if cov > 1e-4 {
2139 let fx = (u.clamp(0.0, 1.0) * sw_f - 0.5).clamp(0.0, sw_max);
2140 let fy = (v.clamp(0.0, 1.0) * sh_f - 0.5).clamp(0.0, sh_max);
2141 let x0 = fx.floor() as usize;
2142 let y0 = fy.floor() as usize;
2143 let x1 = (x0 + 1).min(sw_i - 1);
2144 let y1 = (y0 + 1).min(sh_i - 1);
2145 let tx = (fx - x0 as f64) as f32;
2146 let ty = (fy - y0 as f64) as f32;
2147
2148 let w00 = (1.0 - tx) * (1.0 - ty);
2149 let w10 = tx * (1.0 - ty);
2150 let w01 = (1.0 - tx) * ty;
2151 let w11 = tx * ty;
2152
2153 let i00 = (y0 * sw_i + x0) * 4;
2154 let i10 = (y0 * sw_i + x1) * 4;
2155 let i01 = (y1 * sw_i + x0) * 4;
2156 let i11 = (y1 * sw_i + x1) * 4;
2157
2158 let s_a = sprite.rgba[i00 + 3] as f32 * w00
2159 + sprite.rgba[i10 + 3] as f32 * w10
2160 + sprite.rgba[i01 + 3] as f32 * w01
2161 + sprite.rgba[i11 + 3] as f32 * w11;
2162 let pa = s_a * ta * cov;
2163 if pa > 1e-5 {
2164 let s_r = sprite.rgba[i00] as f32 * w00
2165 + sprite.rgba[i10] as f32 * w10
2166 + sprite.rgba[i01] as f32 * w01
2167 + sprite.rgba[i11] as f32 * w11;
2168 let s_g = sprite.rgba[i00 + 1] as f32 * w00
2169 + sprite.rgba[i10 + 1] as f32 * w10
2170 + sprite.rgba[i01 + 1] as f32 * w01
2171 + sprite.rgba[i11 + 1] as f32 * w11;
2172 let s_b = sprite.rgba[i00 + 2] as f32 * w00
2173 + sprite.rgba[i10 + 2] as f32 * w10
2174 + sprite.rgba[i01 + 2] as f32 * w01
2175 + sprite.rgba[i11 + 2] as f32 * w11;
2176 let inv_a = 1.0 - pa;
2177 dst[0] = s_r * (tr * cov) + dst[0] * inv_a;
2178 dst[1] = s_g * (tg * cov) + dst[1] * inv_a;
2179 dst[2] = s_b * (tb * cov) + dst[2] * inv_a;
2180 dst[3] = pa + dst[3] * inv_a;
2181 }
2182 }
2183 }
2184 u += du_dx;
2185 v += dv_dx;
2186 }
2187 }
2188 }
2189}
2190
2191314#[cfg(test)]
2192315mod w26c_tests {
2193316 use super::*;
crates/engine/src/particles/raster.rs+736-222
......@@ -1,5 +1,3 @@
1//! 2D particle rasterization (points, blobs, NGons, and bilinear bitmap sprites).
2
31use std::collections::HashMap;
42
53use model::{Comp, ExprEngine, Gradient, Node, NodeId};
......@@ -8,10 +6,50 @@ use super::{
86 BLOB_SIGMA_PER_SIZE, CAMERA_DISTANCE, Particle, ParticleStyleKind, SpriteImage,
97};
108
9const INV_255: f32 = 1.0 / 255.0;
10
11pub(super) struct DrawCmd {
12 min_x: usize,
13 max_x: usize,
14 min_y: usize,
15 max_y: usize,
16 color: [f32; 4],
17 shape: DrawShape,
18}
19
20enum DrawShape {
21 Point,
22 Blob {
23 cx: f64,
24 cy: f64,
25 inv_two_sigma_sq: f64,
26 },
27 NGon {
28 cx: f64,
29 cy: f64,
30 inv_two_sigma_sq: f64,
31 inv_half_period: f64,
32 spike_period: f64,
33 phase: f64,
34 sharpness: f64,
35 },
36 Bitmap {
37 emitter_idx: usize,
38 cx: f64,
39 cy: f64,
40 draw_w: f64,
41 draw_h: f64,
42 rot_z_deg: f64,
43 },
44}
45
1146struct EmitterRenderProps<'a> {
12 emitter_id: NodeId,
47 emitter_hash: u64,
1348 style: ParticleStyleKind,
49 /// Owned 1x1 tiny-background sprite, if applicable.
1450 tiny_sprite: Option<([f64; 2], SpriteImage)>,
51 /// External sprite reference + nominal dimensions when not a tiny background.
52 ext_sprite: Option<(&'a SpriteImage, [f64; 2])>,
1553 ngon_sides: f64,
1654 size_over_life: Option<&'a model::BezierSpline>,
1755 fade_in: f64,
......@@ -19,21 +57,25 @@ struct EmitterRenderProps<'a> {
1957 color_over_life: Option<Gradient>,
2058}
2159
60impl<'a> EmitterRenderProps<'a> {
61 #[inline]
62 fn resolved_sprite(&self) -> Option<(&SpriteImage, [f64; 2])> {
63 match &self.tiny_sprite {
64 Some((nominal, sprite)) => Some((sprite, *nominal)),
65 None => self.ext_sprite,
66 }
67 }
68}
69
2270fn collect_emitter_render_props<'a>(
2371 comp: &'a Comp,
2472 emitter_nodes: &HashMap<u64, NodeId>,
25 particles: &[Particle],
2673 time: f64,
2774 expr: &ExprEngine,
28) -> HashMap<u64, EmitterRenderProps<'a>> {
29 let mut map = HashMap::new();
30 for p in particles {
31 if map.contains_key(&p.emitter_hash) {
32 continue;
33 }
34 let Some(&emitter_id) = emitter_nodes.get(&p.emitter_hash) else {
35 continue;
36 };
75 sprites: &'a HashMap<NodeId, SpriteImage>,
76) -> Vec<EmitterRenderProps<'a>> {
77 let mut list = Vec::with_capacity(emitter_nodes.len());
78 for (&emitter_hash, &emitter_id) in emitter_nodes {
3779 let Some(node) = comp.nodes.get(emitter_id.0) else {
3880 continue;
3981 };
......@@ -56,33 +98,48 @@ fn collect_emitter_render_props<'a>(
5698 .eval_number(node, "ParticleStyle.FadeOut", time, 1.0, expr)
5799 .clamp(0.0, 1.0);
58100 let color_over_life_on =
59 comp.eval_number(node, "ParticleStyle.ColorOverLifeControls", time, 0.0, expr) > 0.5;
101 comp.eval_number(node, "ParticleStyle.ColorOverLifeControls", time, 0.0, expr)
102 > 0.5;
60103 let color_over_life = if color_over_life_on {
61104 comp.eval_gradient(node, "ParticleStyle.ColorOverLife", time)
62105 } else {
63106 None
64107 };
65 map.insert(
66 p.emitter_hash,
67 EmitterRenderProps {
68 emitter_id,
69 style,
70 tiny_sprite: tiny_background_sprite(comp, node, time, expr),
71 ngon_sides: comp.eval_number(node, "ParticleStyleNGon.NGonSides", time, 5.0, expr).round().max(3.0),
72 size_over_life,
73 fade_in,
74 fade_out,
75 color_over_life,
76 },
77 );
108 let tiny_sprite = tiny_background_sprite(comp, node, time, expr);
109 let ext_sprite = if tiny_sprite.is_none() && style == ParticleStyleKind::Bitmap {
110 sprites
111 .get(&emitter_id)
112 .filter(|s| {
113 s.size[0] > 0
114 && s.size[1] > 0
115 && s.rgba.len()
116 >= (s.size[0] as usize)
117 .saturating_mul(s.size[1] as usize)
118 .saturating_mul(4)
119 })
120 .map(|s| (s, [s.size[0] as f64, s.size[1] as f64]))
121 } else {
122 None
123 };
124 list.push(EmitterRenderProps {
125 emitter_hash,
126 style,
127 tiny_sprite,
128 ext_sprite,
129 ngon_sides: comp
130 .eval_number(node, "ParticleStyleNGon.NGonSides", time, 5.0, expr)
131 .round()
132 .max(3.0),
133 size_over_life,
134 fade_in,
135 fade_out,
136 color_over_life,
137 });
78138 }
79 map
139 list
80140}
81141
82142/// Solid sprite for a `Background` tool narrower than 16 px.
83///
84/// The engine evaluates such tools at comp size, so the particle uses the tool's nominal
85/// `Width`/`Height` and its flat color directly.
86143fn tiny_background_sprite(
87144 comp: &Comp,
88145 emitter: &Node,
......@@ -99,7 +156,8 @@ fn tiny_background_sprite(
99156 if !(w >= 1.0 && h >= 1.0 && (w < 16.0 || h < 16.0)) {
100157 return None;
101158 }
102 let channel = |name: &str, default: f64| comp.eval_number(src, name, t, default, expr).clamp(0.0, 1.0);
159 let channel =
160 |name: &str, default: f64| comp.eval_number(src, name, t, default, expr).clamp(0.0, 1.0);
103161 let a = channel("TopLeftAlpha", 1.0);
104162 let px = |c: f64| (c * a * 255.0 + 0.5) as u8;
105163 let rgba = vec![
......@@ -111,9 +169,28 @@ fn tiny_background_sprite(
111169 Some(([w, h], SpriteImage { size: [1, 1], rgba }))
112170}
113171
172/// Clamps a floating-point `[lo, hi]` interval to `[0, limit - 1]`, returning `None` if empty.
173#[inline]
174fn clip_bounds(lo: f64, hi: f64, limit: usize) -> Option<(usize, usize)> {
175 if limit == 0 || !lo.is_finite() || !hi.is_finite() {
176 return None;
177 }
178 let max_i = (limit - 1) as isize;
179 let a = lo.floor() as isize;
180 let b = hi.ceil() as isize;
181 if b < 0 || a > max_i {
182 return None;
183 }
184 let min_u = a.max(0) as usize;
185 let max_u = b.min(max_i) as usize;
186 (min_u <= max_u).then_some((min_u, max_u))
187}
188
114189#[allow(clippy::too_many_arguments)]
115190pub(super) fn rasterize_particles(
116191 out: &mut [u8],
192 scratch_accum: &mut Vec<f32>,
193 scratch_cmds: &mut Vec<DrawCmd>,
117194 dims: [u32; 2],
118195 px_scale: f64,
119196 comp: &Comp,
......@@ -127,25 +204,47 @@ pub(super) fn rasterize_particles(
127204 return;
128205 }
129206
130 let props_map = collect_emitter_render_props(comp, emitter_nodes, particles, time, expr);
131207 let w = dims[0] as usize;
132208 let h = dims[1] as usize;
209 if w == 0 || h == 0 {
210 return;
211 }
133212 let w_f = w as f64;
134213 let h_f = h as f64;
135214
136 // Accumulate in linear-ish float premultiplied RGBA for clean blending, then pack to u8.
137 let mut accum = vec![0.0f32; w * h * 4];
215 let props_list = collect_emitter_render_props(comp, emitter_nodes, time, expr, sprites);
216 if props_list.is_empty() {
217 return;
218 }
219
220 scratch_cmds.clear();
221 if scratch_cmds.capacity() < particles.len() {
222 scratch_cmds.reserve(particles.len() - scratch_cmds.capacity());
223 }
224
225 let mut dirty_y0 = h;
226 let mut dirty_y1 = 0usize;
227 let mut last_hash = u64::MAX;
228 let mut last_idx = usize::MAX;
138229
139230 for p in particles {
140231 if !p.alive {
141232 continue;
142233 }
143 let Some(props) = props_map.get(&p.emitter_hash) else {
144 continue;
234 let props_idx = if p.emitter_hash == last_hash && last_idx < props_list.len() {
235 last_idx
236 } else {
237 let Some(idx) = props_list.iter().position(|pr| pr.emitter_hash == p.emitter_hash)
238 else {
239 continue;
240 };
241 last_hash = p.emitter_hash;
242 last_idx = idx;
243 idx
145244 };
245 let props = &props_list[props_idx];
146246
147247 let life_frac = (p.age / p.lifespan.max(1.0)).clamp(0.0, 1.0);
148 // Fusion's SizeOverLife LUT maps 0.5 -> 1.0x (0.0 -> 0x, 1.0 -> 2x).
149248 let size_mult = props
150249 .size_over_life
151250 .map(|sp| (2.0 * sp.eval(life_frac)).max(0.0))
......@@ -183,76 +282,428 @@ pub(super) fn rasterize_particles(
183282 continue;
184283 }
185284
186 // Fusion 2D particle coordinates: X in [-0.5, +0.5], Y-up with same unit scale as X.
187285 let cx = (p.pos[0] * depth_scale + 0.5) * w_f;
188286 let cy = h_f * 0.5 - p.pos[1] * depth_scale * w_f;
189287
190288 if props.style == ParticleStyleKind::Bitmap {
191 let (sprite, nominal) = match &props.tiny_sprite {
192 Some((nominal, sprite)) => (Some(sprite), *nominal),
193 None => {
194 let sprite = sprites.get(&props.emitter_id);
195 (sprite, sprite.map_or([0.0; 2], |s| [s.size[0] as f64, s.size[1] as f64]))
289 if let Some((_, nominal)) = props.resolved_sprite() {
290 let draw_w = size_world * nominal[0] * px_scale;
291 let draw_h = size_world * nominal[1] * px_scale;
292 if draw_w < 0.5 || draw_h < 0.5 {
293 continue;
196294 }
197 };
198 if let Some(sprite) = sprite.filter(|s| {
199 s.size[0] > 0
200 && s.size[1] > 0
201 && s.rgba.len() >= (s.size[0] as usize).saturating_mul(s.size[1] as usize).saturating_mul(4)
202 }) {
203 draw_bitmap_particle(
204 &mut accum,
205 w,
206 h,
207 cx,
208 cy,
209 size_world * nominal[0] * px_scale,
210 size_world * nominal[1] * px_scale,
211 p.rot_z,
212 [cr, cg, cb, ca],
213 sprite,
214 );
295 let hw = draw_w * 0.5;
296 let hh = draw_h * 0.5;
297 let (rx, ry) = if p.rot_z.abs() <= 1e-6 {
298 (hw + 1.0, hh + 1.0)
299 } else {
300 let theta = p.rot_z.to_radians();
301 let ca_t = theta.cos().abs();
302 let sa_t = theta.sin().abs();
303 (hw * ca_t + hh * sa_t + 1.0, hw * sa_t + hh * ca_t + 1.0)
304 };
305 let Some((min_x, max_x)) = clip_bounds(cx - rx, cx + rx, w) else {
306 continue;
307 };
308 let Some((min_y, max_y)) = clip_bounds(cy - ry, cy + ry, h) else {
309 continue;
310 };
311 dirty_y0 = dirty_y0.min(min_y);
312 dirty_y1 = dirty_y1.max(max_y + 1);
313 scratch_cmds.push(DrawCmd {
314 min_x,
315 max_x,
316 min_y,
317 max_y,
318 color: [cr, cg, cb, ca],
319 shape: DrawShape::Bitmap {
320 emitter_idx: props_idx,
321 cx,
322 cy,
323 draw_w,
324 draw_h,
325 rot_z_deg: p.rot_z,
326 },
327 });
215328 continue;
216329 }
217330 }
218331
219332 match props.style {
220333 ParticleStyleKind::Point => {
221 blend_pixel(&mut accum, w, h, cx.floor(), cy.floor(), [cr, cg, cb, ca]);
334 let ix = cx.floor() as isize;
335 let iy = cy.floor() as isize;
336 if ix < 0 || iy < 0 || ix >= w as isize || iy >= h as isize {
337 continue;
338 }
339 let ux = ix as usize;
340 let uy = iy as usize;
341 dirty_y0 = dirty_y0.min(uy);
342 dirty_y1 = dirty_y1.max(uy + 1);
343 scratch_cmds.push(DrawCmd {
344 min_x: ux,
345 max_x: ux,
346 min_y: uy,
347 max_y: uy,
348 color: [cr, cg, cb, ca],
349 shape: DrawShape::Point,
350 });
222351 }
223352 ParticleStyleKind::Blob | ParticleStyleKind::Bitmap => {
224353 let sigma = BLOB_SIGMA_PER_SIZE * size_world * px_scale;
225 draw_soft_particle(&mut accum, w, h, cx, cy, sigma, [cr, cg, cb, ca], |_, _| 1.0);
354 if sigma <= 1e-6 {
355 continue;
356 }
357 let inv_two_sigma_sq = 0.5 / (sigma * sigma);
358 let bound = (4.0 * sigma).min((((ca as f64) * 1.0e5).ln().max(0.0) / inv_two_sigma_sq).sqrt());
359 let Some((min_x, max_x)) = clip_bounds(cx - bound, cx + bound, w) else {
360 continue;
361 };
362 let Some((min_y, max_y)) = clip_bounds(cy - bound, cy + bound, h) else {
363 continue;
364 };
365 dirty_y0 = dirty_y0.min(min_y);
366 dirty_y1 = dirty_y1.max(max_y + 1);
367 scratch_cmds.push(DrawCmd {
368 min_x,
369 max_x,
370 min_y,
371 max_y,
372 color: [cr, cg, cb, ca],
373 shape: DrawShape::Blob {
374 cx,
375 cy,
376 inv_two_sigma_sq,
377 },
378 });
226379 }
227380 ParticleStyleKind::NGon => {
228381 let sigma = BLOB_SIGMA_PER_SIZE * size_world * px_scale;
382 if sigma <= 1e-6 {
383 continue;
384 }
385 let inv_two_sigma_sq = 0.5 / (sigma * sigma);
386 let bound = (4.0 * sigma).min((((ca as f64) * 1.0e5).ln().max(0.0) / inv_two_sigma_sq).sqrt());
387 let Some((min_x, max_x)) = clip_bounds(cx - bound, cx + bound, w) else {
388 continue;
389 };
390 let Some((min_y, max_y)) = clip_bounds(cy - bound, cy + bound, h) else {
391 continue;
392 };
229393 let sides = props.ngon_sides;
230394 let spike_period = std::f64::consts::TAU / sides;
231395 let phase = std::f64::consts::FRAC_PI_2 + p.rot_z.to_radians();
232 // Spike sharpness fitted to Fusion 21.1: alpha mass is 0.18/0.48/0.78 of a blob for 3/5/8 sides.
233396 let sharpness = 4.5 * (3.0 / sides).powf(2.8);
234 draw_soft_particle(&mut accum, w, h, cx, cy, sigma, [cr, cg, cb, ca], |dx, dy| {
235 // Distance to the nearest spike, as a fraction of half the spike period.
236 let angle = (-dy).atan2(dx) - phase;
237 let off = angle.rem_euclid(spike_period);
238 let to_spike = off.min(spike_period - off);
239 (1.0 - to_spike / (0.5 * spike_period)).powf(sharpness)
397 dirty_y0 = dirty_y0.min(min_y);
398 dirty_y1 = dirty_y1.max(max_y + 1);
399 scratch_cmds.push(DrawCmd {
400 min_x,
401 max_x,
402 min_y,
403 max_y,
404 color: [cr, cg, cb, ca],
405 shape: DrawShape::NGon {
406 cx,
407 cy,
408 inv_two_sigma_sq,
409 inv_half_period: 2.0 / spike_period,
410 spike_period,
411 phase,
412 sharpness,
413 },
240414 });
241415 }
242416 ParticleStyleKind::Brush => {}
243417 }
244418 }
245419
246 for (dst, &src) in out.iter_mut().zip(accum.iter()) {
247 *dst = (src.clamp(0.0, 1.0) * 255.0 + 0.5) as u8;
420 if scratch_cmds.is_empty() || dirty_y0 >= dirty_y1 {
421 return;
422 }
423
424 let needed_floats = w * h * 4;
425 if scratch_accum.len() < needed_floats {
426 scratch_accum.resize(needed_floats, 0.0);
248427 }
428
429 rasterize_bands(
430 out,
431 &mut scratch_accum[..needed_floats],
432 w,
433 dirty_y0,
434 dirty_y1,
435 scratch_cmds,
436 &props_list,
437 );
249438}
250439
251#[allow(clippy::too_many_arguments)]
252fn draw_bitmap_particle(
440fn rasterize_bands(
441 out: &mut [u8],
253442 accum: &mut [f32],
254443 w: usize,
255 h: usize,
444 dirty_y0: usize,
445 dirty_y1: usize,
446 cmds: &[DrawCmd],
447 props_list: &[EmitterRenderProps<'_>],
448) {
449 #[cfg(not(target_arch = "wasm32"))]
450 {
451 let dirty_rows = dirty_y1 - dirty_y0;
452 let dirty_pixels = dirty_rows * w;
453 if dirty_pixels >= 120_000 && dirty_rows >= 32 && cmds.len() >= 16 {
454 let workers = std::thread::available_parallelism()
455 .map(|n| n.get())
456 .unwrap_or(1)
457 .min(8)
458 .min(dirty_rows / 16);
459 if workers > 1 {
460 let stride = w * 4;
461 let rows_per_band = dirty_rows.div_ceil(workers);
462 let accum_dirty = &mut accum[dirty_y0 * stride..dirty_y1 * stride];
463 let out_dirty = &mut out[dirty_y0 * stride..dirty_y1 * stride];
464 std::thread::scope(|scope| {
465 let mut a_rest = accum_dirty;
466 let mut o_rest = out_dirty;
467 let mut band_y0 = dirty_y0;
468 while band_y0 < dirty_y1 {
469 let take_rows = rows_per_band.min(dirty_y1 - band_y0);
470 let take_elems = take_rows * stride;
471 let (a_band, a_next) = a_rest.split_at_mut(take_elems);
472 let (o_band, o_next) = o_rest.split_at_mut(take_elems);
473 a_rest = a_next;
474 o_rest = o_next;
475 let band_y1 = band_y0 + take_rows;
476 scope.spawn(move || {
477 rasterize_single_band(
478 o_band,
479 a_band,
480 w,
481 band_y0,
482 band_y1,
483 cmds,
484 props_list,
485 );
486 });
487 band_y0 = band_y1;
488 }
489 });
490 return;
491 }
492 }
493 }
494
495 let stride = w * 4;
496 let start = dirty_y0 * stride;
497 let end = dirty_y1 * stride;
498 rasterize_single_band(
499 &mut out[start..end],
500 &mut accum[start..end],
501 w,
502 dirty_y0,
503 dirty_y1,
504 cmds,
505 props_list,
506 );
507}
508
509fn rasterize_single_band(
510 out_band: &mut [u8],
511 accum_band: &mut [f32],
512 w: usize,
513 band_y0: usize,
514 band_y1: usize,
515 cmds: &[DrawCmd],
516 props_list: &[EmitterRenderProps<'_>],
517) {
518 let stride = w * 4;
519 let mut wx_heap: Vec<f32> = Vec::new();
520 let mut wx_stack = [0.0f32; 64];
521
522 for cmd in cmds {
523 if cmd.max_y < band_y0 || cmd.min_y >= band_y1 {
524 continue;
525 }
526 let y_lo = cmd.min_y.max(band_y0);
527 let y_hi = cmd.max_y.min(band_y1 - 1);
528 let x_lo = cmd.min_x;
529 let x_hi = cmd.max_x;
530
531 match cmd.shape {
532 DrawShape::Point => {
533 let pa = cmd.color[3];
534 let off = (y_lo - band_y0) * stride + x_lo * 4;
535 let dst = &mut accum_band[off..off + 4];
536 if pa >= 1.0 - 1e-5 {
537 dst[0] = cmd.color[0];
538 dst[1] = cmd.color[1];
539 dst[2] = cmd.color[2];
540 dst[3] = 1.0;
541 } else {
542 let inv_a = 1.0 - pa;
543 dst[0] = cmd.color[0] * pa + dst[0] * inv_a;
544 dst[1] = cmd.color[1] * pa + dst[1] * inv_a;
545 dst[2] = cmd.color[2] * pa + dst[2] * inv_a;
546 dst[3] = pa + dst[3] * inv_a;
547 }
548 }
549 DrawShape::Blob {
550 cx,
551 cy,
552 inv_two_sigma_sq,
553 } => {
554 let span_x = x_hi - x_lo + 1;
555 let wx: &mut [f32] = if span_x <= wx_stack.len() {
556 &mut wx_stack[..span_x]
557 } else {
558 wx_heap.resize(span_x, 0.0);
559 &mut wx_heap[..span_x]
560 };
561 for (i, w_slot) in wx.iter_mut().enumerate() {
562 let dx = (x_lo + i) as f64 + 0.5 - cx;
563 *w_slot = (-(dx * dx) * inv_two_sigma_sq).exp() as f32;
564 }
565
566 let sa = cmd.color[3];
567 let sr = cmd.color[0] * sa;
568 let sg = cmd.color[1] * sa;
569 let sb = cmd.color[2] * sa;
570 let row_x_start = x_lo * 4;
571 let row_x_end = (x_hi + 1) * 4;
572
573 for py in y_lo..=y_hi {
574 let dy = py as f64 + 0.5 - cy;
575 let wy = (-(dy * dy) * inv_two_sigma_sq).exp() as f32;
576 let row_a = sa * wy;
577 if row_a <= 1e-5 {
578 continue;
579 }
580 let row_r = sr * wy;
581 let row_g = sg * wy;
582 let row_b = sb * wy;
583 let row_off = (py - band_y0) * stride;
584 let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end];
585 for (dst, &gx) in row_pixels.chunks_exact_mut(4).zip(wx.iter()) {
586 let pa = row_a * gx;
587 if pa <= 1e-5 {
588 continue;
589 }
590 let inv_a = 1.0 - pa;
591 dst[0] = row_r * gx + dst[0] * inv_a;
592 dst[1] = row_g * gx + dst[1] * inv_a;
593 dst[2] = row_b * gx + dst[2] * inv_a;
594 dst[3] = pa + dst[3] * inv_a;
595 }
596 }
597 }
598 DrawShape::NGon {
599 cx,
600 cy,
601 inv_two_sigma_sq,
602 inv_half_period,
603 spike_period,
604 phase,
605 sharpness,
606 } => {
607 let span_x = x_hi - x_lo + 1;
608 let wx: &mut [f32] = if span_x <= wx_stack.len() {
609 &mut wx_stack[..span_x]
610 } else {
611 wx_heap.resize(span_x, 0.0);
612 &mut wx_heap[..span_x]
613 };
614 for (i, w_slot) in wx.iter_mut().enumerate() {
615 let dx = (x_lo + i) as f64 + 0.5 - cx;
616 *w_slot = (-(dx * dx) * inv_two_sigma_sq).exp() as f32;
617 }
618
619 let sa = cmd.color[3];
620 let cr = cmd.color[0];
621 let cg = cmd.color[1];
622 let cb = cmd.color[2];
623 let row_x_start = x_lo * 4;
624 let row_x_end = (x_hi + 1) * 4;
625
626 for py in y_lo..=y_hi {
627 let dy = py as f64 + 0.5 - cy;
628 let wy = (-(dy * dy) * inv_two_sigma_sq).exp() as f32;
629 let row_a = sa * wy;
630 if row_a <= 1e-5 {
631 continue;
632 }
633 let row_off = (py - band_y0) * stride;
634 let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end];
635 for (i, dst) in row_pixels.chunks_exact_mut(4).enumerate() {
636 let env_a = row_a * wx[i];
637 if env_a <= 1e-5 {
638 continue;
639 }
640 let dx = (x_lo + i) as f64 + 0.5 - cx;
641 let angle = (-dy).atan2(dx) - phase;
642 let off = angle.rem_euclid(spike_period);
643 let to_spike = off.min(spike_period - off);
644 let shape_w = (1.0 - to_spike * inv_half_period).powf(sharpness) as f32;
645 let pa = env_a * shape_w;
646 if pa <= 1e-5 {
647 continue;
648 }
649 let inv_a = 1.0 - pa;
650 dst[0] = cr * pa + dst[0] * inv_a;
651 dst[1] = cg * pa + dst[1] * inv_a;
652 dst[2] = cb * pa + dst[2] * inv_a;
653 dst[3] = pa + dst[3] * inv_a;
654 }
655 }
656 }
657 DrawShape::Bitmap {
658 emitter_idx,
659 cx,
660 cy,
661 draw_w,
662 draw_h,
663 rot_z_deg,
664 } => {
665 let Some((sprite, _)) = props_list[emitter_idx].resolved_sprite() else {
666 continue;
667 };
668 draw_bitmap_band(
669 accum_band,
670 stride,
671 band_y0,
672 y_lo,
673 y_hi,
674 x_lo,
675 x_hi,
676 cx,
677 cy,
678 draw_w,
679 draw_h,
680 rot_z_deg,
681 cmd.color,
682 sprite,
683 );
684 }
685 }
686 }
687
688 // Pack premultiplied f32 -> u8 and simultaneously reset `accum_band` to 0.0
689 // while the cache lines are hot so `scratch_accum` stays zeroed for the next frame.
690 for (dst, src) in out_band.iter_mut().zip(accum_band.iter_mut()) {
691 let v = *src;
692 *src = 0.0;
693 *dst = (v.clamp(0.0, 1.0) * 255.0 + 0.5) as u8;
694 }
695}
696
697#[allow(clippy::too_many_arguments)]
698#[inline]
699fn draw_bitmap_band(
700 accum_band: &mut [f32],
701 stride: usize,
702 band_y0: usize,
703 y_lo: usize,
704 y_hi: usize,
705 x_lo: usize,
706 x_hi: usize,
256707 cx: f64,
257708 cy: f64,
258709 draw_w: f64,
......@@ -261,170 +712,233 @@ fn draw_bitmap_particle(
261712 tint: [f32; 4],
262713 sprite: &SpriteImage,
263714) {
264 if draw_w < 0.5 || draw_h < 0.5 {
265 return;
266 }
267
268 let hw = draw_w * 0.5;
269 let hh = draw_h * 0.5;
270 let theta = rot_z_deg.to_radians();
271 let cos_t = theta.cos();
272 let sin_t = theta.sin();
273
274 let rx = hw * cos_t.abs() + hh * sin_t.abs() + 1.0;
275 let ry = hw * sin_t.abs() + hh * cos_t.abs() + 1.0;
276
277 let min_x = ((cx - rx).floor() as isize).max(0) as usize;
278 let max_x = ((cx + rx).ceil() as isize).min(w as isize - 1);
279 let min_y = ((cy - ry).floor() as isize).max(0) as usize;
280 let max_y = ((cy + ry).ceil() as isize).min(h as isize - 1);
281 if max_x < min_x as isize || max_y < min_y as isize {
282 return;
283 }
284
285715 let inv_dw = 1.0 / draw_w;
286716 let inv_dh = 1.0 / draw_h;
287717 let edge_u = inv_dw * 0.5;
288718 let edge_v = inv_dh * 0.5;
719 let inv_2edge_u = 1.0 / (2.0 * edge_u);
720 let inv_2edge_v = 1.0 / (2.0 * edge_v);
289721 let sw_i = sprite.size[0] as usize;
290722 let sh_i = sprite.size[1] as usize;
723 let row_x_start = x_lo * 4;
724 let row_x_end = (x_hi + 1) * 4;
725
726 // Fast path: axis-aligned (unrotated) sprite.
727 if rot_z_deg.abs() <= 1e-6 {
728 let u0 = (x_lo as f64 + 0.5 - cx) * inv_dw + 0.5;
729 if sw_i == 1 && sh_i == 1 {
730 let s0 = sprite.rgba[0] as f32 * INV_255 * tint[0] * tint[3];
731 let s1 = sprite.rgba[1] as f32 * INV_255 * tint[1] * tint[3];
732 let s2 = sprite.rgba[2] as f32 * INV_255 * tint[2] * tint[3];
733 let s3 = sprite.rgba[3] as f32 * INV_255 * tint[3];
734 if s3 <= 1e-5 {
735 return;
736 }
737 for py in y_lo..=y_hi {
738 let v = (py as f64 + 0.5 - cy) * inv_dh + 0.5;
739 if v <= -edge_v || v >= 1.0 + edge_v {
740 continue;
741 }
742 let cov_v = ((v + edge_v) * inv_2edge_v)
743 .min((1.0 + edge_v - v) * inv_2edge_v)
744 .clamp(0.0, 1.0);
745 if cov_v <= 1e-4 {
746 continue;
747 }
748 let cov_vf = cov_v as f32;
749 let row_off = (py - band_y0) * stride;
750 let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end];
751 let mut u = u0;
752 for dst in row_pixels.chunks_exact_mut(4) {
753 if u > -edge_u && u < 1.0 + edge_u {
754 let cov_u = ((u + edge_u) * inv_2edge_u)
755 .min((1.0 + edge_u - u) * inv_2edge_u)
756 .clamp(0.0, 1.0);
757 let cov = cov_u as f32 * cov_vf;
758 if cov > 1e-4 {
759 let pa = s3 * cov;
760 if pa > 1e-5 {
761 let inv_a = 1.0 - pa;
762 dst[0] = s0 * cov + dst[0] * inv_a;
763 dst[1] = s1 * cov + dst[1] * inv_a;
764 dst[2] = s2 * cov + dst[2] * inv_a;
765 dst[3] = pa + dst[3] * inv_a;
766 }
767 }
768 }
769 u += inv_dw;
770 }
771 }
772 return;
773 }
291774
292 for py in min_y..=(max_y as usize) {
293 let dy = (py as f64 + 0.5) - cy;
294 let row_off = py * w * 4;
295 for px in min_x..=(max_x as usize) {
296 let dx = (px as f64 + 0.5) - cx;
297 // Inverse rotate into sprite local space (CCW in Y-up).
298 let lx = dx * cos_t - dy * sin_t;
299 let ly = dx * sin_t + dy * cos_t;
300
301 let u = lx * inv_dw + 0.5;
302 let v = ly * inv_dh + 0.5;
303 if u <= -edge_u || u >= 1.0 + edge_u || v <= -edge_v || v >= 1.0 + edge_v {
775 let sw_f = sw_i as f64;
776 let sh_f = sh_i as f64;
777 let sw_max = (sw_i - 1) as f64;
778 let sh_max = (sh_i - 1) as f64;
779 let tr = tint[0] * INV_255;
780 let tg = tint[1] * INV_255;
781 let tb = tint[2] * INV_255;
782 let ta = tint[3] * INV_255;
783
784 for py in y_lo..=y_hi {
785 let v = (py as f64 + 0.5 - cy) * inv_dh + 0.5;
786 if v <= -edge_v || v >= 1.0 + edge_v {
304787 continue;
305788 }
306
307 // Anti-aliased border coverage (0.5px feather at edges).
308 let cov_u = ((u + edge_u) / (2.0 * edge_u))
309 .min((1.0 + edge_u - u) / (2.0 * edge_u))
310 .clamp(0.0, 1.0);
311 let cov_v = ((v + edge_v) / (2.0 * edge_v))
312 .min((1.0 + edge_v - v) / (2.0 * edge_v))
789 let cov_v = ((v + edge_v) * inv_2edge_v)
790 .min((1.0 + edge_v - v) * inv_2edge_v)
313791 .clamp(0.0, 1.0);
314 let cov = (cov_u * cov_v) as f32;
315 if cov <= 1e-4 {
792 if cov_v <= 1e-4 {
316793 continue;
317794 }
318
319 let sample = sample_sprite_bilinear(
320 &sprite.rgba,
321 sw_i,
322 sh_i,
323 u.clamp(0.0, 1.0),
324 v.clamp(0.0, 1.0),
325 );
326 let alpha_scale = tint[3] * cov;
327 let pa = sample[3] * alpha_scale;
328 if pa <= 1e-5 {
329 continue;
795 let fy = (v.clamp(0.0, 1.0) * sh_f - 0.5).clamp(0.0, sh_max);
796 let y0 = fy.floor() as usize;
797 let y1 = (y0 + 1).min(sh_i - 1);
798 let ty = (fy - y0 as f64) as f32;
799 let one_minus_ty = 1.0 - ty;
800 let row0 = y0 * sw_i;
801 let row1 = y1 * sw_i;
802 let cov_vf = cov_v as f32;
803
804 let row_off = (py - band_y0) * stride;
805 let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end];
806 let mut u = u0;
807 for dst in row_pixels.chunks_exact_mut(4) {
808 if u > -edge_u && u < 1.0 + edge_u {
809 let cov_u = ((u + edge_u) * inv_2edge_u)
810 .min((1.0 + edge_u - u) * inv_2edge_u)
811 .clamp(0.0, 1.0);
812 let cov = cov_u as f32 * cov_vf;
813 if cov > 1e-4 {
814 let fx = (u.clamp(0.0, 1.0) * sw_f - 0.5).clamp(0.0, sw_max);
815 let x0 = fx.floor() as usize;
816 let x1 = (x0 + 1).min(sw_i - 1);
817 let tx = (fx - x0 as f64) as f32;
818 let omt = 1.0 - tx;
819
820 let w00 = omt * one_minus_ty;
821 let w10 = tx * one_minus_ty;
822 let w01 = omt * ty;
823 let w11 = tx * ty;
824
825 let i00 = (row0 + x0) * 4;
826 let i10 = (row0 + x1) * 4;
827 let i01 = (row1 + x0) * 4;
828 let i11 = (row1 + x1) * 4;
829
830 let s_a = sprite.rgba[i00 + 3] as f32 * w00
831 + sprite.rgba[i10 + 3] as f32 * w10
832 + sprite.rgba[i01 + 3] as f32 * w01
833 + sprite.rgba[i11 + 3] as f32 * w11;
834 let pa = s_a * ta * cov;
835 if pa > 1e-5 {
836 let s_r = sprite.rgba[i00] as f32 * w00
837 + sprite.rgba[i10] as f32 * w10
838 + sprite.rgba[i01] as f32 * w01
839 + sprite.rgba[i11] as f32 * w11;
840 let s_g = sprite.rgba[i00 + 1] as f32 * w00
841 + sprite.rgba[i10 + 1] as f32 * w10
842 + sprite.rgba[i01 + 1] as f32 * w01
843 + sprite.rgba[i11 + 1] as f32 * w11;
844 let s_b = sprite.rgba[i00 + 2] as f32 * w00
845 + sprite.rgba[i10 + 2] as f32 * w10
846 + sprite.rgba[i01 + 2] as f32 * w01
847 + sprite.rgba[i11 + 2] as f32 * w11;
848 let inv_a = 1.0 - pa;
849 dst[0] = s_r * (tr * cov * tint[3]) + dst[0] * inv_a;
850 dst[1] = s_g * (tg * cov * tint[3]) + dst[1] * inv_a;
851 dst[2] = s_b * (tb * cov * tint[3]) + dst[2] * inv_a;
852 dst[3] = pa + dst[3] * inv_a;
853 }
854 }
855 }
856 u += inv_dw;
330857 }
331 let pr = sample[0] * tint[0] * alpha_scale;
332 let pg = sample[1] * tint[1] * alpha_scale;
333 let pb = sample[2] * tint[2] * alpha_scale;
334
335 let idx = row_off + px * 4;
336 let inv_a = 1.0 - pa;
337 accum[idx] = pr + accum[idx] * inv_a;
338 accum[idx + 1] = pg + accum[idx + 1] * inv_a;
339 accum[idx + 2] = pb + accum[idx + 2] * inv_a;
340 accum[idx + 3] = pa + accum[idx + 3] * inv_a;
341858 }
342 }
343}
344
345#[inline]
346fn sample_sprite_bilinear(rgba: &[u8], w: usize, h: usize, u: f64, v: f64) -> [f32; 4] {
347 let fx = (u * w as f64 - 0.5).clamp(0.0, (w - 1) as f64);
348 let fy = (v * h as f64 - 0.5).clamp(0.0, (h - 1) as f64);
349 let x0 = fx.floor() as usize;
350 let y0 = fy.floor() as usize;
351 let x1 = (x0 + 1).min(w - 1);
352 let y1 = (y0 + 1).min(h - 1);
353 let tx = (fx - x0 as f64) as f32;
354 let ty = (fy - y0 as f64) as f32;
355
356 let i00 = (y0 * w + x0) * 4;
357 let i10 = (y0 * w + x1) * 4;
358 let i01 = (y1 * w + x0) * 4;
359 let i11 = (y1 * w + x1) * 4;
360
361 let w00 = (1.0 - tx) * (1.0 - ty) * (1.0 / 255.0);
362 let w10 = tx * (1.0 - ty) * (1.0 / 255.0);
363 let w01 = (1.0 - tx) * ty * (1.0 / 255.0);
364 let w11 = tx * ty * (1.0 / 255.0);
365
366 [
367 rgba[i00] as f32 * w00
368 + rgba[i10] as f32 * w10
369 + rgba[i01] as f32 * w01
370 + rgba[i11] as f32 * w11,
371 rgba[i00 + 1] as f32 * w00
372 + rgba[i10 + 1] as f32 * w10
373 + rgba[i01 + 1] as f32 * w01
374 + rgba[i11 + 1] as f32 * w11,
375 rgba[i00 + 2] as f32 * w00
376 + rgba[i10 + 2] as f32 * w10
377 + rgba[i01 + 2] as f32 * w01
378 + rgba[i11 + 2] as f32 * w11,
379 rgba[i00 + 3] as f32 * w00
380 + rgba[i10 + 3] as f32 * w10
381 + rgba[i01 + 3] as f32 * w01
382 + rgba[i11 + 3] as f32 * w11,
383 ]
384}
385
386/// Source-over blends one premultiplied-accumulator pixel; out-of-bounds coordinates are ignored.
387#[inline]
388fn blend_pixel(accum: &mut [f32], w: usize, h: usize, x: f64, y: f64, color: [f32; 4]) {
389 if x < 0.0 || y < 0.0 || x >= w as f64 || y >= h as f64 {
390859 return;
391860 }
392 let pa = color[3].clamp(0.0, 1.0);
393 if pa <= 1e-5 {
394 return;
395 }
396 let idx = (y as usize * w + x as usize) * 4;
397 let inv_a = 1.0 - pa;
398 accum[idx] = color[0] * pa + accum[idx] * inv_a;
399 accum[idx + 1] = color[1] * pa + accum[idx + 1] * inv_a;
400 accum[idx + 2] = color[2] * pa + accum[idx + 2] * inv_a;
401 accum[idx + 3] = pa + accum[idx + 3] * inv_a;
402}
403861
404/// Gaussian falloff sampled at pixel centers out to `4 sigma`, scaled by `shape(dx, dy)`.
405#[allow(clippy::too_many_arguments)]
406fn draw_soft_particle(
407 accum: &mut [f32],
408 w: usize,
409 h: usize,
410 cx: f64,
411 cy: f64,
412 sigma: f64,
413 color: [f32; 4],
414 shape: impl Fn(f64, f64) -> f64,
415) {
416 let bound = 4.0 * sigma;
417 let min_x = ((cx - bound).floor() as isize).max(0);
418 let max_x = ((cx + bound).ceil() as isize).min(w as isize - 1);
419 let min_y = ((cy - bound).floor() as isize).max(0);
420 let max_y = ((cy + bound).ceil() as isize).min(h as isize - 1);
421 let inv_two_sigma_sq = 0.5 / (sigma * sigma);
422 for py in min_y..=max_y {
862 // General rotated bitmap path with incremental scanline UV stepping.
863 let theta = rot_z_deg.to_radians();
864 let cos_t = theta.cos();
865 let sin_t = theta.sin();
866 let du_dx = cos_t * inv_dw;
867 let dv_dx = sin_t * inv_dh;
868 let dx0 = (x_lo as f64 + 0.5) - cx;
869 let sw_f = sw_i as f64;
870 let sh_f = sh_i as f64;
871 let sw_max = (sw_i - 1) as f64;
872 let sh_max = (sh_i - 1) as f64;
873 let tr = tint[0] * tint[3] * INV_255;
874 let tg = tint[1] * tint[3] * INV_255;
875 let tb = tint[2] * tint[3] * INV_255;
876 let ta = tint[3] * INV_255;
877
878 for py in y_lo..=y_hi {
423879 let dy = (py as f64 + 0.5) - cy;
424 for px in min_x..=max_x {
425 let dx = (px as f64 + 0.5) - cx;
426 let cov = ((-(dx * dx + dy * dy) * inv_two_sigma_sq).exp() * shape(dx, dy)) as f32;
427 blend_pixel(accum, w, h, px as f64, py as f64, [color[0], color[1], color[2], color[3] * cov]);
880 let mut u = (dx0 * cos_t - dy * sin_t) * inv_dw + 0.5;
881 let mut v = (dx0 * sin_t + dy * cos_t) * inv_dh + 0.5;
882 let row_off = (py - band_y0) * stride;
883 let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end];
884
885 for dst in row_pixels.chunks_exact_mut(4) {
886 if u > -edge_u && u < 1.0 + edge_u && v > -edge_v && v < 1.0 + edge_v {
887 let cov_u = ((u + edge_u) * inv_2edge_u)
888 .min((1.0 + edge_u - u) * inv_2edge_u)
889 .clamp(0.0, 1.0);
890 let cov_v = ((v + edge_v) * inv_2edge_v)
891 .min((1.0 + edge_v - v) * inv_2edge_v)
892 .clamp(0.0, 1.0);
893 let cov = (cov_u * cov_v) as f32;
894 if cov > 1e-4 {
895 let fx = (u.clamp(0.0, 1.0) * sw_f - 0.5).clamp(0.0, sw_max);
896 let fy = (v.clamp(0.0, 1.0) * sh_f - 0.5).clamp(0.0, sh_max);
897 let x0 = fx.floor() as usize;
898 let y0 = fy.floor() as usize;
899 let x1 = (x0 + 1).min(sw_i - 1);
900 let y1 = (y0 + 1).min(sh_i - 1);
901 let tx = (fx - x0 as f64) as f32;
902 let ty = (fy - y0 as f64) as f32;
903
904 let w00 = (1.0 - tx) * (1.0 - ty);
905 let w10 = tx * (1.0 - ty);
906 let w01 = (1.0 - tx) * ty;
907 let w11 = tx * ty;
908
909 let i00 = (y0 * sw_i + x0) * 4;
910 let i10 = (y0 * sw_i + x1) * 4;
911 let i01 = (y1 * sw_i + x0) * 4;
912 let i11 = (y1 * sw_i + x1) * 4;
913
914 let s_a = sprite.rgba[i00 + 3] as f32 * w00
915 + sprite.rgba[i10 + 3] as f32 * w10
916 + sprite.rgba[i01 + 3] as f32 * w01
917 + sprite.rgba[i11 + 3] as f32 * w11;
918 let pa = s_a * ta * cov;
919 if pa > 1e-5 {
920 let s_r = sprite.rgba[i00] as f32 * w00
921 + sprite.rgba[i10] as f32 * w10
922 + sprite.rgba[i01] as f32 * w01
923 + sprite.rgba[i11] as f32 * w11;
924 let s_g = sprite.rgba[i00 + 1] as f32 * w00
925 + sprite.rgba[i10 + 1] as f32 * w10
926 + sprite.rgba[i01 + 1] as f32 * w01
927 + sprite.rgba[i11 + 1] as f32 * w11;
928 let s_b = sprite.rgba[i00 + 2] as f32 * w00
929 + sprite.rgba[i10 + 2] as f32 * w10
930 + sprite.rgba[i01 + 2] as f32 * w01
931 + sprite.rgba[i11 + 2] as f32 * w11;
932 let inv_a = 1.0 - pa;
933 dst[0] = s_r * (tr * cov) + dst[0] * inv_a;
934 dst[1] = s_g * (tg * cov) + dst[1] * inv_a;
935 dst[2] = s_b * (tb * cov) + dst[2] * inv_a;
936 dst[3] = pa + dst[3] * inv_a;
937 }
938 }
939 }
940 u += du_dx;
941 v += dv_dx;
428942 }
429943 }
430944}
crates/engine/src/particles/sim.rs+73-34
......@@ -1,5 +1,3 @@
1//! Per-frame particle emission, regions, forces, collisions, and simulation stepping.
2
31use std::collections::HashSet;
42
53use model::{Comp, ExprEngine, Node};
......@@ -141,24 +139,44 @@ fn emit_particles(
141139 let base_b = comp.eval_number(node, "ParticleStyle.Blue", t, 1.0, expr);
142140 let base_a = comp.eval_number(node, "ParticleStyle.Alpha", t, 1.0, expr);
143141
144 let color_var = comp.eval_number(node, "ParticleStyle.ColorVariance", t, 0.0, expr) > 0.5;
145 let r_lo = (base_r + comp.eval_number(node, "ParticleStyle.RedLow", t, 0.0, expr)).clamp(0.0, 1.0);
146 let r_hi = (base_r + comp.eval_number(node, "ParticleStyle.RedHigh", t, 0.0, expr)).clamp(0.0, 1.0);
147 let g_lo = (base_g + comp.eval_number(node, "ParticleStyle.GreenLow", t, 0.0, expr)).clamp(0.0, 1.0);
148 let g_hi = (base_g + comp.eval_number(node, "ParticleStyle.GreenHigh", t, 0.0, expr)).clamp(0.0, 1.0);
149 let b_lo = (base_b + comp.eval_number(node, "ParticleStyle.BlueLow", t, 0.0, expr)).clamp(0.0, 1.0);
150 let b_hi = (base_b + comp.eval_number(node, "ParticleStyle.BlueHigh", t, 0.0, expr)).clamp(0.0, 1.0);
151 let a_lo = (base_a + comp.eval_number(node, "ParticleStyle.AlphaLow", t, 0.0, expr)).clamp(0.0, 1.0);
152 let a_hi = (base_a + comp.eval_number(node, "ParticleStyle.AlphaHigh", t, 0.0, expr)).clamp(0.0, 1.0);
153
142 let red_lo_off = comp.eval_number(node, "ParticleStyle.RedLow", t, 0.0, expr);
143 let red_hi_off = comp.eval_number(node, "ParticleStyle.RedHigh", t, 0.0, expr);
144 let green_lo_off = comp.eval_number(node, "ParticleStyle.GreenLow", t, 0.0, expr);
145 let green_hi_off = comp.eval_number(node, "ParticleStyle.GreenHigh", t, 0.0, expr);
146 let blue_lo_off = comp.eval_number(node, "ParticleStyle.BlueLow", t, 0.0, expr);
147 let blue_hi_off = comp.eval_number(node, "ParticleStyle.BlueHigh", t, 0.0, expr);
148 let alpha_lo_off = comp.eval_number(node, "ParticleStyle.AlphaLow", t, 0.0, expr);
149 let alpha_hi_off = comp.eval_number(node, "ParticleStyle.AlphaHigh", t, 0.0, expr);
150
151 let color_var = comp.eval_number(node, "ParticleStyle.ColorVariance", t, 0.0, expr) > 0.5
152 || red_lo_off.abs() > 1e-9
153 || red_hi_off.abs() > 1e-9
154 || green_lo_off.abs() > 1e-9
155 || green_hi_off.abs() > 1e-9
156 || blue_lo_off.abs() > 1e-9
157 || blue_hi_off.abs() > 1e-9
158 || alpha_lo_off.abs() > 1e-9
159 || alpha_hi_off.abs() > 1e-9;
160
161 let r_lo = (base_r + red_lo_off).clamp(0.0, 1.0);
162 let r_hi = (base_r + red_hi_off).clamp(0.0, 1.0);
163 let g_lo = (base_g + green_lo_off).clamp(0.0, 1.0);
164 let g_hi = (base_g + green_hi_off).clamp(0.0, 1.0);
165 let b_lo = (base_b + blue_lo_off).clamp(0.0, 1.0);
166 let b_hi = (base_b + blue_hi_off).clamp(0.0, 1.0);
167 let a_lo = (base_a + alpha_lo_off).clamp(0.0, 1.0);
168 let a_hi = (base_a + alpha_hi_off).clamp(0.0, 1.0);
169
170 // Fusion's ParticleStyle.Size defaults to 0.1 across all styles.
154171 let size_base = comp
155 .eval_number(node, "ParticleStyle.Size", t, 1.0, expr)
172 .eval_number(node, "ParticleStyle.Size", t, 0.1, expr)
156173 .max(0.0);
157174 let size_var = comp
158175 .eval_number(node, "ParticleStyle.SizeVariance", t, 0.0, expr)
159176 .max(0.0);
160177
161178 let region = RegionSpec::from_node(comp, node, t, expr);
179 state.particles.reserve(emit_count);
162180
163181 for _ in 0..emit_count {
164182 let mut pos = region.sample(&mut rng);
......@@ -516,11 +534,18 @@ impl RegionSpec {
516534 if r_pos > radius && r_next > radius {
517535 return None;
518536 }
519 let ref_v = if r_pos > 1e-9 { dp } else if r_next > 1e-9 { dn } else { [0.0, 1.0, 0.0] };
520 let r_len = (ref_v[0] * ref_v[0] + ref_v[1] * ref_v[1] + ref_v[2] * ref_v[2]).sqrt().max(1e-9);
537 let ref_v = if r_pos > 1e-9 {
538 dp
539 } else if r_next > 1e-9 {
540 dn
541 } else {
542 [0.0, 1.0, 0.0]
543 };
544 let r_len = (ref_v[0] * ref_v[0] + ref_v[1] * ref_v[1] + ref_v[2] * ref_v[2])
545 .sqrt()
546 .max(1e-9);
521547 let mut n = [ref_v[0] / r_len, ref_v[1] / r_len, ref_v[2] / r_len];
522548 if r_pos < radius && r_next >= radius {
523 // Particle hitting sphere wall from inside
524549 n = [-n[0], -n[1], -n[2]];
525550 let pushed = [
526551 center[0] - n[0] * (radius - 1e-5).max(0.0),
......@@ -536,7 +561,11 @@ impl RegionSpec {
536561 ];
537562 Some((pushed, n))
538563 }
539 Self::Rect { center, width, height } => {
564 Self::Rect {
565 center,
566 width,
567 height,
568 } => {
540569 let hx = width * 0.5;
541570 let hy = height * 0.5;
542571 if hy < 1e-6 {
......@@ -555,15 +584,24 @@ impl RegionSpec {
555584 }
556585 bounce_aabb(pos, vel, center, [hx, hy, 1e6], false)
557586 }
558 Self::Cube { center, width, height, depth } => {
559 bounce_aabb(pos, vel, center, [width * 0.5, height * 0.5, depth * 0.5], true)
560 }
587 Self::Cube {
588 center,
589 width,
590 height,
591 depth,
592 } => bounce_aabb(pos, vel, center, [width * 0.5, height * 0.5, depth * 0.5], true),
561593 Self::Point { center } => {
562594 let cy = center[1];
563595 let d0 = pos[1] - cy;
564596 let d1 = next[1] - cy;
565597 if d0 * d1 <= 0.0 || d1.abs() <= 1e-5 {
566 let ny = if vel[1] < 0.0 { 1.0 } else if vel[1] > 0.0 { -1.0 } else { return None };
598 let ny = if vel[1] < 0.0 {
599 1.0
600 } else if vel[1] > 0.0 {
601 -1.0
602 } else {
603 return None;
604 };
567605 let alpha = if (d0 - d1).abs() > 1e-12 {
568606 (d0 / (d0 - d1)).clamp(0.0, 1.0)
569607 } else {
......@@ -601,7 +639,6 @@ fn bounce_aabb(
601639 }
602640
603641 if inside_pos {
604 // Already inside: push out through the closest face
605642 let mut best_axis = 0usize;
606643 let mut best_pen = f64::INFINITY;
607644 let mut best_sign = 1.0f64;
......@@ -674,7 +711,7 @@ fn apply_modifier(
674711) {
675712 match node.kind.as_str() {
676713 "pPointForce" => {
677 let strength = comp.eval_number(node, "Strength", t, 0.0, expr);
714 let strength = comp.eval_number(node, "Strength", t, 0.1, expr);
678715 if strength.abs() < 1e-12 {
679716 return;
680717 }
......@@ -728,14 +765,14 @@ fn apply_modifier(
728765 }
729766 }
730767 "pDrag" | "pFriction" => {
731 let damp = if node.kind == "pFriction" {
732 1.0 - comp.eval_number(node, "VelocityFriction", t, 0.05, expr)
768 let vel_fric = if node.kind == "pFriction" || !node.inputs.contains_key("Drag") {
769 comp.eval_number(node, "VelocityFriction", t, 0.05, expr)
733770 } else {
734 1.0 - comp.eval_number(node, "Drag", t, 0.05, expr)
735 }
736 .clamp(0.0, 1.0);
737 let spin_damp = if node.kind == "pFriction" {
738 1.0 - comp.eval_number(node, "SpinFriction", t, 0.05, expr).clamp(0.0, 1.0)
771 comp.eval_number(node, "Drag", t, 0.05, expr)
772 };
773 let damp = (1.0 - vel_fric).clamp(0.0, 1.0);
774 let spin_damp = if node.kind == "pFriction" || node.inputs.contains_key("SpinFriction") {
775 (1.0 - comp.eval_number(node, "SpinFriction", t, 0.05, expr)).clamp(0.0, 1.0)
739776 } else {
740777 1.0
741778 };
......@@ -752,11 +789,11 @@ fn apply_modifier(
752789 "pTurbulence" => {
753790 let sx = comp.eval_number(node, "XStrength", t, 0.1, expr);
754791 let sy = comp.eval_number(node, "YStrength", t, 0.1, expr);
755 let sz = comp.eval_number(node, "ZStrength", t, 0.0, expr);
792 let sz = comp.eval_number(node, "ZStrength", t, 0.1, expr);
756793 if sx.abs() < 1e-12 && sy.abs() < 1e-12 && sz.abs() < 1e-12 {
757794 return;
758795 }
759 let density = comp.eval_number(node, "Density", t, 1.0, expr).max(0.01);
796 let density = comp.eval_number(node, "Density", t, 10.0, expr).max(0.01);
760797 let seed = comp.eval_number(node, "RandomSeed", t, 0.0, expr).round() as u64;
761798 let time_shift = t * 0.03;
762799
......@@ -768,8 +805,10 @@ fn apply_modifier(
768805 let qy = p.pos[1] * density - time_shift * 0.7;
769806 let qz = p.pos[2] * density;
770807 let nx = value_noise_3d(qx, qy, qz, seed);
771 let ny = value_noise_3d(qx + 31.7, qy + 17.3, qz + 47.1, seed ^ 0x517C_C1B7_2722_0A95);
772 let nz = value_noise_3d(qx - 19.4, qy + 53.9, qz - 11.2, seed ^ 0x9E37_79B9_7F4A_7C15);
808 let ny =
809 value_noise_3d(qx + 31.7, qy + 17.3, qz + 47.1, seed ^ 0x517C_C1B7_2722_0A95);
810 let nz =
811 value_noise_3d(qx - 19.4, qy + 53.9, qz - 11.2, seed ^ 0x9E37_79B9_7F4A_7C15);
773812 p.vel[0] += nx * sx * TURBULENCE_SCALE;
774813 p.vel[1] += ny * sy * TURBULENCE_SCALE;
775814 p.vel[2] += nz * sz * TURBULENCE_SCALE;
scripts/accuracy_ledger.json+315-315
......@@ -1247,42 +1247,42 @@
12471247 "category": "Transform, Warp & Framing"
12481248 },
12491249 "Cube3D": {
1250 "mean_accuracy": 98.5569,
1251 "min_accuracy": 97.8672,
1252 "mean_alpha_accuracy": 94.9009,
1253 "min_alpha_accuracy": 92.4135,
1250 "mean_accuracy": 99.9049,
1251 "min_accuracy": 99.8407,
1252 "mean_alpha_accuracy": 99.9924,
1253 "min_alpha_accuracy": 99.9084,
12541254 "frames": 12,
1255 "timestamp": "2026-12-01T17:47:55Z",
1255 "timestamp": "2026-12-01T23:48:11Z",
12561256 "per_frame": [
12571257 {
12581258 "frame": 0,
12591259 "label": "defaults",
1260 "accuracy": 97.8672,
1261 "alpha_accuracy": 92.415
1260 "accuracy": 99.8845,
1261 "alpha_accuracy": 100.0
12621262 },
12631263 {
12641264 "frame": 1,
12651265 "label": "Left.MtlStdInputs.MaterialID=16, Front.MtlStdInputs.Diffuse.Color.Red=0.22421",
1266 "accuracy": 97.8866,
1267 "alpha_accuracy": 92.415
1266 "accuracy": 99.9081,
1267 "alpha_accuracy": 100.0
12681268 },
12691269 {
12701270 "frame": 2,
12711271 "label": "Transform3DOp.Translate.Z=-7.91602, Back.MtlStdInputs.ReceivesShadows=0, Front.MtlStdInputs.Transmittance.ColorDetail=0.89888",
1272 "accuracy": 99.8103,
1273 "alpha_accuracy": 99.5835
1272 "accuracy": 99.915,
1273 "alpha_accuracy": 100.0
12741274 },
12751275 {
12761276 "frame": 3,
12771277 "label": "Right.MtlStdInputs.Diffuse.Color.Blue=0.46754",
1278 "accuracy": 97.9141,
1279 "alpha_accuracy": 92.415
1278 "accuracy": 99.8845,
1279 "alpha_accuracy": 100.0
12801280 },
12811281 {
12821282 "frame": 4,
12831283 "label": "Back.MtlStdInputs.Specular.Color.Blue=0.70776, SurfaceCubeInputs.Controls.Tangents.Show=1",
1284 "accuracy": 97.8672,
1285 "alpha_accuracy": 92.415
1284 "accuracy": 99.8845,
1285 "alpha_accuracy": 100.0
12861286 },
12871287 {
12881288 "frame": 5,
......@@ -1293,8 +1293,8 @@
12931293 {
12941294 "frame": 6,
12951295 "label": "Top.MtlStdInputs.Transmittance.Color.Green=0.54232",
1296 "accuracy": 97.8672,
1297 "alpha_accuracy": 92.415
1296 "accuracy": 99.8845,
1297 "alpha_accuracy": 100.0
12981298 },
12991299 {
13001300 "frame": 7,
......@@ -1305,20 +1305,20 @@
13051305 {
13061306 "frame": 8,
13071307 "label": "Top.MtlStdInputs.Specular.Intensity=0.48618, Left.MtlStdInputs.Diffuse.Color.Blue=0.3401, SurfaceCubeInputs.SubdivisionWidth=11",
1308 "accuracy": 97.8954,
1309 "alpha_accuracy": 92.4135
1308 "accuracy": 99.8874,
1309 "alpha_accuracy": 100.0
13101310 },
13111311 {
13121312 "frame": 9,
13131313 "label": "Transform3DOp.InvertTransform=1",
1314 "accuracy": 97.8672,
1315 "alpha_accuracy": 92.415
1314 "accuracy": 99.8845,
1315 "alpha_accuracy": 100.0
13161316 },
13171317 {
13181318 "frame": 10,
13191319 "label": "Right.MtlStdInputs.Transmittance.AlphaDetail=0.5861, Top.MtlStdInputs.Transmittance.Saturation=0.56722",
1320 "accuracy": 97.8672,
1321 "alpha_accuracy": 92.415
1320 "accuracy": 99.8845,
1321 "alpha_accuracy": 100.0
13221322 },
13231323 {
13241324 "frame": 11,
......@@ -1496,47 +1496,47 @@
14961496 "category": "Transform, Warp & Framing"
14971497 },
14981498 "DaySky": {
1499 "mean_accuracy": 98.8731,
1500 "min_accuracy": 93.8147,
1499 "mean_accuracy": 99.8635,
1500 "min_accuracy": 99.3055,
15011501 "mean_alpha_accuracy": 100.0,
15021502 "min_alpha_accuracy": 100.0,
15031503 "frames": 12,
1504 "timestamp": "2026-12-01T15:40:16Z",
1504 "timestamp": "2026-12-01T23:48:02Z",
15051505 "per_frame": [
15061506 {
15071507 "frame": 0,
15081508 "label": "defaults",
1509 "accuracy": 99.0831,
1509 "accuracy": 99.8897,
15101510 "alpha_accuracy": 100.0
15111511 },
15121512 {
15131513 "frame": 1,
15141514 "label": "Day=17, Circumsolar.Intensity=0.74033",
1515 "accuracy": 99.1467,
1515 "accuracy": 99.9022,
15161516 "alpha_accuracy": 100.0
15171517 },
15181518 {
15191519 "frame": 2,
15201520 "label": "mask: ApplyMaskInverted=1, MultiplyByMask=1, FitMask=Stretch, MaskChannel=5, MaskLow=0.90546, MaskHigh=0.89202, MaskClipBlack=0, MaskClipWhite=0, Horizon.Brightness=0.6, Latitude=74.84104, Turbidity=0.32029",
1521 "accuracy": 99.5588,
1521 "accuracy": 99.8984,
15221522 "alpha_accuracy": 100.0
15231523 },
15241524 {
15251525 "frame": 3,
15261526 "label": "Time=22.45137",
1527 "accuracy": 93.8147,
1527 "accuracy": 99.3055,
15281528 "alpha_accuracy": 100.0
15291529 },
15301530 {
15311531 "frame": 4,
15321532 "label": "GlobalIn=144, Exposure=0.87893",
1533 "accuracy": 99.1135,
1533 "accuracy": 99.892,
15341534 "alpha_accuracy": 100.0
15351535 },
15361536 {
15371537 "frame": 5,
15381538 "label": "Longitude=143.9376, Month=September, Circumsolar.Width=0.20021",
1539 "accuracy": 99.4673,
1539 "accuracy": 99.8696,
15401540 "alpha_accuracy": 100.0
15411541 },
15421542 {
......@@ -1554,25 +1554,25 @@
15541554 {
15551555 "frame": 8,
15561556 "label": "GlobalOut=548, Day=27, Circumsolar.Intensity=0.12047",
1557 "accuracy": 99.3797,
1557 "accuracy": 99.9408,
15581558 "alpha_accuracy": 100.0
15591559 },
15601560 {
15611561 "frame": 9,
15621562 "label": "Horizon.Brightness=0.90014",
1563 "accuracy": 99.1079,
1563 "accuracy": 99.888,
15641564 "alpha_accuracy": 100.0
15651565 },
15661566 {
15671567 "frame": 10,
15681568 "label": "Latitude=70.22675, Turbidity=0.26902",
1569 "accuracy": 99.4541,
1569 "accuracy": 99.9051,
15701570 "alpha_accuracy": 100.0
15711571 },
15721572 {
15731573 "frame": 11,
15741574 "label": "Day=23, Circumsolar.Intensity=0.90625, Horizon.Brightness=0.19732, Latitude=38.59997, Turbidity=0.83761, Time=21.22089, GlobalIn=444, Exposure=0.25907, Longitude=95.61617, Month=May",
1575 "accuracy": 98.3517,
1575 "accuracy": 99.8711,
15761576 "alpha_accuracy": 100.0
15771577 }
15781578 ],
......@@ -2492,12 +2492,12 @@
24922492 "category": "Generators"
24932493 },
24942494 "FilmGrain": {
2495 "mean_accuracy": 96.2094,
2495 "mean_accuracy": 96.3089,
24962496 "min_accuracy": 91.7395,
24972497 "mean_alpha_accuracy": 100.0,
24982498 "min_alpha_accuracy": 100.0,
24992499 "frames": 12,
2500 "timestamp": "2026-12-01T18:59:00Z",
2500 "timestamp": "2026-12-01T23:49:26Z",
25012501 "per_frame": [
25022502 {
25032503 "frame": 0,
......@@ -2514,37 +2514,37 @@
25142514 {
25152515 "frame": 2,
25162516 "label": "mask: ApplyMaskInverted=1, MultiplyByMask=1, FitMask=Stretch, MaskChannel=1, MaskLow=0.83829, MaskHigh=0.27302, MaskClipBlack=0, MaskClipWhite=0, GreenYSize=2.56413, MasterXSize=2.07301, RedRoughness=4.73538",
2517 "accuracy": 96.5892,
2517 "accuracy": 96.587,
25182518 "alpha_accuracy": 100.0
25192519 },
25202520 {
25212521 "frame": 3,
25222522 "label": "BlueXSize=1.46911",
2523 "accuracy": 96.632,
2523 "accuracy": 96.6373,
25242524 "alpha_accuracy": 100.0
25252525 },
25262526 {
25272527 "frame": 4,
25282528 "label": "RedYSize=3.4556, GreenXSize=1.41648",
2529 "accuracy": 96.6088,
2529 "accuracy": 96.6201,
25302530 "alpha_accuracy": 100.0
25312531 },
25322532 {
25332533 "frame": 5,
25342534 "label": "TimeLockSeed=1, GreenOffset=-0.0103, BlueStrength=4.07106",
2535 "accuracy": 95.6434,
2535 "accuracy": 96.6551,
25362536 "alpha_accuracy": 100.0
25372537 },
25382538 {
25392539 "frame": 6,
25402540 "label": "BlueOffset=-0.02686",
2541 "accuracy": 96.6281,
2541 "accuracy": 96.6155,
25422542 "alpha_accuracy": 100.0
25432543 },
25442544 {
25452545 "frame": 7,
25462546 "label": "RedXSize=1.93192, LogProcessing=0",
2547 "accuracy": 95.6357,
2547 "accuracy": 95.8466,
25482548 "alpha_accuracy": 100.0
25492549 },
25502550 {
......@@ -2568,7 +2568,7 @@
25682568 {
25692569 "frame": 11,
25702570 "label": "LockSizeXY=0, Complexity=7, GreenYSize=0.55074, MasterXSize=4.65962, RedRoughness=2.72199, BlueXSize=1.21276, RedYSize=0.35629, GreenXSize=2.91717, TimeLockSeed=1, GreenOffset=-0.06399",
2571 "accuracy": 96.6445,
2571 "accuracy": 96.6146,
25722572 "alpha_accuracy": 100.0
25732573 }
25742574 ],
......@@ -3737,12 +3737,12 @@
37373737 "category": "3D Pipeline"
37383738 },
37393739 "MtlBlinn": {
3740 "mean_accuracy": 99.1714,
3741 "min_accuracy": 95.8793,
3740 "mean_accuracy": 99.5709,
3741 "min_accuracy": 97.8704,
37423742 "mean_alpha_accuracy": 94.9089,
37433743 "min_alpha_accuracy": 48.6462,
37443744 "frames": 12,
3745 "timestamp": "2026-12-01T17:48:05Z",
3745 "timestamp": "2026-12-01T23:49:17Z",
37463746 "per_frame": [
37473747 {
37483748 "frame": 0,
......@@ -3765,7 +3765,7 @@
37653765 {
37663766 "frame": 3,
37673767 "label": "Diffuse.Opacity=0.93702",
3768 "accuracy": 97.0419,
3768 "accuracy": 98.7846,
37693769 "alpha_accuracy": 96.4366
37703770 },
37713771 {
......@@ -3813,7 +3813,7 @@
38133813 {
38143814 "frame": 11,
38153815 "label": "Specular.Color.Red=0.78044, Specular.Color.Green=0.64395, Diffuse.Color.Blue=0.83415, Diffuse.Color.Green=0.50219, Specular.Intensity=0.71189, Diffuse.Opacity=0.88575, Transmittance.ColorDetail=0.84589, Specular.Color.Blue=0.58158, ReceivesShadows=0, Transmittance.Saturation=0.70342",
3816 "accuracy": 95.8793,
3816 "accuracy": 98.9311,
38173817 "alpha_accuracy": 93.8235
38183818 }
38193819 ],
......@@ -3903,12 +3903,12 @@
39033903 "category": "3D Pipeline"
39043904 },
39053905 "MtlPhong": {
3906 "mean_accuracy": 98.8657,
3907 "min_accuracy": 91.2276,
3906 "mean_accuracy": 99.4048,
3907 "min_accuracy": 96.5864,
39083908 "mean_alpha_accuracy": 91.0109,
39093909 "min_alpha_accuracy": 8.5935,
39103910 "frames": 12,
3911 "timestamp": "2026-12-01T17:48:14Z",
3911 "timestamp": "2026-12-01T23:49:09Z",
39123912 "per_frame": [
39133913 {
39143914 "frame": 0,
......@@ -3949,7 +3949,7 @@
39493949 {
39503950 "frame": 6,
39513951 "label": "Diffuse.Opacity=0.73887",
3952 "accuracy": 91.2276,
3952 "accuracy": 97.6971,
39533953 "alpha_accuracy": 87.9675
39543954 },
39553955 {
......@@ -4235,84 +4235,84 @@
42354235 "category": "Time, Routing & Utility"
42364236 },
42374237 "Plasma": {
4238 "mean_accuracy": 98.0516,
4239 "min_accuracy": 77.8272,
4240 "mean_alpha_accuracy": 98.0419,
4241 "min_alpha_accuracy": 77.6996,
4238 "mean_accuracy": 99.8692,
4239 "min_accuracy": 98.4626,
4240 "mean_alpha_accuracy": 99.8702,
4241 "min_alpha_accuracy": 98.4736,
42424242 "frames": 12,
4243 "timestamp": "2026-12-01T15:45:00Z",
4243 "timestamp": "2026-12-01T23:47:54Z",
42444244 "per_frame": [
42454245 {
42464246 "frame": 0,
42474247 "label": "defaults",
4248 "accuracy": 99.946,
4249 "alpha_accuracy": 99.9469
4248 "accuracy": 99.9981,
4249 "alpha_accuracy": 99.9984
42504250 },
42514251 {
42524252 "frame": 1,
42534253 "label": "Phase=0.21449, Operation=2",
4254 "accuracy": 99.3417,
4255 "alpha_accuracy": 99.3492
4254 "accuracy": 99.9882,
4255 "alpha_accuracy": 99.9873
42564256 },
42574257 {
42584258 "frame": 2,
42594259 "label": "mask: ApplyMaskInverted=1, MultiplyByMask=1, FitMask=Width, MaskChannel=0, MaskLow=0.67719, MaskHigh=0.45798, MaskClipBlack=0, MaskClipWhite=0, Circle1Scale=2.31527, GlobalOut=320, Circle1Center=[0.3014, 0.5722]",
4260 "accuracy": 99.9466,
4261 "alpha_accuracy": 99.9458
4260 "accuracy": 99.998,
4261 "alpha_accuracy": 99.9979
42624262 },
42634263 {
42644264 "frame": 3,
42654265 "label": "Circle4Type=1",
4266 "accuracy": 99.8825,
4267 "alpha_accuracy": 99.8836
4266 "accuracy": 99.998,
4267 "alpha_accuracy": 99.9979
42684268 },
42694269 {
42704270 "frame": 4,
42714271 "label": "Circle4Scale=6.22018, Scale=1.53596",
4272 "accuracy": 99.9498,
4273 "alpha_accuracy": 99.9505
4272 "accuracy": 99.9979,
4273 "alpha_accuracy": 99.9979
42744274 },
42754275 {
42764276 "frame": 5,
42774277 "label": "AlphaPhase=0.33794, Circle2Center=[0.9242, 0.4649], Circle3Center=[0.62, 0.423]",
4278 "accuracy": 99.9473,
4279 "alpha_accuracy": 99.947
4278 "accuracy": 99.998,
4279 "alpha_accuracy": 99.9982
42804280 },
42814281 {
42824282 "frame": 6,
42834283 "label": "Circle3Type=0",
4284 "accuracy": 99.9432,
4285 "alpha_accuracy": 99.9447
4284 "accuracy": 99.998,
4285 "alpha_accuracy": 99.9981
42864286 },
42874287 {
42884288 "frame": 7,
42894289 "label": "RedPhase=0.39531, Circle4Center=[0.2463, 0.1526]",
4290 "accuracy": 99.9467,
4291 "alpha_accuracy": 99.9472
4290 "accuracy": 99.998,
4291 "alpha_accuracy": 99.9981
42924292 },
42934293 {
42944294 "frame": 8,
42954295 "label": "Circle1Type=0, Circle3Scale=6.13489, Circle2Type=0",
4296 "accuracy": 99.9929,
4297 "alpha_accuracy": 99.9927
4296 "accuracy": 99.998,
4297 "alpha_accuracy": 99.9981
42984298 },
42994299 {
43004300 "frame": 9,
43014301 "label": "Circle2Scale=9.01932",
4302 "accuracy": 99.9485,
4303 "alpha_accuracy": 99.9484
4302 "accuracy": 99.998,
4303 "alpha_accuracy": 99.998
43044304 },
43054305 {
43064306 "frame": 10,
43074307 "label": "BluePhase=0.16082, GreenPhase=0.31153",
4308 "accuracy": 99.9466,
4309 "alpha_accuracy": 99.9469
4308 "accuracy": 99.9981,
4309 "alpha_accuracy": 99.9984
43104310 },
43114311 {
43124312 "frame": 11,
43134313 "label": "Phase=0.3804, Operation=3, Circle1Scale=7.48849, GlobalOut=837, Circle1Center=[0.0597, 0.8826], Circle4Type=1, Circle4Scale=9.22157, Scale=4.53735, AlphaPhase=0.06949, Circle2Center=[0.7631, 0.8558]",
4314 "accuracy": 77.8272,
4315 "alpha_accuracy": 77.6996
4314 "accuracy": 98.4626,
4315 "alpha_accuracy": 98.4736
43164316 }
43174317 ],
43184318 "category": "Generators"
......@@ -5314,84 +5314,84 @@
53145314 "category": "Blur, Sharpen & Glow"
53155315 },
53165316 "Text3D": {
5317 "mean_accuracy": 97.9281,
5318 "min_accuracy": 93.6396,
5319 "mean_alpha_accuracy": 97.9066,
5320 "min_alpha_accuracy": 93.6396,
5317 "mean_accuracy": 98.5185,
5318 "min_accuracy": 95.337,
5319 "mean_alpha_accuracy": 98.5028,
5320 "min_alpha_accuracy": 95.337,
53215321 "frames": 12,
5322 "timestamp": "2026-12-01T18:57:44Z",
5322 "timestamp": "2026-12-01T23:48:17Z",
53235323 "per_frame": [
53245324 {
53255325 "frame": 0,
53265326 "label": "defaults",
5327 "accuracy": 98.4733,
5328 "alpha_accuracy": 98.4733
5327 "accuracy": 98.8826,
5328 "alpha_accuracy": 98.8826
53295329 },
53305330 {
53315331 "frame": 1,
53325332 "label": "Level1=1, MiterLimit1=2.25293",
5333 "accuracy": 98.4733,
5334 "alpha_accuracy": 98.4733
5333 "accuracy": 98.8826,
5334 "alpha_accuracy": 98.8826
53355335 },
53365336 {
53375337 "frame": 2,
53385338 "label": "HorizontallyJustified=0.26834, Red1Clone=0.1994, CleanIntersections1=1",
5339 "accuracy": 98.4733,
5340 "alpha_accuracy": 98.4733
5339 "accuracy": 98.8826,
5340 "alpha_accuracy": 98.8826
53415341 },
53425342 {
53435343 "frame": 3,
53445344 "label": "LinePivot=[0.2658, -0.0958]",
5345 "accuracy": 98.4733,
5346 "alpha_accuracy": 98.4733
5345 "accuracy": 98.8826,
5346 "alpha_accuracy": 98.8826
53475347 },
53485348 {
53495349 "frame": 4,
53505350 "label": "CharacterSizeX=1.3364, ImageSource1=1",
5351 "accuracy": 98.5892,
5352 "alpha_accuracy": 98.5892
5351 "accuracy": 99.1562,
5352 "alpha_accuracy": 99.1562
53535353 },
53545354 {
53555355 "frame": 5,
53565356 "label": "LineSizeY=4.18055, BlueBevel=0.54337, UseOneMaterial=0",
5357 "accuracy": 93.6396,
5358 "alpha_accuracy": 93.6396
5357 "accuracy": 95.337,
5358 "alpha_accuracy": 95.337
53595359 },
53605360 {
53615361 "frame": 6,
53625362 "label": "VerticallyJustified=0.22981",
5363 "accuracy": 98.4733,
5364 "alpha_accuracy": 98.4733
5363 "accuracy": 98.8826,
5364 "alpha_accuracy": 98.8826
53655365 },
53665366 {
53675367 "frame": 7,
53685368 "label": "ScrollPosition=0.71693, Overlap1=1",
5369 "accuracy": 98.4733,
5370 "alpha_accuracy": 98.4733
5369 "accuracy": 98.8826,
5370 "alpha_accuracy": 98.8826
53715371 },
53725372 {
53735373 "frame": 8,
53745374 "label": "SpecularRed=0.45963, ColorBrush1=14, Clip=1",
5375 "accuracy": 98.4733,
5376 "alpha_accuracy": 98.4733
5375 "accuracy": 98.8826,
5376 "alpha_accuracy": 98.8826
53775377 },
53785378 {
53795379 "frame": 9,
53805380 "label": "AlphaBevel=0.47633",
5381 "accuracy": 98.4733,
5382 "alpha_accuracy": 98.4733
5381 "accuracy": 98.8826,
5382 "alpha_accuracy": 98.8826
53835383 },
53845384 {
53855385 "frame": 10,
53865386 "label": "SelectElement=1, Green1=0.35516",
5387 "accuracy": 98.7313,
5388 "alpha_accuracy": 98.4733
5387 "accuracy": 99.0704,
5388 "alpha_accuracy": 98.8826
53895389 },
53905390 {
53915391 "frame": 11,
53925392 "label": "Level1=1, MiterLimit1=3.74615, HorizontallyJustified=0.78566, Red1Clone=0.71672, CleanIntersections1=1, LinePivot=[0.235, -0.1265], CharacterSizeX=2.83709, ImageSource1=2, LineSizeY=2.83828, BlueBevel=0.27492",
5393 "accuracy": 96.3905,
5394 "alpha_accuracy": 96.3905
5393 "accuracy": 97.5975,
5394 "alpha_accuracy": 97.5975
53955395 }
53965396 ],
53975397 "category": "3D Pipeline"
......@@ -6310,333 +6310,333 @@
63106310 "category": "Masks"
63116311 },
63126312 "pBounce": {
6313 "mean_accuracy": 98.5555,
6314 "min_accuracy": 98.1757,
6315 "mean_alpha_accuracy": 98.5555,
6316 "min_alpha_accuracy": 98.1757,
6313 "mean_accuracy": 99.8083,
6314 "min_accuracy": 99.6713,
6315 "mean_alpha_accuracy": 99.8083,
6316 "min_alpha_accuracy": 99.6713,
63176317 "frames": 12,
6318 "timestamp": "2026-12-01T15:48:22Z",
6318 "timestamp": "2026-12-01T23:48:48Z",
63196319 "per_frame": [
63206320 {
63216321 "frame": 0,
63226322 "label": "defaults",
6323 "accuracy": 99.119,
6324 "alpha_accuracy": 99.119
6323 "accuracy": 99.9599,
6324 "alpha_accuracy": 99.9599
63256325 },
63266326 {
63276327 "frame": 1,
63286328 "label": "Roughness=9.94739, Set13=0",
6329 "accuracy": 98.8851,
6330 "alpha_accuracy": 98.8851
6329 "accuracy": 99.9249,
6330 "alpha_accuracy": 99.9249
63316331 },
63326332 {
63336333 "frame": 2,
63346334 "label": "Set1=0, Set6=0, Set19=0",
6335 "accuracy": 98.8063,
6336 "alpha_accuracy": 98.8063
6335 "accuracy": 99.8943,
6336 "alpha_accuracy": 99.8943
63376337 },
63386338 {
63396339 "frame": 3,
63406340 "label": "Set25=0",
6341 "accuracy": 98.7001,
6342 "alpha_accuracy": 98.7001
6341 "accuracy": 99.8616,
6342 "alpha_accuracy": 99.8616
63436343 },
63446344 {
63456345 "frame": 4,
63466346 "label": "Set28=0, Set21=0",
6347 "accuracy": 98.5436,
6348 "alpha_accuracy": 98.5436
6347 "accuracy": 99.8464,
6348 "alpha_accuracy": 99.8464
63496349 },
63506350 {
63516351 "frame": 5,
63526352 "label": "Set27=0, Set5=0, Set20=0",
6353 "accuracy": 98.5054,
6354 "alpha_accuracy": 98.5054
6353 "accuracy": 99.8142,
6354 "alpha_accuracy": 99.8142
63556355 },
63566356 {
63576357 "frame": 6,
63586358 "label": "SetMode=Ignore",
6359 "accuracy": 98.5573,
6360 "alpha_accuracy": 98.5573
6359 "accuracy": 99.7892,
6360 "alpha_accuracy": 99.7892
63616361 },
63626362 {
63636363 "frame": 7,
63646364 "label": "EndAge=0.49319, Variance=0.31734",
6365 "accuracy": 98.4019,
6366 "alpha_accuracy": 98.4019
6365 "accuracy": 99.765,
6366 "alpha_accuracy": 99.765
63676367 },
63686368 {
63696369 "frame": 8,
63706370 "label": "RandomSeed=743, Set29=0, Set4=0",
6371 "accuracy": 98.3643,
6372 "alpha_accuracy": 98.3643
6371 "accuracy": 99.7458,
6372 "alpha_accuracy": 99.7458
63736373 },
63746374 {
63756375 "frame": 9,
63766376 "label": "Set22=0",
6377 "accuracy": 98.3073,
6378 "alpha_accuracy": 98.3073
6377 "accuracy": 99.7216,
6378 "alpha_accuracy": 99.7216
63796379 },
63806380 {
63816381 "frame": 10,
63826382 "label": "LineRgn.End.Y=-1.35171, Set11=0",
6383 "accuracy": 98.1757,
6384 "alpha_accuracy": 98.1757
6383 "accuracy": 99.7053,
6384 "alpha_accuracy": 99.7053
63856385 },
63866386 {
63876387 "frame": 11,
63886388 "label": "Roughness=13.26565, Set13=0, Set1=0, Set6=0, Set19=0, Set25=0, Set28=0, Set21=0, Set27=0, Set5=0",
6389 "accuracy": 98.3003,
6390 "alpha_accuracy": 98.3003
6389 "accuracy": 99.6713,
6390 "alpha_accuracy": 99.6713
63916391 }
63926392 ],
63936393 "category": "Particles"
63946394 },
63956395 "pDirectionalForce": {
6396 "mean_accuracy": 98.4816,
6397 "min_accuracy": 97.9117,
6398 "mean_alpha_accuracy": 98.4816,
6399 "min_alpha_accuracy": 97.9117,
6396 "mean_accuracy": 99.8136,
6397 "min_accuracy": 99.708,
6398 "mean_alpha_accuracy": 99.8136,
6399 "min_alpha_accuracy": 99.708,
64006400 "frames": 12,
6401 "timestamp": "2026-12-01T15:48:28Z",
6401 "timestamp": "2026-12-01T23:48:36Z",
64026402 "per_frame": [
64036403 {
64046404 "frame": 0,
64056405 "label": "defaults",
6406 "accuracy": 99.119,
6407 "alpha_accuracy": 99.119
6406 "accuracy": 99.9599,
6407 "alpha_accuracy": 99.9599
64086408 },
64096409 {
64106410 "frame": 1,
64116411 "label": "Probability=0.84725, Set26=0",
6412 "accuracy": 98.8805,
6413 "alpha_accuracy": 98.8805
6412 "accuracy": 99.9288,
6413 "alpha_accuracy": 99.9288
64146414 },
64156415 {
64166416 "frame": 2,
64176417 "label": "Strength=0.10884, Set21=0, Set13=0",
6418 "accuracy": 98.7972,
6419 "alpha_accuracy": 98.7972
6418 "accuracy": 99.8979,
6419 "alpha_accuracy": 99.8979
64206420 },
64216421 {
64226422 "frame": 3,
64236423 "label": "Set4=0",
6424 "accuracy": 98.7043,
6425 "alpha_accuracy": 98.7043
6424 "accuracy": 99.8778,
6425 "alpha_accuracy": 99.8778
64266426 },
64276427 {
64286428 "frame": 4,
64296429 "label": "EndAge=0.32638, Set3=0",
6430 "accuracy": 98.5449,
6431 "alpha_accuracy": 98.5449
6430 "accuracy": 99.8432,
6431 "alpha_accuracy": 99.8432
64326432 },
64336433 {
64346434 "frame": 5,
64356435 "label": "Set6=0, Set30=0, Set32=0",
6436 "accuracy": 98.4607,
6437 "alpha_accuracy": 98.4607
6436 "accuracy": 99.8102,
6437 "alpha_accuracy": 99.8102
64386438 },
64396439 {
64406440 "frame": 6,
64416441 "label": "RegionMode=Ignore",
6442 "accuracy": 98.4911,
6443 "alpha_accuracy": 98.4911
6442 "accuracy": 99.7909,
6443 "alpha_accuracy": 99.7909
64446444 },
64456445 {
64466446 "frame": 7,
64476447 "label": "StartAge=0.58407, Set5=0",
6448 "accuracy": 98.3235,
6449 "alpha_accuracy": 98.3235
6448 "accuracy": 99.7666,
6449 "alpha_accuracy": 99.7666
64506450 },
64516451 {
64526452 "frame": 8,
64536453 "label": "Set25=0, Set14=0, Set9=0",
6454 "accuracy": 98.2251,
6455 "alpha_accuracy": 98.2251
6454 "accuracy": 99.7358,
6455 "alpha_accuracy": 99.7358
64566456 },
64576457 {
64586458 "frame": 9,
64596459 "label": "Set10=0",
6460 "accuracy": 98.1312,
6461 "alpha_accuracy": 98.1312
6460 "accuracy": 99.7281,
6461 "alpha_accuracy": 99.7281
64626462 },
64636463 {
64646464 "frame": 10,
64656465 "label": "Set18=0, Set31=0",
6466 "accuracy": 97.9117,
6467 "alpha_accuracy": 97.9117
6466 "accuracy": 99.7164,
6467 "alpha_accuracy": 99.7164
64686468 },
64696469 {
64706470 "frame": 11,
64716471 "label": "Probability=0.09316, Set26=0, Strength=-0.05223, Set21=0, Set13=0, Set4=0, EndAge=0.62652, Set3=0, Set6=0, Set30=0",
6472 "accuracy": 98.1898,
6473 "alpha_accuracy": 98.1898
6472 "accuracy": 99.708,
6473 "alpha_accuracy": 99.708
64746474 }
64756475 ],
64766476 "category": "Particles"
64776477 },
64786478 "pDrag": {
6479 "mean_accuracy": 98.6098,
6480 "min_accuracy": 98.31,
6481 "mean_alpha_accuracy": 98.6098,
6482 "min_alpha_accuracy": 98.31,
6479 "mean_accuracy": 99.8245,
6480 "min_accuracy": 99.7331,
6481 "mean_alpha_accuracy": 99.8245,
6482 "min_alpha_accuracy": 99.7331,
64836483 "frames": 12,
6484 "timestamp": "2026-12-01T15:48:35Z",
6484 "timestamp": "2026-12-01T23:49:01Z",
64856485 "per_frame": [
64866486 {
64876487 "frame": 0,
64886488 "label": "defaults",
6489 "accuracy": 99.1184,
6490 "alpha_accuracy": 99.1184
6489 "accuracy": 99.9591,
6490 "alpha_accuracy": 99.9591
64916491 },
64926492 {
64936493 "frame": 1,
64946494 "label": "Region=CubeRgn, Set2=0",
6495 "accuracy": 98.8878,
6496 "alpha_accuracy": 98.8878
6495 "accuracy": 99.9231,
6496 "alpha_accuracy": 99.9231
64976497 },
64986498 {
64996499 "frame": 2,
65006500 "label": "Set15=0, Set25=0, Set12=0",
6501 "accuracy": 98.8104,
6502 "alpha_accuracy": 98.8104
6501 "accuracy": 99.8991,
6502 "alpha_accuracy": 99.8991
65036503 },
65046504 {
65056505 "frame": 3,
65066506 "label": "Set13=0",
6507 "accuracy": 98.7067,
6508 "alpha_accuracy": 98.7067
6507 "accuracy": 99.8714,
6508 "alpha_accuracy": 99.8714
65096509 },
65106510 {
65116511 "frame": 4,
65126512 "label": "Set1=0, Set19=0",
6513 "accuracy": 98.563,
6514 "alpha_accuracy": 98.563
6513 "accuracy": 99.8478,
6514 "alpha_accuracy": 99.8478
65156515 },
65166516 {
65176517 "frame": 5,
65186518 "label": "SpinFriction=0.90166, Set30=0, SetMode=DontAffect",
6519 "accuracy": 98.5434,
6520 "alpha_accuracy": 98.5434
6519 "accuracy": 99.8246,
6520 "alpha_accuracy": 99.8246
65216521 },
65226522 {
65236523 "frame": 6,
65246524 "label": "Set3=0",
6525 "accuracy": 98.6045,
6526 "alpha_accuracy": 98.6045
6525 "accuracy": 99.7949,
6526 "alpha_accuracy": 99.7949
65276527 },
65286528 {
65296529 "frame": 7,
65306530 "label": "Set21=0, Probability=0.09181",
6531 "accuracy": 98.4676,
6532 "alpha_accuracy": 98.4676
6531 "accuracy": 99.778,
6532 "alpha_accuracy": 99.778
65336533 },
65346534 {
65356535 "frame": 8,
65366536 "label": "Set20=0, Set16=0, RandomSeed=915",
6537 "accuracy": 98.4425,
6538 "alpha_accuracy": 98.4425
6537 "accuracy": 99.7742,
6538 "alpha_accuracy": 99.7742
65396539 },
65406540 {
65416541 "frame": 9,
65426542 "label": "StartAge=0.05488",
6543 "accuracy": 98.4165,
6544 "alpha_accuracy": 98.4165
6543 "accuracy": 99.7445,
6544 "alpha_accuracy": 99.7445
65456545 },
65466546 {
65476547 "frame": 10,
65486548 "label": "Set17=0, Set22=0",
6549 "accuracy": 98.31,
6550 "alpha_accuracy": 98.31
6549 "accuracy": 99.7443,
6550 "alpha_accuracy": 99.7443
65516551 },
65526552 {
65536553 "frame": 11,
65546554 "label": "Region=LineRgn, Set2=0, Set15=0, Set25=0, Set12=0, Set13=0, Set1=0, Set19=0, SpinFriction=0.63321, Set30=0",
6555 "accuracy": 98.4467,
6556 "alpha_accuracy": 98.4467
6555 "accuracy": 99.7331,
6556 "alpha_accuracy": 99.7331
65576557 }
65586558 ],
65596559 "category": "Particles"
65606560 },
65616561 "pEmitter": {
6562 "mean_accuracy": 98.2475,
6563 "min_accuracy": 97.0471,
6564 "mean_alpha_accuracy": 98.2482,
6565 "min_alpha_accuracy": 97.0471,
6562 "mean_accuracy": 99.8132,
6563 "min_accuracy": 99.6732,
6564 "mean_alpha_accuracy": 99.8121,
6565 "min_alpha_accuracy": 99.6732,
65666566 "frames": 12,
6567 "timestamp": "2026-12-01T15:48:42Z",
6567 "timestamp": "2026-12-01T23:48:24Z",
65686568 "per_frame": [
65696569 {
65706570 "frame": 0,
65716571 "label": "defaults",
6572 "accuracy": 99.0113,
6573 "alpha_accuracy": 99.0113
6572 "accuracy": 99.9564,
6573 "alpha_accuracy": 99.9564
65746574 },
65756575 {
65766576 "frame": 1,
65776577 "label": "Set24=1, Set14=1",
6578 "accuracy": 98.7924,
6579 "alpha_accuracy": 98.7924
6578 "accuracy": 99.9309,
6579 "alpha_accuracy": 99.9309
65806580 },
65816581 {
65826582 "frame": 2,
65836583 "label": "RotationZ=134.28566, RotationXVariance=145.73754, VelocityVariance=0.49077",
6584 "accuracy": 97.6235,
6585 "alpha_accuracy": 97.6235
6584 "accuracy": 99.8807,
6585 "alpha_accuracy": 99.8807
65866586 },
65876587 {
65886588 "frame": 3,
65896589 "label": "SpinZVariance=90.70891",
6590 "accuracy": 98.6042,
6591 "alpha_accuracy": 98.6042
6590 "accuracy": 99.862,
6591 "alpha_accuracy": 99.862
65926592 },
65936593 {
65946594 "frame": 4,
65956595 "label": "SphereRgn.Rotate.Z=31.10569, ParticleStyle.RedHigh=-0.43584",
6596 "accuracy": 98.6261,
6597 "alpha_accuracy": 98.6346
6596 "accuracy": 99.8546,
6597 "alpha_accuracy": 99.842
65986598 },
65996599 {
66006600 "frame": 5,
66016601 "label": "Set18=1, TimeLockSeed=1, Set7=1",
6602 "accuracy": 98.5158,
6603 "alpha_accuracy": 98.5158
6602 "accuracy": 99.8199,
6603 "alpha_accuracy": 99.8199
66046604 },
66056605 {
66066606 "frame": 6,
66076607 "label": "Set3=1",
6608 "accuracy": 98.4437,
6609 "alpha_accuracy": 98.4437
6608 "accuracy": 99.8074,
6609 "alpha_accuracy": 99.8074
66106610 },
66116611 {
66126612 "frame": 7,
66136613 "label": "ParticleStyle.BlueHigh=0.10081, Set17=1",
6614 "accuracy": 98.4191,
6615 "alpha_accuracy": 98.4191
6614 "accuracy": 99.7962,
6615 "alpha_accuracy": 99.7962
66166616 },
66176617 {
66186618 "frame": 8,
66196619 "label": "ParticleStyle.GreenLow=0.74792, InheritVelocityVariance=0.8157, InheritVelocity=1.28612",
6620 "accuracy": 98.4047,
6621 "alpha_accuracy": 98.4047
6620 "accuracy": 99.7598,
6621 "alpha_accuracy": 99.7598
66226622 },
66236623 {
66246624 "frame": 9,
66256625 "label": "ParticleStylePoint.SubPixelRendered=1",
6626 "accuracy": 98.2948,
6627 "alpha_accuracy": 98.2948
6626 "accuracy": 99.7425,
6627 "alpha_accuracy": 99.7425
66286628 },
66296629 {
66306630 "frame": 10,
66316631 "label": "AlwaysFaceCamera=0, AngleVariance=149.8772",
6632 "accuracy": 97.0471,
6633 "alpha_accuracy": 97.0471
6632 "accuracy": 99.6732,
6633 "alpha_accuracy": 99.6732
66346634 },
66356635 {
66366636 "frame": 11,
66376637 "label": "Set24=1, Set14=1, RotationZ=320.52137, RotationXVariance=331.97326, VelocityVariance=0.08809, SpinZVariance=72.25177, SphereRgn.Rotate.Z=139.15569, ParticleStyle.RedHigh=0.16444, Set18=1, TimeLockSeed=1",
6638 "accuracy": 97.1871,
6639 "alpha_accuracy": 97.1871
6638 "accuracy": 99.6747,
6639 "alpha_accuracy": 99.6747
66406640 }
66416641 ],
66426642 "category": "Particles"
......@@ -6808,250 +6808,250 @@
68086808 "category": "Particles"
68096809 },
68106810 "pPointForce": {
6811 "mean_accuracy": 98.5158,
6812 "min_accuracy": 97.9994,
6813 "mean_alpha_accuracy": 98.5158,
6814 "min_alpha_accuracy": 97.9994,
6811 "mean_accuracy": 99.7975,
6812 "min_accuracy": 99.6424,
6813 "mean_alpha_accuracy": 99.7975,
6814 "min_alpha_accuracy": 99.6424,
68156815 "frames": 12,
6816 "timestamp": "2026-12-01T15:49:02Z",
6816 "timestamp": "2026-12-01T23:48:42Z",
68176817 "per_frame": [
68186818 {
68196819 "frame": 0,
68206820 "label": "defaults",
6821 "accuracy": 99.119,
6822 "alpha_accuracy": 99.119
6821 "accuracy": 99.9599,
6822 "alpha_accuracy": 99.9599
68236823 },
68246824 {
68256825 "frame": 1,
68266826 "label": "EndAge=0.6275, Set13=0",
6827 "accuracy": 98.8842,
6828 "alpha_accuracy": 98.8842
6827 "accuracy": 99.9335,
6828 "alpha_accuracy": 99.9335
68296829 },
68306830 {
68316831 "frame": 2,
68326832 "label": "Set19=0, StartAge=0.3012, Set24=0",
6833 "accuracy": 98.8076,
6834 "alpha_accuracy": 98.8076
6833 "accuracy": 99.8894,
6834 "alpha_accuracy": 99.8894
68356835 },
68366836 {
68376837 "frame": 3,
68386838 "label": "Set11=0",
6839 "accuracy": 98.6889,
6840 "alpha_accuracy": 98.6889
6839 "accuracy": 99.8816,
6840 "alpha_accuracy": 99.8816
68416841 },
68426842 {
68436843 "frame": 4,
68446844 "label": "Set1=0, Set10=0",
6845 "accuracy": 98.5319,
6846 "alpha_accuracy": 98.5319
6845 "accuracy": 99.8456,
6846 "alpha_accuracy": 99.8456
68476847 },
68486848 {
68496849 "frame": 5,
68506850 "label": "Set12=0, Set29=0, Set28=0",
6851 "accuracy": 98.4815,
6852 "alpha_accuracy": 98.4815
6851 "accuracy": 99.8069,
6852 "alpha_accuracy": 99.8069
68536853 },
68546854 {
68556855 "frame": 6,
68566856 "label": "Set20=0",
6857 "accuracy": 98.5125,
6858 "alpha_accuracy": 98.5125
6857 "accuracy": 99.7751,
6858 "alpha_accuracy": 99.7751
68596859 },
68606860 {
68616861 "frame": 7,
68626862 "label": "Set26=0, Translate.Z=-7.72739",
6863 "accuracy": 98.404,
6864 "alpha_accuracy": 98.404
6863 "accuracy": 99.7727,
6864 "alpha_accuracy": 99.7727
68656865 },
68666866 {
68676867 "frame": 8,
68686868 "label": "Set2=0, Probability=0.84479, Set30=0",
6869 "accuracy": 98.2762,
6870 "alpha_accuracy": 98.2762
6869 "accuracy": 99.7243,
6870 "alpha_accuracy": 99.7243
68716871 },
68726872 {
68736873 "frame": 9,
68746874 "label": "Set32=0",
6875 "accuracy": 98.1689,
6876 "alpha_accuracy": 98.1689
6875 "accuracy": 99.6953,
6876 "alpha_accuracy": 99.6953
68776877 },
68786878 {
68796879 "frame": 10,
68806880 "label": "Set22=0, Set6=0",
6881 "accuracy": 97.9994,
6882 "alpha_accuracy": 97.9994
6881 "accuracy": 99.6432,
6882 "alpha_accuracy": 99.6432
68836883 },
68846884 {
68856885 "frame": 11,
68866886 "label": "EndAge=0.79341, Set13=0, Set19=0, StartAge=0.81852, Set24=0, Set11=0, Set1=0, Set10=0, Set12=0, Set29=0",
6887 "accuracy": 98.3149,
6888 "alpha_accuracy": 98.3149
6887 "accuracy": 99.6424,
6888 "alpha_accuracy": 99.6424
68896889 }
68906890 ],
68916891 "category": "Particles"
68926892 },
68936893 "pRender": {
6894 "mean_accuracy": 98.4485,
6895 "min_accuracy": 97.7268,
6896 "mean_alpha_accuracy": 98.4485,
6897 "min_alpha_accuracy": 97.7268,
6894 "mean_accuracy": 99.6839,
6895 "min_accuracy": 98.4009,
6896 "mean_alpha_accuracy": 99.6839,
6897 "min_alpha_accuracy": 98.4009,
68986898 "frames": 12,
6899 "timestamp": "2026-12-01T15:49:08Z",
6899 "timestamp": "2026-12-01T23:48:30Z",
69006900 "per_frame": [
69016901 {
69026902 "frame": 0,
69036903 "label": "defaults",
6904 "accuracy": 99.119,
6905 "alpha_accuracy": 99.119
6904 "accuracy": 99.9599,
6905 "alpha_accuracy": 99.9599
69066906 },
69076907 {
69086908 "frame": 1,
69096909 "label": "PreGenerateFrames=90, ObjectID.Set19=4",
6910 "accuracy": 97.7268,
6911 "alpha_accuracy": 97.7268
6910 "accuracy": 98.4009,
6911 "alpha_accuracy": 98.4009
69126912 },
69136913 {
69146914 "frame": 2,
69156915 "label": "mask: ApplyMaskInverted=1, MultiplyByMask=1, FitMask=Height, MaskChannel=0, MaskLow=0.60876, MaskHigh=0.61963, MaskClipBlack=0, MaskClipWhite=0, ObjectID.Set14=19, GlobalIn=358, ObjectID.Set12=8",
6916 "accuracy": 98.7439,
6917 "alpha_accuracy": 98.7439
6916 "accuracy": 99.9397,
6917 "alpha_accuracy": 99.9397
69186918 },
69196919 {
69206920 "frame": 3,
69216921 "label": "RotationOrder=4",
6922 "accuracy": 98.7015,
6923 "alpha_accuracy": 98.7015
6922 "accuracy": 99.8654,
6923 "alpha_accuracy": 99.8654
69246924 },
69256925 {
69266926 "frame": 4,
69276927 "label": "ObjectID.Set15=23, Glow=0.09235",
6928 "accuracy": 98.5458,
6929 "alpha_accuracy": 98.5458
6928 "accuracy": 99.846,
6929 "alpha_accuracy": 99.846
69306930 },
69316931 {
69326932 "frame": 5,
69336933 "label": "ObjectID.Set26=22, MaterialID.Set11=3, ShowGrid=1",
6934 "accuracy": 98.5078,
6935 "alpha_accuracy": 98.5078
6934 "accuracy": 99.8147,
6935 "alpha_accuracy": 99.8147
69366936 },
69376937 {
69386938 "frame": 6,
69396939 "label": "ObjectID.Set23=15",
6940 "accuracy": 98.5608,
6941 "alpha_accuracy": 98.5608
6940 "accuracy": 99.7969,
6941 "alpha_accuracy": 99.7969
69426942 },
69436943 {
69446944 "frame": 7,
69456945 "label": "ObjectID.Set18=15, GridBlue=0.40469",
6946 "accuracy": 98.404,
6947 "alpha_accuracy": 98.404
6946 "accuracy": 99.7727,
6947 "alpha_accuracy": 99.7727
69486948 },
69496949 {
69506950 "frame": 8,
69516951 "label": "OutputMode=ThreeD, GenerateZBuffer=1, ObjectID.Set1=2",
6952 "accuracy": 98.368,
6953 "alpha_accuracy": 98.368
6952 "accuracy": 99.7773,
6953 "alpha_accuracy": 99.7773
69546954 },
69556955 {
69566956 "frame": 9,
69576957 "label": "MaterialID.Set22=21",
6958 "accuracy": 98.3152,
6959 "alpha_accuracy": 98.3152
6958 "accuracy": 99.7519,
6959 "alpha_accuracy": 99.7519
69606960 },
69616961 {
69626962 "frame": 10,
69636963 "label": "ObjectID.Set32=10, Rotate.X=-76.18976",
6964 "accuracy": 97.9746,
6965 "alpha_accuracy": 97.9746
6964 "accuracy": 99.7909,
6965 "alpha_accuracy": 99.7909
69666966 },
69676967 {
69686968 "frame": 11,
69696969 "label": "PreGenerateFrames=14, ObjectID.Set19=9, ObjectID.Set14=7, GlobalIn=876, ObjectID.Set12=23, RotationOrder=3, ObjectID.Set15=5, Glow=0.39248, ObjectID.Set26=14, MaterialID.Set11=22",
6970 "accuracy": 98.4146,
6971 "alpha_accuracy": 98.4146
6970 "accuracy": 99.4911,
6971 "alpha_accuracy": 99.4911
69726972 }
69736973 ],
69746974 "category": "Particles"
69756975 },
69766976 "pTurbulence": {
6977 "mean_accuracy": 98.5835,
6978 "min_accuracy": 98.2654,
6979 "mean_alpha_accuracy": 98.5835,
6980 "min_alpha_accuracy": 98.2654,
6977 "mean_accuracy": 99.8163,
6978 "min_accuracy": 99.6958,
6979 "mean_alpha_accuracy": 99.8163,
6980 "min_alpha_accuracy": 99.6958,
69816981 "frames": 12,
6982 "timestamp": "2026-12-01T15:49:15Z",
6982 "timestamp": "2026-12-01T23:48:55Z",
69836983 "per_frame": [
69846984 {
69856985 "frame": 0,
69866986 "label": "defaults",
6987 "accuracy": 99.119,
6988 "alpha_accuracy": 99.119
6987 "accuracy": 99.9599,
6988 "alpha_accuracy": 99.9599
69896989 },
69906990 {
69916991 "frame": 1,
69926992 "label": "SetMode=DontAffect, ZStrength=0.24941",
6993 "accuracy": 98.8854,
6994 "alpha_accuracy": 98.8854
6993 "accuracy": 99.9277,
6994 "alpha_accuracy": 99.9277
69956995 },
69966996 {
69976997 "frame": 2,
69986998 "label": "Set5=0, TimeLockSeed=1, Set12=0",
6999 "accuracy": 98.8075,
7000 "alpha_accuracy": 98.8075
6999 "accuracy": 99.896,
7000 "alpha_accuracy": 99.896
70017001 },
70027002 {
70037003 "frame": 3,
70047004 "label": "Set16=0",
7005 "accuracy": 98.7008,
7006 "alpha_accuracy": 98.7008
7005 "accuracy": 99.8682,
7006 "alpha_accuracy": 99.8682
70077007 },
70087008 {
70097009 "frame": 4,
70107010 "label": "Set21=0, Set19=0",
7011 "accuracy": 98.5508,
7012 "alpha_accuracy": 98.5508
7011 "accuracy": 99.8482,
7012 "alpha_accuracy": 99.8482
70137013 },
70147014 {
70157015 "frame": 5,
70167016 "label": "Set17=0, Set20=0, Set23=0",
7017 "accuracy": 98.5278,
7018 "alpha_accuracy": 98.5278
7017 "accuracy": 99.8121,
7018 "alpha_accuracy": 99.8121
70197019 },
70207020 {
70217021 "frame": 6,
70227022 "label": "Set11=0",
7023 "accuracy": 98.5823,
7024 "alpha_accuracy": 98.5823
7023 "accuracy": 99.7999,
7024 "alpha_accuracy": 99.7999
70257025 },
70267026 {
70277027 "frame": 7,
70287028 "label": "RegionMode=NotInside, Set2=0",
7029 "accuracy": 98.4446,
7030 "alpha_accuracy": 98.4446
7029 "accuracy": 99.7751,
7030 "alpha_accuracy": 99.7751
70317031 },
70327032 {
70337033 "frame": 8,
70347034 "label": "Set27=0, Set25=0, Set6=0",
7035 "accuracy": 98.4108,
7036 "alpha_accuracy": 98.4108
7035 "accuracy": 99.7596,
7036 "alpha_accuracy": 99.7596
70377037 },
70387038 {
70397039 "frame": 9,
70407040 "label": "Set29=0",
7041 "accuracy": 98.378,
7042 "alpha_accuracy": 98.378
7041 "accuracy": 99.7468,
7042 "alpha_accuracy": 99.7468
70437043 },
70447044 {
70457045 "frame": 10,
70467046 "label": "Region=MeshRegion, Set13=0",
7047 "accuracy": 98.2654,
7048 "alpha_accuracy": 98.2654
7047 "accuracy": 99.7064,
7048 "alpha_accuracy": 99.7064
70497049 },
70507050 {
70517051 "frame": 11,
70527052 "label": "SetMode=Ignore, ZStrength=0.41533, Set5=0, TimeLockSeed=1, Set12=0, Set16=0, Set21=0, Set19=0, Set17=0, Set20=0",
7053 "accuracy": 98.3298,
7054 "alpha_accuracy": 98.3298
7053 "accuracy": 99.6958,
7054 "alpha_accuracy": 99.6958
70557055 }
70567056 ],
70577057 "category": "Particles"