From f80b0ebc6787471689dc60d888ce6ebb3bcf5b8f Mon Sep 17 00:00:00 2001 From: clover caruso Date: Tue, 1 Dec 2026 15:46:09 -0800 Subject: [PATCH] Wave 26 integration: restore particles/ submodules and update accuracy ledger + compatibility.md --- compatibility.md | 30 +- crates/engine/src/particles.rs | 1881 +------------------------ crates/engine/src/particles/raster.rs | 948 ++++++++++--- crates/engine/src/particles/sim.rs | 105 +- scripts/accuracy_ledger.json | 630 ++++----- 5 files changed, 1135 insertions(+), 2459 deletions(-) diff --git a/compatibility.md b/compatibility.md index 2d1dbd35d618b473ffc724c0a0ddad11dac20b70..dba06ab6dcc86f9b89835a0d194a5f7f609c40f9 100644 --- a/compatibility.md +++ b/compatibility.md @@ -11,7 +11,7 @@ Fission currently supports **125** tool types across 2D/3D compositing, all with | **Supported Tools** | **125** | | **Modifiers & Animation** | **8** | | **Accuracy across [paper clover](https://paperclover.net)'s compositions** | **99.5%** | -| **Supported Tool Accuracy** | **99.5%** | +| **Supported Tool Accuracy** | **99.7%** | | **Supported Tools with 100% Accuracy** | **46** | | **Coverage of Fusion's Built-in Tools** | **28.0%** | | **Coverage of All Fuses on Reactor** | **0.5%** | @@ -22,10 +22,10 @@ Fission currently supports **125** tool types across 2D/3D compositing, all with | --- | --- | --- | | `Background` | ✅ 100.0% | — | | `FastNoise` | ✅ 100.0% | — | -| `Plasma` | 98.1% | — | +| `Plasma` | 99.9% | — | | `TextPlus` | 99.4% | — | | `Loader` | ✅ 100.0% | — | -| `DaySky` | 98.9% | — | +| `DaySky` | 99.9% | — | | `Fuse.CheckerPieceGenerator` | ✅ 100.0% | — | ## Compositing & Blending @@ -77,7 +77,7 @@ Fission currently supports **125** tool types across 2D/3D compositing, all with | `Fuse.XGlow` | 99.2%–99.8% | Octave-capped in `Fast` mode. | | `ErodeDilate` | ✅ 100.0% | — | | `RemoveNoise` | ✅ 100.0% | — | -| `FilmGrain` | 96.2% | Stochastic per-frame PRNG seed differs from Fusion. | +| `FilmGrain` | 96.3% | Stochastic per-frame PRNG seed differs from Fusion. | | `Fuse.Outline` | 99.5%–99.9% | — | | `Fuse.XfChroma` | 99.5%–99.9% | — | | `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 | Tool | Accuracy | Notes | | --- | --- | --- | -| `pRender` | 98.4% | 2D mode only (no 3D particle renderer); stochastic PRNG seed differs. | -| `pEmitter` | 98.2% | Stochastic PRNG seed differs; cold starts >600 frames window-simulate. | -| `pPointForce` | 98.5% | — | -| `pDirectionalForce` | 98.5% | — | -| `pTurbulence` | 98.6% | — | -| `pDrag` | 98.6% | — | +| `pRender` | 99.7% | 2D mode only (no 3D particle renderer); stochastic PRNG seed differs. | +| `pEmitter` | 99.8% | Stochastic PRNG seed differs; cold starts >600 frames window-simulate. | +| `pPointForce` | 99.8% | — | +| `pDirectionalForce` | 99.8% | — | +| `pTurbulence` | 99.8% | — | +| `pDrag` | 99.8% | — | | `pKill` | 99.1% | — | | `pMerge` | 99.7% | — | -| `pBounce` | 98.6% | — | +| `pBounce` | 99.8% | — | ## 3D Pipeline @@ -155,16 +155,16 @@ Each 3D tool's accuracy is measured by rendering it inside a lit `Merge3D` + `Ca | `Transform3D` | 99.4% | — | | `ImagePlane3D` | 99.2% | — | | `Shape3D` | 99.9% | — | -| `Cube3D` | 98.6% | — | +| `Cube3D` | 99.9% | — | | `SurfaceFBXMesh` | Visual* | Static mesh only (no skeletal skinning/morph animation). | -| `Text3D` | 97.9% | Bevels not implemented. | +| `Text3D` | 98.5% | Bevels not implemented. | | `LightAmbient` | ✅ 100.0% | — | | `LightDirectional` | 99.9% | Up to 4 directional lights per scene; shadow maps pending (`#46`). | | `LightPoint` | 99.9% | — | | `LightSpot` | 99.6% | Spot shadow maps pending (`#46`). | -| `MtlBlinn` | 99.2% | — | +| `MtlBlinn` | 99.6% | — | | `MtlCookTorrance` | 98.9% | — | -| `MtlPhong` | 98.9% | — | +| `MtlPhong` | 99.4% | — | | `Texture2DOperator` | 99.3% | — | | `TextureTransformOperator` | 99.6% | — | | `BumpMap` | 99.2% | — | diff --git a/crates/engine/src/particles.rs b/crates/engine/src/particles.rs index be514beb8557d0c294624ccc137a3605ca0921fb..b7b0bc9f378810073ceea970660c1c510ef699df 100644 --- a/crates/engine/src/particles.rs +++ b/crates/engine/src/particles.rs @@ -4,6 +4,8 @@ //! `pDrag` / `pFriction`, `pKill`, `pBounce`, `pMerge`, and `pRender` (2D mode). mod plan; +mod raster; +mod sim; #[cfg(test)] mod tests; @@ -309,1885 +311,6 @@ pub fn render_particles_2d( } /// Per-frame particle emission, regions, forces, collisions, and simulation stepping. -mod sim { - use std::collections::HashSet; - - use model::{Comp, ExprEngine, Node}; - - use super::plan::ParticlePlan; - use super::{ - MAX_PARTICLES, POINT_FORCE_SCALE, Particle, SimState, SplitMix64, TURBULENCE_SCALE, - VELOCITY_SCALE, - }; - - /// Advances the particle simulation by a single integer frame `frame`. - pub(super) fn step_simulation( - state: &mut SimState, - comp: &Comp, - plan: &ParticlePlan, - frame: i64, - expr: &ExprEngine, - ) { - let t = frame as f64; - - // 1. Apply forces & kills to existing live particles, then integrate motion and age. - if !state.particles.is_empty() { - for (mod_id, scope) in &plan.modifiers { - let Some(node) = comp.nodes.get(mod_id.0) else { - continue; - }; - apply_modifier(&mut state.particles, comp, node, scope, t, expr); - } - - for p in &mut state.particles { - if !p.alive { - continue; - } - p.pos[0] += p.vel[0]; - p.pos[1] += p.vel[1]; - p.pos[2] += p.vel[2]; - p.rot_z += p.spin_z; - p.age += 1.0; - if p.age >= p.lifespan { - p.alive = false; - } - } - state.particles.retain(|p| p.alive); - } - - // 2. Emit new particles for `frame` (born with `age = 0.0` at their spawn region). - let first_new = state.particles.len(); - for &(emitter_id, emitter_hash) in &plan.emitters { - if state.particles.len() >= MAX_PARTICLES { - break; - } - let Some(node) = comp.nodes.get(emitter_id.0) else { - continue; - }; - emit_particles(state, comp, node, emitter_hash, frame, t, expr); - } - - // A newborn is damped by friction and then integrated once on its birth frame; other forces - // only start acting next frame. - for (mod_id, scope) in &plan.modifiers { - let Some(node) = comp.nodes.get(mod_id.0) else { - continue; - }; - if matches!(node.kind.as_str(), "pDrag" | "pFriction") { - apply_modifier(&mut state.particles[first_new..], comp, node, scope, t, expr); - } - } - for p in &mut state.particles[first_new..] { - for axis in 0..3 { - p.pos[axis] += p.vel[axis]; - } - p.rot_z += p.spin_z; - } - } - - fn emit_particles( - state: &mut SimState, - comp: &Comp, - node: &Node, - emitter_hash: u64, - frame: i64, - t: f64, - expr: &ExprEngine, - ) { - let seed = comp.eval_number(node, "RandomSeed", t, 0.0, expr).round() as i64; - let mut rng = SplitMix64::from_parts(seed, frame, &node.name); - - let number = comp.eval_number(node, "Number", t, 10.0, expr).max(0.0); - let number_var = comp - .eval_number(node, "NumberVariance", t, 0.0, expr) - .max(0.0); - - let rate = (number + rng.signed() * number_var).max(0.0); - let accum = state.emit_accum.entry(emitter_hash).or_insert(0.0); - *accum += rate; - let mut emit_count = accum.floor() as usize; - *accum -= emit_count as f64; - - if emit_count == 0 { - return; - } - let remaining_cap = MAX_PARTICLES.saturating_sub(state.particles.len()); - if emit_count > remaining_cap { - emit_count = remaining_cap; - } - - let lifespan_base = comp.eval_number(node, "Lifespan", t, 100.0, expr).max(1.0); - let lifespan_var = comp - .eval_number(node, "LifespanVariance", t, 0.0, expr) - .max(0.0); - let pos_var = comp - .eval_number(node, "PositionVariance", t, 0.0, expr) - .max(0.0); - - let vel_base = comp.eval_number(node, "Velocity", t, 0.0, expr); - let vel_var = comp - .eval_number(node, "VelocityVariance", t, 0.0, expr) - .max(0.0); - let angle_base = comp.eval_number(node, "Angle", t, 0.0, expr); - let angle_var = comp - .eval_number(node, "AngleVariance", t, 0.0, expr) - .max(0.0); - let angle_z_base = comp.eval_number(node, "AngleZ", t, 0.0, expr); - let angle_z_var = comp - .eval_number(node, "AngleZVariance", t, 0.0, expr) - .max(0.0); - - let rot_z_base = comp.eval_number(node, "RotationZ", t, 0.0, expr); - let rot_z_var = comp - .eval_number(node, "RotationZVariance", t, 0.0, expr) - .max(0.0); - let spin_z_base = comp.eval_number(node, "SpinZ", t, 0.0, expr); - let spin_z_var = comp - .eval_number(node, "SpinZVariance", t, 0.0, expr) - .max(0.0); - - let base_r = comp.eval_number(node, "ParticleStyle.Red", t, 1.0, expr); - let base_g = comp.eval_number(node, "ParticleStyle.Green", t, 1.0, expr); - let base_b = comp.eval_number(node, "ParticleStyle.Blue", t, 1.0, expr); - let base_a = comp.eval_number(node, "ParticleStyle.Alpha", t, 1.0, expr); - - let red_lo_off = comp.eval_number(node, "ParticleStyle.RedLow", t, 0.0, expr); - let red_hi_off = comp.eval_number(node, "ParticleStyle.RedHigh", t, 0.0, expr); - let green_lo_off = comp.eval_number(node, "ParticleStyle.GreenLow", t, 0.0, expr); - let green_hi_off = comp.eval_number(node, "ParticleStyle.GreenHigh", t, 0.0, expr); - let blue_lo_off = comp.eval_number(node, "ParticleStyle.BlueLow", t, 0.0, expr); - let blue_hi_off = comp.eval_number(node, "ParticleStyle.BlueHigh", t, 0.0, expr); - let alpha_lo_off = comp.eval_number(node, "ParticleStyle.AlphaLow", t, 0.0, expr); - let alpha_hi_off = comp.eval_number(node, "ParticleStyle.AlphaHigh", t, 0.0, expr); - - let color_var = comp.eval_number(node, "ParticleStyle.ColorVariance", t, 0.0, expr) > 0.5 - || red_lo_off.abs() > 1e-9 - || red_hi_off.abs() > 1e-9 - || green_lo_off.abs() > 1e-9 - || green_hi_off.abs() > 1e-9 - || blue_lo_off.abs() > 1e-9 - || blue_hi_off.abs() > 1e-9 - || alpha_lo_off.abs() > 1e-9 - || alpha_hi_off.abs() > 1e-9; - - let r_lo = (base_r + red_lo_off).clamp(0.0, 1.0); - let r_hi = (base_r + red_hi_off).clamp(0.0, 1.0); - let g_lo = (base_g + green_lo_off).clamp(0.0, 1.0); - let g_hi = (base_g + green_hi_off).clamp(0.0, 1.0); - let b_lo = (base_b + blue_lo_off).clamp(0.0, 1.0); - let b_hi = (base_b + blue_hi_off).clamp(0.0, 1.0); - let a_lo = (base_a + alpha_lo_off).clamp(0.0, 1.0); - let a_hi = (base_a + alpha_hi_off).clamp(0.0, 1.0); - - // Fusion's ParticleStyle.Size defaults to 0.1 across all styles. - let size_base = comp - .eval_number(node, "ParticleStyle.Size", t, 0.1, expr) - .max(0.0); - let size_var = comp - .eval_number(node, "ParticleStyle.SizeVariance", t, 0.0, expr) - .max(0.0); - - let region = RegionSpec::from_node(comp, node, t, expr); - state.particles.reserve(emit_count); - - for _ in 0..emit_count { - let mut pos = region.sample(&mut rng); - if pos_var > 0.0 { - pos[0] += rng.signed() * pos_var; - pos[1] += rng.signed() * pos_var; - pos[2] += rng.signed() * pos_var; - } - - let speed = (vel_base + rng.signed() * vel_var) * VELOCITY_SCALE; - let ang = (angle_base + rng.signed() * angle_var).to_radians(); - let ang_z = (angle_z_base + rng.signed() * angle_z_var).to_radians(); - let cos_z = ang_z.cos(); - let vel = [ - speed * ang.cos() * cos_z, - speed * ang.sin() * cos_z, - speed * ang_z.sin(), - ]; - - let rot_z = rot_z_base + rng.signed() * rot_z_var; - let spin_z = spin_z_base + rng.signed() * spin_z_var; - let lifespan = (lifespan_base + rng.signed() * lifespan_var).max(1.0); - let size = (size_base + rng.signed() * size_var).max(0.0); - - let color = if color_var { - [ - rng.range(r_lo, r_hi) as f32, - rng.range(g_lo, g_hi) as f32, - rng.range(b_lo, b_hi) as f32, - rng.range(a_lo, a_hi) as f32, - ] - } else { - [ - base_r.clamp(0.0, 1.0) as f32, - base_g.clamp(0.0, 1.0) as f32, - base_b.clamp(0.0, 1.0) as f32, - base_a.clamp(0.0, 1.0) as f32, - ] - }; - - state.particles.push(Particle { - emitter_hash, - pos, - vel, - rot_z, - spin_z, - age: 0.0, - lifespan, - size, - color, - alive: true, - }); - } - } - - #[derive(Clone, Copy)] - pub(super) enum RegionSpec { - Point { - center: [f64; 3], - }, - Rect { - center: [f64; 3], - width: f64, - height: f64, - }, - Sphere { - center: [f64; 3], - radius: f64, - }, - Cube { - center: [f64; 3], - width: f64, - height: f64, - depth: f64, - }, - Line { - start: [f64; 3], - end: [f64; 3], - }, - All, - } - - impl RegionSpec { - pub(super) fn from_node(comp: &Comp, node: &Node, t: f64, expr: &ExprEngine) -> Self { - let region_name = node.static_str("Region").unwrap_or("SphereRgn"); - match region_name { - "RectRgn" => Self::Rect { - center: [ - comp.eval_number(node, "RectRgn.Translate.X", t, 0.0, expr), - comp.eval_number(node, "RectRgn.Translate.Y", t, 0.0, expr), - comp.eval_number(node, "RectRgn.Translate.Z", t, 0.0, expr), - ], - width: comp.eval_number(node, "RectRgn.Width", t, 0.1, expr).abs(), - height: comp.eval_number(node, "RectRgn.Height", t, 0.1, expr).abs(), - }, - "SphereRgn" => Self::Sphere { - center: [ - comp.eval_number(node, "SphereRgn.Translate.X", t, 0.0, expr), - comp.eval_number(node, "SphereRgn.Translate.Y", t, 0.0, expr), - comp.eval_number(node, "SphereRgn.Translate.Z", t, 0.0, expr), - ], - radius: comp.eval_number(node, "SphereRgn.Size", t, 0.1, expr).abs() * 0.5, - }, - "CubeRgn" => Self::Cube { - center: [ - comp.eval_number(node, "CubeRgn.Translate.X", t, 0.0, expr), - comp.eval_number(node, "CubeRgn.Translate.Y", t, 0.0, expr), - comp.eval_number(node, "CubeRgn.Translate.Z", t, 0.0, expr), - ], - width: comp.eval_number(node, "CubeRgn.Width", t, 0.1, expr).abs(), - height: comp.eval_number(node, "CubeRgn.Height", t, 0.1, expr).abs(), - depth: comp.eval_number(node, "CubeRgn.Depth", t, 0.1, expr).abs(), - }, - "LineRgn" => { - let tx = comp.eval_number(node, "LineRgn.Translate.X", t, 0.0, expr); - let ty = comp.eval_number(node, "LineRgn.Translate.Y", t, 0.0, expr); - let tz = comp.eval_number(node, "LineRgn.Translate.Z", t, 0.0, expr); - Self::Line { - start: [ - tx + comp.eval_number(node, "LineRgn.Start.X", t, -0.5, expr), - ty + comp.eval_number(node, "LineRgn.Start.Y", t, 0.0, expr), - tz + comp.eval_number(node, "LineRgn.Start.Z", t, 0.0, expr), - ], - end: [ - tx + comp.eval_number(node, "LineRgn.End.X", t, 0.5, expr), - ty + comp.eval_number(node, "LineRgn.End.Y", t, 0.0, expr), - tz + comp.eval_number(node, "LineRgn.End.Z", t, 0.0, expr), - ], - } - } - "AllRgn" | "All" => Self::All, - _ => Self::Point { - center: [ - comp.eval_number(node, "Point.Translate.X", t, 0.0, expr), - comp.eval_number(node, "Point.Translate.Y", t, 0.0, expr), - comp.eval_number(node, "Point.Translate.Z", t, 0.0, expr), - ], - }, - } - } - - fn sample(&self, rng: &mut SplitMix64) -> [f64; 3] { - match *self { - Self::Point { center } => center, - Self::Rect { - center, - width, - height, - } => [ - center[0] + (rng.next_f64() - 0.5) * width, - center[1] + (rng.next_f64() - 0.5) * height, - center[2], - ], - Self::Sphere { center, radius } => { - let u = rng.next_f64(); - let v = rng.next_f64(); - let w = rng.next_f64(); - let theta = u * std::f64::consts::TAU; - let cos_phi = 2.0 * v - 1.0; - let sin_phi = (1.0 - cos_phi * cos_phi).max(0.0).sqrt(); - let r = radius * w.cbrt(); - [ - center[0] + r * sin_phi * theta.cos(), - center[1] + r * sin_phi * theta.sin(), - center[2] + r * cos_phi, - ] - } - Self::Cube { - center, - width, - height, - depth, - } => [ - center[0] + (rng.next_f64() - 0.5) * width, - center[1] + (rng.next_f64() - 0.5) * height, - center[2] + (rng.next_f64() - 0.5) * depth, - ], - Self::Line { start, end } => { - let u = rng.next_f64(); - [ - start[0] + (end[0] - start[0]) * u, - start[1] + (end[1] - start[1]) * u, - start[2] + (end[2] - start[2]) * u, - ] - } - Self::All => [0.0, 0.0, 0.0], - } - } - - fn contains(&self, p: [f64; 3]) -> bool { - match *self { - Self::All => true, - Self::Point { center } => { - let dx = p[0] - center[0]; - let dy = p[1] - center[1]; - let dz = p[2] - center[2]; - dx * dx + dy * dy + dz * dz <= 1e-4 - } - Self::Rect { - center, - width, - height, - } => { - (p[0] - center[0]).abs() <= width * 0.5 - && (p[1] - center[1]).abs() <= height * 0.5 - } - Self::Sphere { center, radius } => { - let dx = p[0] - center[0]; - let dy = p[1] - center[1]; - let dz = p[2] - center[2]; - dx * dx + dy * dy + dz * dz <= radius * radius - } - Self::Cube { - center, - width, - height, - depth, - } => { - (p[0] - center[0]).abs() <= width * 0.5 - && (p[1] - center[1]).abs() <= height * 0.5 - && (p[2] - center[2]).abs() <= depth * 0.5 - } - Self::Line { start, end } => { - let vx = end[0] - start[0]; - let vy = end[1] - start[1]; - let vz = end[2] - start[2]; - let len_sq = vx * vx + vy * vy + vz * vz; - let u = if len_sq > 1e-9 { - (((p[0] - start[0]) * vx + (p[1] - start[1]) * vy + (p[2] - start[2]) * vz) - / len_sq) - .clamp(0.0, 1.0) - } else { - 0.0 - }; - let cx = start[0] + vx * u; - let cy = start[1] + vy * u; - let cz = start[2] + vz * u; - let dx = p[0] - cx; - let dy = p[1] - cy; - let dz = p[2] - cz; - dx * dx + dy * dy + dz * dz <= 1e-3 - } - } - } - - /// Parses a `pBounce` region (supports `LineRgn`, `RectRgn`, `CubeRgn`, `SphereRgn`, - /// `MeshRegion`, and `Transform3DOp.Translate` fallback). - fn from_bounce_node(comp: &Comp, node: &Node, t: f64, expr: &ExprEngine) -> Self { - let tx = comp.eval_number(node, "Transform3DOp.Translate.X", t, 0.0, expr); - let ty = comp.eval_number(node, "Transform3DOp.Translate.Y", t, 0.0, expr); - let tz = comp.eval_number(node, "Transform3DOp.Translate.Z", t, 0.0, expr); - match node.static_str("Region") { - Some("RectRgn") => Self::Rect { - center: [ - comp.eval_number(node, "RectRgn.Translate.X", t, tx, expr), - comp.eval_number(node, "RectRgn.Translate.Y", t, ty, expr), - comp.eval_number(node, "RectRgn.Translate.Z", t, tz, expr), - ], - width: comp.eval_number(node, "RectRgn.Width", t, 0.1, expr).abs(), - height: comp.eval_number(node, "RectRgn.Height", t, 0.1, expr).abs(), - }, - Some("SphereRgn") => Self::Sphere { - center: [ - comp.eval_number(node, "SphereRgn.Translate.X", t, tx, expr), - comp.eval_number(node, "SphereRgn.Translate.Y", t, ty, expr), - comp.eval_number(node, "SphereRgn.Translate.Z", t, tz, expr), - ], - radius: comp.eval_number(node, "SphereRgn.Size", t, 0.5, expr).abs() * 0.5, - }, - Some("CubeRgn") => Self::Cube { - center: [ - comp.eval_number(node, "CubeRgn.Translate.X", t, tx, expr), - comp.eval_number(node, "CubeRgn.Translate.Y", t, ty, expr), - comp.eval_number(node, "CubeRgn.Translate.Z", t, tz, expr), - ], - width: comp.eval_number(node, "CubeRgn.Width", t, 0.1, expr).abs(), - height: comp.eval_number(node, "CubeRgn.Height", t, 0.1, expr).abs(), - depth: comp.eval_number(node, "CubeRgn.Depth", t, 0.1, expr).abs(), - }, - Some("LineRgn") => { - let lx = comp.eval_number(node, "LineRgn.Translate.X", t, tx, expr); - let ly = comp.eval_number(node, "LineRgn.Translate.Y", t, ty, expr); - let lz = comp.eval_number(node, "LineRgn.Translate.Z", t, tz, expr); - Self::Line { - start: [ - lx + comp.eval_number(node, "LineRgn.Start.X", t, -0.5, expr), - ly + comp.eval_number(node, "LineRgn.Start.Y", t, 0.0, expr), - lz + comp.eval_number(node, "LineRgn.Start.Z", t, 0.0, expr), - ], - end: [ - lx + comp.eval_number(node, "LineRgn.End.X", t, 0.5, expr), - ly + comp.eval_number(node, "LineRgn.End.Y", t, 0.0, expr), - lz + comp.eval_number(node, "LineRgn.End.Z", t, 0.0, expr), - ], - } - } - Some("MeshRegion") | None => Self::Point { center: [tx, ty, tz] }, - _ => Self::from_node(comp, node, t, expr), - } - } - - /// Checks whether a particle stepping `pos -> pos + vel` collides with this bounce region. - /// Returns `(contact_pos, outward_unit_normal)` when a reflection should occur. - fn bounce_collision(&self, pos: [f64; 3], vel: [f64; 3]) -> Option<([f64; 3], [f64; 3])> { - let next = [pos[0] + vel[0], pos[1] + vel[1], pos[2] + vel[2]]; - match *self { - Self::Line { start, end } => { - let sx = end[0] - start[0]; - let sy = end[1] - start[1]; - let len_sq = sx * sx + sy * sy; - let len = len_sq.sqrt(); - if len < 1e-9 { - return None; - } - let mut n = [-sy / len, sx / len, 0.0]; - let d0 = (pos[0] - start[0]) * n[0] + (pos[1] - start[1]) * n[1]; - let d1 = (next[0] - start[0]) * n[0] + (next[1] - start[1]) * n[1]; - let crosses = (d0 * d1 <= 0.0 && (d0.abs() > 1e-12 || d1.abs() > 1e-12)) - || d1.abs() <= 1e-4; - if !crosses { - return None; - } - let alpha = if (d0 - d1).abs() > 1e-12 { - (d0 / (d0 - d1)).clamp(0.0, 1.0) - } else { - 1.0 - }; - let hit = [ - pos[0] + vel[0] * alpha, - pos[1] + vel[1] * alpha, - pos[2] + vel[2] * alpha, - ]; - let u = ((hit[0] - start[0]) * sx + (hit[1] - start[1]) * sy) / len_sq; - if !(-1e-4..=1.0 + 1e-4).contains(&u) { - return None; - } - let vn = vel[0] * n[0] + vel[1] * n[1]; - if vn > 0.0 { - n[0] = -n[0]; - n[1] = -n[1]; - } - if vel[0] * n[0] + vel[1] * n[1] >= -1e-12 { - return None; - } - Some(([hit[0] + n[0] * 1e-5, hit[1] + n[1] * 1e-5, hit[2]], n)) - } - Self::Sphere { center, radius } => { - if radius < 1e-6 { - return None; - } - let dp = [pos[0] - center[0], pos[1] - center[1], pos[2] - center[2]]; - let dn = [next[0] - center[0], next[1] - center[1], next[2] - center[2]]; - let r_pos = (dp[0] * dp[0] + dp[1] * dp[1] + dp[2] * dp[2]).sqrt(); - let r_next = (dn[0] * dn[0] + dn[1] * dn[1] + dn[2] * dn[2]).sqrt(); - if r_pos > radius && r_next > radius { - return None; - } - let ref_v = if r_pos > 1e-9 { - dp - } else if r_next > 1e-9 { - dn - } else { - [0.0, 1.0, 0.0] - }; - 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); - let mut n = [ref_v[0] / r_len, ref_v[1] / r_len, ref_v[2] / r_len]; - if r_pos < radius && r_next >= radius { - n = [-n[0], -n[1], -n[2]]; - let pushed = [ - center[0] - n[0] * (radius - 1e-5).max(0.0), - center[1] - n[1] * (radius - 1e-5).max(0.0), - center[2] - n[2] * (radius - 1e-5).max(0.0), - ]; - return Some((pushed, n)); - } - let pushed = [ - center[0] + n[0] * (radius + 1e-5), - center[1] + n[1] * (radius + 1e-5), - center[2] + n[2] * (radius + 1e-5), - ]; - Some((pushed, n)) - } - Self::Rect { - center, - width, - height, - } => { - let hx = width * 0.5; - let hy = height * 0.5; - if hy < 1e-6 { - let line = Self::Line { - start: [center[0] - hx, center[1], center[2]], - end: [center[0] + hx, center[1], center[2]], - }; - return line.bounce_collision(pos, vel); - } - if hx < 1e-6 { - let line = Self::Line { - start: [center[0], center[1] - hy, center[2]], - end: [center[0], center[1] + hy, center[2]], - }; - return line.bounce_collision(pos, vel); - } - bounce_aabb(pos, vel, center, [hx, hy, 1e6], false) - } - Self::Cube { - center, - width, - height, - depth, - } => bounce_aabb(pos, vel, center, [width * 0.5, height * 0.5, depth * 0.5], true), - Self::Point { center } => { - let cy = center[1]; - let d0 = pos[1] - cy; - let d1 = next[1] - cy; - if d0 * d1 <= 0.0 || d1.abs() <= 1e-5 { - let ny = if vel[1] < 0.0 { - 1.0 - } else if vel[1] > 0.0 { - -1.0 - } else { - return None; - }; - let alpha = if (d0 - d1).abs() > 1e-12 { - (d0 / (d0 - d1)).clamp(0.0, 1.0) - } else { - 1.0 - }; - let hit = [ - pos[0] + vel[0] * alpha, - cy + ny * 1e-5, - pos[2] + vel[2] * alpha, - ]; - return Some((hit, [0.0, ny, 0.0])); - } - None - } - Self::All => None, - } - } - } - - /// Slab-method segment-vs-AABB bounce helper (2D when `check_z == false`, 3D when `check_z == true`). - fn bounce_aabb( - pos: [f64; 3], - vel: [f64; 3], - center: [f64; 3], - half: [f64; 3], - check_z: bool, - ) -> Option<([f64; 3], [f64; 3])> { - let axes = if check_z { 3 } else { 2 }; - let mut inside_pos = true; - for a in 0..axes { - if (pos[a] - center[a]).abs() > half[a] { - inside_pos = false; - break; - } - } - - if inside_pos { - let mut best_axis = 0usize; - let mut best_pen = f64::INFINITY; - let mut best_sign = 1.0f64; - for a in 0..axes { - let delta = pos[a] - center[a]; - let pen = half[a] - delta.abs(); - if pen < best_pen { - best_pen = pen; - best_axis = a; - best_sign = if delta >= 0.0 { 1.0 } else { -1.0 }; - } - } - let mut n = [0.0; 3]; - n[best_axis] = best_sign; - let mut pushed = pos; - pushed[best_axis] = center[best_axis] + best_sign * (half[best_axis] + 1e-5); - return Some((pushed, n)); - } - - let mut t_min = 0.0_f64; - let mut t_max = 1.0_f64; - let mut hit_axis = 0usize; - let mut hit_sign = 1.0_f64; - - for a in 0..axes { - let min_b = center[a] - half[a]; - let max_b = center[a] + half[a]; - if vel[a].abs() < 1e-12 { - if pos[a] < min_b || pos[a] > max_b { - return None; - } - } else { - let inv = 1.0 / vel[a]; - let mut t1 = (min_b - pos[a]) * inv; - let mut t2 = (max_b - pos[a]) * inv; - let mut s = -1.0; - if t1 > t2 { - std::mem::swap(&mut t1, &mut t2); - s = 1.0; - } - if t1 > t_min { - t_min = t1; - hit_axis = a; - hit_sign = s; - } - t_max = t_max.min(t2); - if t_min > t_max { - return None; - } - } - } - - let mut n = [0.0; 3]; - n[hit_axis] = hit_sign; - let hit = [ - pos[0] + vel[0] * t_min + n[0] * 1e-5, - pos[1] + vel[1] * t_min + n[1] * 1e-5, - pos[2] + vel[2] * t_min + n[2] * 1e-5, - ]; - Some((hit, n)) - } - - fn apply_modifier( - particles: &mut [Particle], - comp: &Comp, - node: &Node, - scope: &HashSet, - t: f64, - expr: &ExprEngine, - ) { - match node.kind.as_str() { - "pPointForce" => { - let strength = comp.eval_number(node, "Strength", t, 0.1, expr); - if strength.abs() < 1e-12 { - return; - } - let power = comp.eval_number(node, "Power", t, 2.0, expr); - let tx = comp.eval_number(node, "Translate.X", t, 0.0, expr); - let ty = comp.eval_number(node, "Translate.Y", t, 0.0, expr); - let tz = comp.eval_number(node, "Translate.Z", t, 0.0, expr); - - for p in particles.iter_mut() { - if !p.alive || !scope.contains(&p.emitter_hash) { - continue; - } - let dx = tx - p.pos[0]; - let dy = ty - p.pos[1]; - let dz = tz - p.pos[2]; - let dist = (dx * dx + dy * dy + dz * dz).sqrt(); - if dist < 1e-7 { - continue; - } - let falloff = dist.max(0.005).powf(power); - let mag = (strength * POINT_FORCE_SCALE / falloff).clamp(-0.25, 0.25); - let inv_d = 1.0 / dist; - p.vel[0] += dx * inv_d * mag; - p.vel[1] += dy * inv_d * mag; - p.vel[2] += dz * inv_d * mag; - } - } - "pDirectionalForce" => { - let strength = comp.eval_number(node, "Strength", t, 0.1, expr); - if strength.abs() < 1e-12 { - return; - } - let dir = comp - .eval_number(node, "Direction", t, -90.0, expr) - .to_radians(); - let dir_z = comp - .eval_number(node, "DirectionZ", t, 0.0, expr) - .to_radians(); - let mag = strength * VELOCITY_SCALE * VELOCITY_SCALE; - let ax = mag * dir.cos() * dir_z.cos(); - let ay = mag * dir.sin() * dir_z.cos(); - let az = mag * dir_z.sin(); - - for p in particles.iter_mut() { - if !p.alive || !scope.contains(&p.emitter_hash) { - continue; - } - p.vel[0] += ax; - p.vel[1] += ay; - p.vel[2] += az; - } - } - "pDrag" | "pFriction" => { - let vel_fric = if node.kind == "pFriction" || !node.inputs.contains_key("Drag") { - comp.eval_number(node, "VelocityFriction", t, 0.05, expr) - } else { - comp.eval_number(node, "Drag", t, 0.05, expr) - }; - let damp = (1.0 - vel_fric).clamp(0.0, 1.0); - let spin_damp = if node.kind == "pFriction" || node.inputs.contains_key("SpinFriction") { - (1.0 - comp.eval_number(node, "SpinFriction", t, 0.05, expr)).clamp(0.0, 1.0) - } else { - 1.0 - }; - for p in particles.iter_mut() { - if !p.alive || !scope.contains(&p.emitter_hash) { - continue; - } - p.vel[0] *= damp; - p.vel[1] *= damp; - p.vel[2] *= damp; - p.spin_z *= spin_damp; - } - } - "pTurbulence" => { - let sx = comp.eval_number(node, "XStrength", t, 0.1, expr); - let sy = comp.eval_number(node, "YStrength", t, 0.1, expr); - let sz = comp.eval_number(node, "ZStrength", t, 0.1, expr); - if sx.abs() < 1e-12 && sy.abs() < 1e-12 && sz.abs() < 1e-12 { - return; - } - let density = comp.eval_number(node, "Density", t, 10.0, expr).max(0.01); - let seed = comp.eval_number(node, "RandomSeed", t, 0.0, expr).round() as u64; - let time_shift = t * 0.03; - - for p in particles.iter_mut() { - if !p.alive || !scope.contains(&p.emitter_hash) { - continue; - } - let qx = p.pos[0] * density + time_shift; - let qy = p.pos[1] * density - time_shift * 0.7; - let qz = p.pos[2] * density; - let nx = value_noise_3d(qx, qy, qz, seed); - let ny = - value_noise_3d(qx + 31.7, qy + 17.3, qz + 47.1, seed ^ 0x517C_C1B7_2722_0A95); - let nz = - value_noise_3d(qx - 19.4, qy + 53.9, qz - 11.2, seed ^ 0x9E37_79B9_7F4A_7C15); - p.vel[0] += nx * sx * TURBULENCE_SCALE; - p.vel[1] += ny * sy * TURBULENCE_SCALE; - p.vel[2] += nz * sz * TURBULENCE_SCALE; - } - } - "pKill" => { - let region = if node.static_str("Region").is_some() { - RegionSpec::from_node(comp, node, t, expr) - } else { - RegionSpec::All - }; - let kill_outside = matches!( - node.static_str("RegionMode"), - Some("Outside") | Some("Leaving") - ); - for p in particles.iter_mut() { - if !p.alive || !scope.contains(&p.emitter_hash) { - continue; - } - let inside = region.contains(p.pos); - if (!kill_outside && inside) || (kill_outside && !inside) { - p.alive = false; - } - } - } - "pBounce" => { - let region = RegionSpec::from_bounce_node(comp, node, t, expr); - let elasticity = comp.eval_number(node, "Elasticity", t, 1.0, expr).clamp(0.0, 2.0); - let variance = comp.eval_number(node, "Variance", t, 0.0, expr).max(0.0); - let friction = comp.eval_number(node, "Friction", t, 0.0, expr).clamp(0.0, 1.0); - let roughness = comp.eval_number(node, "Roughness", t, 0.0, expr).max(0.0); - let spin = comp.eval_number(node, "Spin", t, 0.0, expr); - let seed = comp.eval_number(node, "RandomSeed", t, 0.0, expr).round() as i64; - let mut rng = SplitMix64::from_parts(seed, t.round() as i64, &node.name); - - for p in particles.iter_mut() { - if !p.alive || !scope.contains(&p.emitter_hash) { - continue; - } - let Some((pushed_pos, n)) = region.bounce_collision(p.pos, p.vel) else { - continue; - }; - let vn = p.vel[0] * n[0] + p.vel[1] * n[1] + p.vel[2] * n[2]; - if vn < 0.0 { - let e = (elasticity * (1.0 + rng.signed() * variance)).clamp(0.0, 2.0); - let t_damp = (1.0 - friction).clamp(0.0, 1.0); - let vnx = vn * n[0]; - let vny = vn * n[1]; - let vnz = vn * n[2]; - let vtx = p.vel[0] - vnx; - let vty = p.vel[1] - vny; - let vtz = p.vel[2] - vnz; - p.vel[0] = vtx * t_damp - vnx * e; - p.vel[1] = vty * t_damp - vny * e; - p.vel[2] = vtz * t_damp - vnz * e; - if roughness > 1e-6 { - let scatter = roughness * 0.01 * vn.abs(); - p.vel[0] += rng.signed() * scatter; - p.vel[1] += rng.signed() * scatter; - p.vel[2] += rng.signed() * scatter; - } - if spin.abs() > 1e-9 { - p.spin_z += spin * (1.0 + 0.5 * rng.signed()); - } - p.pos = pushed_pos; - } - } - } - _ => {} - } - } - - /// Smooth deterministic 3D value noise in `[-1.0, 1.0]`. - fn value_noise_3d(x: f64, y: f64, z: f64, seed: u64) -> f64 { - let xi = x.floor() as i64; - let yi = y.floor() as i64; - let zi = z.floor() as i64; - let xf = x - xi as f64; - let yf = y - yi as f64; - let zf = z - zi as f64; - - let u = xf * xf * (3.0 - 2.0 * xf); - let v = yf * yf * (3.0 - 2.0 * yf); - let w = zf * zf * (3.0 - 2.0 * zf); - - let n000 = lattice_hash(xi, yi, zi, seed); - let n100 = lattice_hash(xi + 1, yi, zi, seed); - let n010 = lattice_hash(xi, yi + 1, zi, seed); - let n110 = lattice_hash(xi + 1, yi + 1, zi, seed); - let n001 = lattice_hash(xi, yi, zi + 1, seed); - let n101 = lattice_hash(xi + 1, yi, zi + 1, seed); - let n011 = lattice_hash(xi, yi + 1, zi + 1, seed); - let n111 = lattice_hash(xi + 1, yi + 1, zi + 1, seed); - - let nx00 = n000 + (n100 - n000) * u; - let nx10 = n010 + (n110 - n010) * u; - let nx01 = n001 + (n101 - n001) * u; - let nx11 = n011 + (n111 - n011) * u; - - let nxy0 = nx00 + (nx10 - nx00) * v; - let nxy1 = nx01 + (nx11 - nx01) * v; - - nxy0 + (nxy1 - nxy0) * w - } - - #[inline] - fn lattice_hash(x: i64, y: i64, z: i64, seed: u64) -> f64 { - let mut h = seed - ^ (x as u64).wrapping_mul(0x9E37_79B9_7F4A_7C15) - ^ (y as u64).wrapping_mul(0xBF58_476D_1CE4_E5B9) - ^ (z as u64).wrapping_mul(0x94D0_49BB_1331_11EB); - h = (h ^ (h >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9); - h = (h ^ (h >> 27)).wrapping_mul(0x94D0_49BB_1331_11EB); - h ^= h >> 31; - let unit = (h >> 11) as f64 * (1.0 / ((1u64 << 53) as f64)); - unit * 2.0 - 1.0 - } -} - -/// Optimized 2D particle rasterization (points, separable Gaussian blobs, NGons, and bitmap sprites). -mod raster { - use std::collections::HashMap; - - use model::{Comp, ExprEngine, Gradient, Node, NodeId}; - - use super::{ - BLOB_SIGMA_PER_SIZE, CAMERA_DISTANCE, Particle, ParticleStyleKind, SpriteImage, - }; - - const INV_255: f32 = 1.0 / 255.0; - - pub(super) struct DrawCmd { - min_x: usize, - max_x: usize, - min_y: usize, - max_y: usize, - color: [f32; 4], - shape: DrawShape, - } - - enum DrawShape { - Point, - Blob { - cx: f64, - cy: f64, - inv_two_sigma_sq: f64, - }, - NGon { - cx: f64, - cy: f64, - inv_two_sigma_sq: f64, - inv_half_period: f64, - spike_period: f64, - phase: f64, - sharpness: f64, - }, - Bitmap { - emitter_idx: usize, - cx: f64, - cy: f64, - draw_w: f64, - draw_h: f64, - rot_z_deg: f64, - }, - } - - struct EmitterRenderProps<'a> { - emitter_hash: u64, - style: ParticleStyleKind, - /// Owned 1x1 tiny-background sprite, if applicable. - tiny_sprite: Option<([f64; 2], SpriteImage)>, - /// External sprite reference + nominal dimensions when not a tiny background. - ext_sprite: Option<(&'a SpriteImage, [f64; 2])>, - ngon_sides: f64, - size_over_life: Option<&'a model::BezierSpline>, - fade_in: f64, - fade_out: f64, - color_over_life: Option, - } - - impl<'a> EmitterRenderProps<'a> { - #[inline] - fn resolved_sprite(&self) -> Option<(&SpriteImage, [f64; 2])> { - match &self.tiny_sprite { - Some((nominal, sprite)) => Some((sprite, *nominal)), - None => self.ext_sprite, - } - } - } - - fn collect_emitter_render_props<'a>( - comp: &'a Comp, - emitter_nodes: &HashMap, - time: f64, - expr: &ExprEngine, - sprites: &'a HashMap, - ) -> Vec> { - let mut list = Vec::with_capacity(emitter_nodes.len()); - for (&emitter_hash, &emitter_id) in emitter_nodes { - let Some(node) = comp.nodes.get(emitter_id.0) else { - continue; - }; - let style = match node.static_str("Style") { - Some("ParticleStyleBitmap") => ParticleStyleKind::Bitmap, - Some("ParticleStyleBlob") => ParticleStyleKind::Blob, - Some("ParticleStyleNGon") => ParticleStyleKind::NGon, - Some("ParticleStyleBrush") => ParticleStyleKind::Brush, - _ => ParticleStyleKind::Point, - }; - let size_over_life = node - .inputs - .get("ParticleStyle.SizeOverLife") - .and_then(|b| b.source_op.as_deref()) - .and_then(|src| comp.splines.get(src)); - let fade_in = comp - .eval_number(node, "ParticleStyle.FadeIn", time, 0.0, expr) - .clamp(0.0, 1.0); - let fade_out = comp - .eval_number(node, "ParticleStyle.FadeOut", time, 1.0, expr) - .clamp(0.0, 1.0); - let color_over_life_on = - comp.eval_number(node, "ParticleStyle.ColorOverLifeControls", time, 0.0, expr) - > 0.5; - let color_over_life = if color_over_life_on { - comp.eval_gradient(node, "ParticleStyle.ColorOverLife", time) - } else { - None - }; - let tiny_sprite = tiny_background_sprite(comp, node, time, expr); - let ext_sprite = if tiny_sprite.is_none() && style == ParticleStyleKind::Bitmap { - sprites - .get(&emitter_id) - .filter(|s| { - s.size[0] > 0 - && s.size[1] > 0 - && s.rgba.len() - >= (s.size[0] as usize) - .saturating_mul(s.size[1] as usize) - .saturating_mul(4) - }) - .map(|s| (s, [s.size[0] as f64, s.size[1] as f64])) - } else { - None - }; - list.push(EmitterRenderProps { - emitter_hash, - style, - tiny_sprite, - ext_sprite, - ngon_sides: comp - .eval_number(node, "ParticleStyleNGon.NGonSides", time, 5.0, expr) - .round() - .max(3.0), - size_over_life, - fade_in, - fade_out, - color_over_life, - }); - } - list - } - - /// Solid sprite for a `Background` tool narrower than 16 px. - fn tiny_background_sprite( - comp: &Comp, - emitter: &Node, - t: f64, - expr: &ExprEngine, - ) -> Option<([f64; 2], SpriteImage)> { - let src = emitter - .connected_node("ParticleStyleBitmap.DropToolsHere") - .and_then(|name| comp.find_node(name)) - .map(|id| &comp.nodes[id.0]) - .filter(|n| n.kind == "Background")?; - let w = comp.eval_number(src, "Width", t, 0.0, expr); - let h = comp.eval_number(src, "Height", t, 0.0, expr); - if !(w >= 1.0 && h >= 1.0 && (w < 16.0 || h < 16.0)) { - return None; - } - let channel = - |name: &str, default: f64| comp.eval_number(src, name, t, default, expr).clamp(0.0, 1.0); - let a = channel("TopLeftAlpha", 1.0); - let px = |c: f64| (c * a * 255.0 + 0.5) as u8; - let rgba = vec![ - px(channel("TopLeftRed", 0.0)), - px(channel("TopLeftGreen", 0.0)), - px(channel("TopLeftBlue", 0.0)), - (a * 255.0 + 0.5) as u8, - ]; - Some(([w, h], SpriteImage { size: [1, 1], rgba })) - } - - /// Clamps a floating-point `[lo, hi]` interval to `[0, limit - 1]`, returning `None` if empty. - #[inline] - fn clip_bounds(lo: f64, hi: f64, limit: usize) -> Option<(usize, usize)> { - if limit == 0 || !lo.is_finite() || !hi.is_finite() { - return None; - } - let max_i = (limit - 1) as isize; - let a = lo.floor() as isize; - let b = hi.ceil() as isize; - if b < 0 || a > max_i { - return None; - } - let min_u = a.max(0) as usize; - let max_u = b.min(max_i) as usize; - (min_u <= max_u).then_some((min_u, max_u)) - } - - #[allow(clippy::too_many_arguments)] - pub(super) fn rasterize_particles( - out: &mut [u8], - scratch_accum: &mut Vec, - scratch_cmds: &mut Vec, - dims: [u32; 2], - px_scale: f64, - comp: &Comp, - emitter_nodes: &HashMap, - particles: &[Particle], - time: f64, - expr: &ExprEngine, - sprites: &HashMap, - ) { - if particles.is_empty() { - return; - } - - let w = dims[0] as usize; - let h = dims[1] as usize; - if w == 0 || h == 0 { - return; - } - let w_f = w as f64; - let h_f = h as f64; - - let props_list = collect_emitter_render_props(comp, emitter_nodes, time, expr, sprites); - if props_list.is_empty() { - return; - } - - scratch_cmds.clear(); - if scratch_cmds.capacity() < particles.len() { - scratch_cmds.reserve(particles.len() - scratch_cmds.capacity()); - } - - let mut dirty_y0 = h; - let mut dirty_y1 = 0usize; - let mut last_hash = u64::MAX; - let mut last_idx = usize::MAX; - - for p in particles { - if !p.alive { - continue; - } - let props_idx = if p.emitter_hash == last_hash && last_idx < props_list.len() { - last_idx - } else { - let Some(idx) = props_list.iter().position(|pr| pr.emitter_hash == p.emitter_hash) - else { - continue; - }; - last_hash = p.emitter_hash; - last_idx = idx; - idx - }; - let props = &props_list[props_idx]; - - let life_frac = (p.age / p.lifespan.max(1.0)).clamp(0.0, 1.0); - let size_mult = props - .size_over_life - .map(|sp| (2.0 * sp.eval(life_frac)).max(0.0)) - .unwrap_or(1.0); - let depth_scale = CAMERA_DISTANCE / (CAMERA_DISTANCE + p.pos[2]); - if !(depth_scale > 0.0) { - continue; - } - let size_world = p.size * size_mult * depth_scale; - if size_world <= 1e-6 { - continue; - } - - let mut fade = 1.0f64; - if props.fade_in > 1e-6 && life_frac < props.fade_in { - fade *= life_frac / props.fade_in; - } - if props.fade_out < 1.0 - 1e-6 && life_frac > props.fade_out { - fade *= ((1.0 - life_frac) / (1.0 - props.fade_out)).max(0.0); - } - - let mut cr = p.color[0]; - let mut cg = p.color[1]; - let mut cb = p.color[2]; - let mut ca = p.color[3] * fade as f32; - if let Some(grad) = &props.color_over_life { - let g = grad.sample(life_frac); - cr *= g[0]; - cg *= g[1]; - cb *= g[2]; - ca *= g[3]; - } - ca = ca.clamp(0.0, 1.0); - if ca <= 1e-4 { - continue; - } - - let cx = (p.pos[0] * depth_scale + 0.5) * w_f; - let cy = h_f * 0.5 - p.pos[1] * depth_scale * w_f; - - if props.style == ParticleStyleKind::Bitmap { - if let Some((_, nominal)) = props.resolved_sprite() { - let draw_w = size_world * nominal[0] * px_scale; - let draw_h = size_world * nominal[1] * px_scale; - if draw_w < 0.5 || draw_h < 0.5 { - continue; - } - let hw = draw_w * 0.5; - let hh = draw_h * 0.5; - let (rx, ry) = if p.rot_z.abs() <= 1e-6 { - (hw + 1.0, hh + 1.0) - } else { - let theta = p.rot_z.to_radians(); - let ca_t = theta.cos().abs(); - let sa_t = theta.sin().abs(); - (hw * ca_t + hh * sa_t + 1.0, hw * sa_t + hh * ca_t + 1.0) - }; - let Some((min_x, max_x)) = clip_bounds(cx - rx, cx + rx, w) else { - continue; - }; - let Some((min_y, max_y)) = clip_bounds(cy - ry, cy + ry, h) else { - continue; - }; - dirty_y0 = dirty_y0.min(min_y); - dirty_y1 = dirty_y1.max(max_y + 1); - scratch_cmds.push(DrawCmd { - min_x, - max_x, - min_y, - max_y, - color: [cr, cg, cb, ca], - shape: DrawShape::Bitmap { - emitter_idx: props_idx, - cx, - cy, - draw_w, - draw_h, - rot_z_deg: p.rot_z, - }, - }); - continue; - } - } - - match props.style { - ParticleStyleKind::Point => { - let ix = cx.floor() as isize; - let iy = cy.floor() as isize; - if ix < 0 || iy < 0 || ix >= w as isize || iy >= h as isize { - continue; - } - let ux = ix as usize; - let uy = iy as usize; - dirty_y0 = dirty_y0.min(uy); - dirty_y1 = dirty_y1.max(uy + 1); - scratch_cmds.push(DrawCmd { - min_x: ux, - max_x: ux, - min_y: uy, - max_y: uy, - color: [cr, cg, cb, ca], - shape: DrawShape::Point, - }); - } - ParticleStyleKind::Blob | ParticleStyleKind::Bitmap => { - let sigma = BLOB_SIGMA_PER_SIZE * size_world * px_scale; - if sigma <= 1e-6 { - continue; - } - let inv_two_sigma_sq = 0.5 / (sigma * sigma); - let bound = (4.0 * sigma).min((((ca as f64) * 1.0e5).ln().max(0.0) / inv_two_sigma_sq).sqrt()); - let Some((min_x, max_x)) = clip_bounds(cx - bound, cx + bound, w) else { - continue; - }; - let Some((min_y, max_y)) = clip_bounds(cy - bound, cy + bound, h) else { - continue; - }; - dirty_y0 = dirty_y0.min(min_y); - dirty_y1 = dirty_y1.max(max_y + 1); - scratch_cmds.push(DrawCmd { - min_x, - max_x, - min_y, - max_y, - color: [cr, cg, cb, ca], - shape: DrawShape::Blob { - cx, - cy, - inv_two_sigma_sq, - }, - }); - } - ParticleStyleKind::NGon => { - let sigma = BLOB_SIGMA_PER_SIZE * size_world * px_scale; - if sigma <= 1e-6 { - continue; - } - let inv_two_sigma_sq = 0.5 / (sigma * sigma); - let bound = (4.0 * sigma).min((((ca as f64) * 1.0e5).ln().max(0.0) / inv_two_sigma_sq).sqrt()); - let Some((min_x, max_x)) = clip_bounds(cx - bound, cx + bound, w) else { - continue; - }; - let Some((min_y, max_y)) = clip_bounds(cy - bound, cy + bound, h) else { - continue; - }; - let sides = props.ngon_sides; - let spike_period = std::f64::consts::TAU / sides; - let phase = std::f64::consts::FRAC_PI_2 + p.rot_z.to_radians(); - let sharpness = 4.5 * (3.0 / sides).powf(2.8); - dirty_y0 = dirty_y0.min(min_y); - dirty_y1 = dirty_y1.max(max_y + 1); - scratch_cmds.push(DrawCmd { - min_x, - max_x, - min_y, - max_y, - color: [cr, cg, cb, ca], - shape: DrawShape::NGon { - cx, - cy, - inv_two_sigma_sq, - inv_half_period: 2.0 / spike_period, - spike_period, - phase, - sharpness, - }, - }); - } - ParticleStyleKind::Brush => {} - } - } - - if scratch_cmds.is_empty() || dirty_y0 >= dirty_y1 { - return; - } - - let needed_floats = w * h * 4; - if scratch_accum.len() < needed_floats { - scratch_accum.resize(needed_floats, 0.0); - } - - rasterize_bands( - out, - &mut scratch_accum[..needed_floats], - w, - dirty_y0, - dirty_y1, - scratch_cmds, - &props_list, - ); - } - - fn rasterize_bands( - out: &mut [u8], - accum: &mut [f32], - w: usize, - dirty_y0: usize, - dirty_y1: usize, - cmds: &[DrawCmd], - props_list: &[EmitterRenderProps<'_>], - ) { - #[cfg(not(target_arch = "wasm32"))] - { - let dirty_rows = dirty_y1 - dirty_y0; - let dirty_pixels = dirty_rows * w; - if dirty_pixels >= 120_000 && dirty_rows >= 32 && cmds.len() >= 16 { - let workers = std::thread::available_parallelism() - .map(|n| n.get()) - .unwrap_or(1) - .min(8) - .min(dirty_rows / 16); - if workers > 1 { - let stride = w * 4; - let rows_per_band = dirty_rows.div_ceil(workers); - let accum_dirty = &mut accum[dirty_y0 * stride..dirty_y1 * stride]; - let out_dirty = &mut out[dirty_y0 * stride..dirty_y1 * stride]; - std::thread::scope(|scope| { - let mut a_rest = accum_dirty; - let mut o_rest = out_dirty; - let mut band_y0 = dirty_y0; - while band_y0 < dirty_y1 { - let take_rows = rows_per_band.min(dirty_y1 - band_y0); - let take_elems = take_rows * stride; - let (a_band, a_next) = a_rest.split_at_mut(take_elems); - let (o_band, o_next) = o_rest.split_at_mut(take_elems); - a_rest = a_next; - o_rest = o_next; - let band_y1 = band_y0 + take_rows; - scope.spawn(move || { - rasterize_single_band( - o_band, - a_band, - w, - band_y0, - band_y1, - cmds, - props_list, - ); - }); - band_y0 = band_y1; - } - }); - return; - } - } - } - - let stride = w * 4; - let start = dirty_y0 * stride; - let end = dirty_y1 * stride; - rasterize_single_band( - &mut out[start..end], - &mut accum[start..end], - w, - dirty_y0, - dirty_y1, - cmds, - props_list, - ); - } - - fn rasterize_single_band( - out_band: &mut [u8], - accum_band: &mut [f32], - w: usize, - band_y0: usize, - band_y1: usize, - cmds: &[DrawCmd], - props_list: &[EmitterRenderProps<'_>], - ) { - let stride = w * 4; - let mut wx_heap: Vec = Vec::new(); - let mut wx_stack = [0.0f32; 64]; - - for cmd in cmds { - if cmd.max_y < band_y0 || cmd.min_y >= band_y1 { - continue; - } - let y_lo = cmd.min_y.max(band_y0); - let y_hi = cmd.max_y.min(band_y1 - 1); - let x_lo = cmd.min_x; - let x_hi = cmd.max_x; - - match cmd.shape { - DrawShape::Point => { - let pa = cmd.color[3]; - let off = (y_lo - band_y0) * stride + x_lo * 4; - let dst = &mut accum_band[off..off + 4]; - if pa >= 1.0 - 1e-5 { - dst[0] = cmd.color[0]; - dst[1] = cmd.color[1]; - dst[2] = cmd.color[2]; - dst[3] = 1.0; - } else { - let inv_a = 1.0 - pa; - dst[0] = cmd.color[0] * pa + dst[0] * inv_a; - dst[1] = cmd.color[1] * pa + dst[1] * inv_a; - dst[2] = cmd.color[2] * pa + dst[2] * inv_a; - dst[3] = pa + dst[3] * inv_a; - } - } - DrawShape::Blob { - cx, - cy, - inv_two_sigma_sq, - } => { - let span_x = x_hi - x_lo + 1; - let wx: &mut [f32] = if span_x <= wx_stack.len() { - &mut wx_stack[..span_x] - } else { - wx_heap.resize(span_x, 0.0); - &mut wx_heap[..span_x] - }; - for (i, w_slot) in wx.iter_mut().enumerate() { - let dx = (x_lo + i) as f64 + 0.5 - cx; - *w_slot = (-(dx * dx) * inv_two_sigma_sq).exp() as f32; - } - - let sa = cmd.color[3]; - let sr = cmd.color[0] * sa; - let sg = cmd.color[1] * sa; - let sb = cmd.color[2] * sa; - let row_x_start = x_lo * 4; - let row_x_end = (x_hi + 1) * 4; - - for py in y_lo..=y_hi { - let dy = py as f64 + 0.5 - cy; - let wy = (-(dy * dy) * inv_two_sigma_sq).exp() as f32; - let row_a = sa * wy; - if row_a <= 1e-5 { - continue; - } - let row_r = sr * wy; - let row_g = sg * wy; - let row_b = sb * wy; - let row_off = (py - band_y0) * stride; - let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end]; - for (dst, &gx) in row_pixels.chunks_exact_mut(4).zip(wx.iter()) { - let pa = row_a * gx; - if pa <= 1e-5 { - continue; - } - let inv_a = 1.0 - pa; - dst[0] = row_r * gx + dst[0] * inv_a; - dst[1] = row_g * gx + dst[1] * inv_a; - dst[2] = row_b * gx + dst[2] * inv_a; - dst[3] = pa + dst[3] * inv_a; - } - } - } - DrawShape::NGon { - cx, - cy, - inv_two_sigma_sq, - inv_half_period, - spike_period, - phase, - sharpness, - } => { - let span_x = x_hi - x_lo + 1; - let wx: &mut [f32] = if span_x <= wx_stack.len() { - &mut wx_stack[..span_x] - } else { - wx_heap.resize(span_x, 0.0); - &mut wx_heap[..span_x] - }; - for (i, w_slot) in wx.iter_mut().enumerate() { - let dx = (x_lo + i) as f64 + 0.5 - cx; - *w_slot = (-(dx * dx) * inv_two_sigma_sq).exp() as f32; - } - - let sa = cmd.color[3]; - let cr = cmd.color[0]; - let cg = cmd.color[1]; - let cb = cmd.color[2]; - let row_x_start = x_lo * 4; - let row_x_end = (x_hi + 1) * 4; - - for py in y_lo..=y_hi { - let dy = py as f64 + 0.5 - cy; - let wy = (-(dy * dy) * inv_two_sigma_sq).exp() as f32; - let row_a = sa * wy; - if row_a <= 1e-5 { - continue; - } - let row_off = (py - band_y0) * stride; - let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end]; - for (i, dst) in row_pixels.chunks_exact_mut(4).enumerate() { - let env_a = row_a * wx[i]; - if env_a <= 1e-5 { - continue; - } - let dx = (x_lo + i) as f64 + 0.5 - cx; - let angle = (-dy).atan2(dx) - phase; - let off = angle.rem_euclid(spike_period); - let to_spike = off.min(spike_period - off); - let shape_w = (1.0 - to_spike * inv_half_period).powf(sharpness) as f32; - let pa = env_a * shape_w; - if pa <= 1e-5 { - continue; - } - let inv_a = 1.0 - pa; - dst[0] = cr * pa + dst[0] * inv_a; - dst[1] = cg * pa + dst[1] * inv_a; - dst[2] = cb * pa + dst[2] * inv_a; - dst[3] = pa + dst[3] * inv_a; - } - } - } - DrawShape::Bitmap { - emitter_idx, - cx, - cy, - draw_w, - draw_h, - rot_z_deg, - } => { - let Some((sprite, _)) = props_list[emitter_idx].resolved_sprite() else { - continue; - }; - draw_bitmap_band( - accum_band, - stride, - band_y0, - y_lo, - y_hi, - x_lo, - x_hi, - cx, - cy, - draw_w, - draw_h, - rot_z_deg, - cmd.color, - sprite, - ); - } - } - } - - // Pack premultiplied f32 -> u8 and simultaneously reset `accum_band` to 0.0 - // while the cache lines are hot so `scratch_accum` stays zeroed for the next frame. - for (dst, src) in out_band.iter_mut().zip(accum_band.iter_mut()) { - let v = *src; - *src = 0.0; - *dst = (v.clamp(0.0, 1.0) * 255.0 + 0.5) as u8; - } - } - - #[allow(clippy::too_many_arguments)] - #[inline] - fn draw_bitmap_band( - accum_band: &mut [f32], - stride: usize, - band_y0: usize, - y_lo: usize, - y_hi: usize, - x_lo: usize, - x_hi: usize, - cx: f64, - cy: f64, - draw_w: f64, - draw_h: f64, - rot_z_deg: f64, - tint: [f32; 4], - sprite: &SpriteImage, - ) { - let inv_dw = 1.0 / draw_w; - let inv_dh = 1.0 / draw_h; - let edge_u = inv_dw * 0.5; - let edge_v = inv_dh * 0.5; - let inv_2edge_u = 1.0 / (2.0 * edge_u); - let inv_2edge_v = 1.0 / (2.0 * edge_v); - let sw_i = sprite.size[0] as usize; - let sh_i = sprite.size[1] as usize; - let row_x_start = x_lo * 4; - let row_x_end = (x_hi + 1) * 4; - - // Fast path: axis-aligned (unrotated) sprite. - if rot_z_deg.abs() <= 1e-6 { - let u0 = (x_lo as f64 + 0.5 - cx) * inv_dw + 0.5; - if sw_i == 1 && sh_i == 1 { - let s0 = sprite.rgba[0] as f32 * INV_255 * tint[0] * tint[3]; - let s1 = sprite.rgba[1] as f32 * INV_255 * tint[1] * tint[3]; - let s2 = sprite.rgba[2] as f32 * INV_255 * tint[2] * tint[3]; - let s3 = sprite.rgba[3] as f32 * INV_255 * tint[3]; - if s3 <= 1e-5 { - return; - } - for py in y_lo..=y_hi { - let v = (py as f64 + 0.5 - cy) * inv_dh + 0.5; - if v <= -edge_v || v >= 1.0 + edge_v { - continue; - } - let cov_v = ((v + edge_v) * inv_2edge_v) - .min((1.0 + edge_v - v) * inv_2edge_v) - .clamp(0.0, 1.0); - if cov_v <= 1e-4 { - continue; - } - let cov_vf = cov_v as f32; - let row_off = (py - band_y0) * stride; - let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end]; - let mut u = u0; - for dst in row_pixels.chunks_exact_mut(4) { - if u > -edge_u && u < 1.0 + edge_u { - let cov_u = ((u + edge_u) * inv_2edge_u) - .min((1.0 + edge_u - u) * inv_2edge_u) - .clamp(0.0, 1.0); - let cov = cov_u as f32 * cov_vf; - if cov > 1e-4 { - let pa = s3 * cov; - if pa > 1e-5 { - let inv_a = 1.0 - pa; - dst[0] = s0 * cov + dst[0] * inv_a; - dst[1] = s1 * cov + dst[1] * inv_a; - dst[2] = s2 * cov + dst[2] * inv_a; - dst[3] = pa + dst[3] * inv_a; - } - } - } - u += inv_dw; - } - } - return; - } - - let sw_f = sw_i as f64; - let sh_f = sh_i as f64; - let sw_max = (sw_i - 1) as f64; - let sh_max = (sh_i - 1) as f64; - let tr = tint[0] * INV_255; - let tg = tint[1] * INV_255; - let tb = tint[2] * INV_255; - let ta = tint[3] * INV_255; - - for py in y_lo..=y_hi { - let v = (py as f64 + 0.5 - cy) * inv_dh + 0.5; - if v <= -edge_v || v >= 1.0 + edge_v { - continue; - } - let cov_v = ((v + edge_v) * inv_2edge_v) - .min((1.0 + edge_v - v) * inv_2edge_v) - .clamp(0.0, 1.0); - if cov_v <= 1e-4 { - continue; - } - let fy = (v.clamp(0.0, 1.0) * sh_f - 0.5).clamp(0.0, sh_max); - let y0 = fy.floor() as usize; - let y1 = (y0 + 1).min(sh_i - 1); - let ty = (fy - y0 as f64) as f32; - let one_minus_ty = 1.0 - ty; - let row0 = y0 * sw_i; - let row1 = y1 * sw_i; - let cov_vf = cov_v as f32; - - let row_off = (py - band_y0) * stride; - let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end]; - let mut u = u0; - for dst in row_pixels.chunks_exact_mut(4) { - if u > -edge_u && u < 1.0 + edge_u { - let cov_u = ((u + edge_u) * inv_2edge_u) - .min((1.0 + edge_u - u) * inv_2edge_u) - .clamp(0.0, 1.0); - let cov = cov_u as f32 * cov_vf; - if cov > 1e-4 { - let fx = (u.clamp(0.0, 1.0) * sw_f - 0.5).clamp(0.0, sw_max); - let x0 = fx.floor() as usize; - let x1 = (x0 + 1).min(sw_i - 1); - let tx = (fx - x0 as f64) as f32; - let omt = 1.0 - tx; - - let w00 = omt * one_minus_ty; - let w10 = tx * one_minus_ty; - let w01 = omt * ty; - let w11 = tx * ty; - - let i00 = (row0 + x0) * 4; - let i10 = (row0 + x1) * 4; - let i01 = (row1 + x0) * 4; - let i11 = (row1 + x1) * 4; - - let s_a = sprite.rgba[i00 + 3] as f32 * w00 - + sprite.rgba[i10 + 3] as f32 * w10 - + sprite.rgba[i01 + 3] as f32 * w01 - + sprite.rgba[i11 + 3] as f32 * w11; - let pa = s_a * ta * cov; - if pa > 1e-5 { - let s_r = sprite.rgba[i00] as f32 * w00 - + sprite.rgba[i10] as f32 * w10 - + sprite.rgba[i01] as f32 * w01 - + sprite.rgba[i11] as f32 * w11; - let s_g = sprite.rgba[i00 + 1] as f32 * w00 - + sprite.rgba[i10 + 1] as f32 * w10 - + sprite.rgba[i01 + 1] as f32 * w01 - + sprite.rgba[i11 + 1] as f32 * w11; - let s_b = sprite.rgba[i00 + 2] as f32 * w00 - + sprite.rgba[i10 + 2] as f32 * w10 - + sprite.rgba[i01 + 2] as f32 * w01 - + sprite.rgba[i11 + 2] as f32 * w11; - let inv_a = 1.0 - pa; - dst[0] = s_r * (tr * cov * tint[3]) + dst[0] * inv_a; - dst[1] = s_g * (tg * cov * tint[3]) + dst[1] * inv_a; - dst[2] = s_b * (tb * cov * tint[3]) + dst[2] * inv_a; - dst[3] = pa + dst[3] * inv_a; - } - } - } - u += inv_dw; - } - } - return; - } - - // General rotated bitmap path with incremental scanline UV stepping. - let theta = rot_z_deg.to_radians(); - let cos_t = theta.cos(); - let sin_t = theta.sin(); - let du_dx = cos_t * inv_dw; - let dv_dx = sin_t * inv_dh; - let dx0 = (x_lo as f64 + 0.5) - cx; - let sw_f = sw_i as f64; - let sh_f = sh_i as f64; - let sw_max = (sw_i - 1) as f64; - let sh_max = (sh_i - 1) as f64; - let tr = tint[0] * tint[3] * INV_255; - let tg = tint[1] * tint[3] * INV_255; - let tb = tint[2] * tint[3] * INV_255; - let ta = tint[3] * INV_255; - - for py in y_lo..=y_hi { - let dy = (py as f64 + 0.5) - cy; - let mut u = (dx0 * cos_t - dy * sin_t) * inv_dw + 0.5; - let mut v = (dx0 * sin_t + dy * cos_t) * inv_dh + 0.5; - let row_off = (py - band_y0) * stride; - let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end]; - - for dst in row_pixels.chunks_exact_mut(4) { - if u > -edge_u && u < 1.0 + edge_u && v > -edge_v && v < 1.0 + edge_v { - let cov_u = ((u + edge_u) * inv_2edge_u) - .min((1.0 + edge_u - u) * inv_2edge_u) - .clamp(0.0, 1.0); - let cov_v = ((v + edge_v) * inv_2edge_v) - .min((1.0 + edge_v - v) * inv_2edge_v) - .clamp(0.0, 1.0); - let cov = (cov_u * cov_v) as f32; - if cov > 1e-4 { - let fx = (u.clamp(0.0, 1.0) * sw_f - 0.5).clamp(0.0, sw_max); - let fy = (v.clamp(0.0, 1.0) * sh_f - 0.5).clamp(0.0, sh_max); - let x0 = fx.floor() as usize; - let y0 = fy.floor() as usize; - let x1 = (x0 + 1).min(sw_i - 1); - let y1 = (y0 + 1).min(sh_i - 1); - let tx = (fx - x0 as f64) as f32; - let ty = (fy - y0 as f64) as f32; - - let w00 = (1.0 - tx) * (1.0 - ty); - let w10 = tx * (1.0 - ty); - let w01 = (1.0 - tx) * ty; - let w11 = tx * ty; - - let i00 = (y0 * sw_i + x0) * 4; - let i10 = (y0 * sw_i + x1) * 4; - let i01 = (y1 * sw_i + x0) * 4; - let i11 = (y1 * sw_i + x1) * 4; - - let s_a = sprite.rgba[i00 + 3] as f32 * w00 - + sprite.rgba[i10 + 3] as f32 * w10 - + sprite.rgba[i01 + 3] as f32 * w01 - + sprite.rgba[i11 + 3] as f32 * w11; - let pa = s_a * ta * cov; - if pa > 1e-5 { - let s_r = sprite.rgba[i00] as f32 * w00 - + sprite.rgba[i10] as f32 * w10 - + sprite.rgba[i01] as f32 * w01 - + sprite.rgba[i11] as f32 * w11; - let s_g = sprite.rgba[i00 + 1] as f32 * w00 - + sprite.rgba[i10 + 1] as f32 * w10 - + sprite.rgba[i01 + 1] as f32 * w01 - + sprite.rgba[i11 + 1] as f32 * w11; - let s_b = sprite.rgba[i00 + 2] as f32 * w00 - + sprite.rgba[i10 + 2] as f32 * w10 - + sprite.rgba[i01 + 2] as f32 * w01 - + sprite.rgba[i11 + 2] as f32 * w11; - let inv_a = 1.0 - pa; - dst[0] = s_r * (tr * cov) + dst[0] * inv_a; - dst[1] = s_g * (tg * cov) + dst[1] * inv_a; - dst[2] = s_b * (tb * cov) + dst[2] * inv_a; - dst[3] = pa + dst[3] * inv_a; - } - } - } - u += du_dx; - v += dv_dx; - } - } - } -} - #[cfg(test)] mod w26c_tests { use super::*; diff --git a/crates/engine/src/particles/raster.rs b/crates/engine/src/particles/raster.rs index bca9b5c76a0e48f1cafbb349e232c612545d9ef7..8cc1fcfe3724f0fc251e65c4f0bb440f73f7e66b 100644 --- a/crates/engine/src/particles/raster.rs +++ b/crates/engine/src/particles/raster.rs @@ -1,5 +1,3 @@ -//! 2D particle rasterization (points, blobs, NGons, and bilinear bitmap sprites). - use std::collections::HashMap; use model::{Comp, ExprEngine, Gradient, Node, NodeId}; @@ -8,10 +6,50 @@ use super::{ BLOB_SIGMA_PER_SIZE, CAMERA_DISTANCE, Particle, ParticleStyleKind, SpriteImage, }; +const INV_255: f32 = 1.0 / 255.0; + +pub(super) struct DrawCmd { + min_x: usize, + max_x: usize, + min_y: usize, + max_y: usize, + color: [f32; 4], + shape: DrawShape, +} + +enum DrawShape { + Point, + Blob { + cx: f64, + cy: f64, + inv_two_sigma_sq: f64, + }, + NGon { + cx: f64, + cy: f64, + inv_two_sigma_sq: f64, + inv_half_period: f64, + spike_period: f64, + phase: f64, + sharpness: f64, + }, + Bitmap { + emitter_idx: usize, + cx: f64, + cy: f64, + draw_w: f64, + draw_h: f64, + rot_z_deg: f64, + }, +} + struct EmitterRenderProps<'a> { - emitter_id: NodeId, + emitter_hash: u64, style: ParticleStyleKind, + /// Owned 1x1 tiny-background sprite, if applicable. tiny_sprite: Option<([f64; 2], SpriteImage)>, + /// External sprite reference + nominal dimensions when not a tiny background. + ext_sprite: Option<(&'a SpriteImage, [f64; 2])>, ngon_sides: f64, size_over_life: Option<&'a model::BezierSpline>, fade_in: f64, @@ -19,21 +57,25 @@ struct EmitterRenderProps<'a> { color_over_life: Option, } +impl<'a> EmitterRenderProps<'a> { + #[inline] + fn resolved_sprite(&self) -> Option<(&SpriteImage, [f64; 2])> { + match &self.tiny_sprite { + Some((nominal, sprite)) => Some((sprite, *nominal)), + None => self.ext_sprite, + } + } +} + fn collect_emitter_render_props<'a>( comp: &'a Comp, emitter_nodes: &HashMap, - particles: &[Particle], time: f64, expr: &ExprEngine, -) -> HashMap> { - let mut map = HashMap::new(); - for p in particles { - if map.contains_key(&p.emitter_hash) { - continue; - } - let Some(&emitter_id) = emitter_nodes.get(&p.emitter_hash) else { - continue; - }; + sprites: &'a HashMap, +) -> Vec> { + let mut list = Vec::with_capacity(emitter_nodes.len()); + for (&emitter_hash, &emitter_id) in emitter_nodes { let Some(node) = comp.nodes.get(emitter_id.0) else { continue; }; @@ -56,33 +98,48 @@ fn collect_emitter_render_props<'a>( .eval_number(node, "ParticleStyle.FadeOut", time, 1.0, expr) .clamp(0.0, 1.0); let color_over_life_on = - comp.eval_number(node, "ParticleStyle.ColorOverLifeControls", time, 0.0, expr) > 0.5; + comp.eval_number(node, "ParticleStyle.ColorOverLifeControls", time, 0.0, expr) + > 0.5; let color_over_life = if color_over_life_on { comp.eval_gradient(node, "ParticleStyle.ColorOverLife", time) } else { None }; - map.insert( - p.emitter_hash, - EmitterRenderProps { - emitter_id, - style, - tiny_sprite: tiny_background_sprite(comp, node, time, expr), - ngon_sides: comp.eval_number(node, "ParticleStyleNGon.NGonSides", time, 5.0, expr).round().max(3.0), - size_over_life, - fade_in, - fade_out, - color_over_life, - }, - ); + let tiny_sprite = tiny_background_sprite(comp, node, time, expr); + let ext_sprite = if tiny_sprite.is_none() && style == ParticleStyleKind::Bitmap { + sprites + .get(&emitter_id) + .filter(|s| { + s.size[0] > 0 + && s.size[1] > 0 + && s.rgba.len() + >= (s.size[0] as usize) + .saturating_mul(s.size[1] as usize) + .saturating_mul(4) + }) + .map(|s| (s, [s.size[0] as f64, s.size[1] as f64])) + } else { + None + }; + list.push(EmitterRenderProps { + emitter_hash, + style, + tiny_sprite, + ext_sprite, + ngon_sides: comp + .eval_number(node, "ParticleStyleNGon.NGonSides", time, 5.0, expr) + .round() + .max(3.0), + size_over_life, + fade_in, + fade_out, + color_over_life, + }); } - map + list } /// Solid sprite for a `Background` tool narrower than 16 px. -/// -/// The engine evaluates such tools at comp size, so the particle uses the tool's nominal -/// `Width`/`Height` and its flat color directly. fn tiny_background_sprite( comp: &Comp, emitter: &Node, @@ -99,7 +156,8 @@ fn tiny_background_sprite( if !(w >= 1.0 && h >= 1.0 && (w < 16.0 || h < 16.0)) { return None; } - let channel = |name: &str, default: f64| comp.eval_number(src, name, t, default, expr).clamp(0.0, 1.0); + let channel = + |name: &str, default: f64| comp.eval_number(src, name, t, default, expr).clamp(0.0, 1.0); let a = channel("TopLeftAlpha", 1.0); let px = |c: f64| (c * a * 255.0 + 0.5) as u8; let rgba = vec![ @@ -111,9 +169,28 @@ fn tiny_background_sprite( Some(([w, h], SpriteImage { size: [1, 1], rgba })) } +/// Clamps a floating-point `[lo, hi]` interval to `[0, limit - 1]`, returning `None` if empty. +#[inline] +fn clip_bounds(lo: f64, hi: f64, limit: usize) -> Option<(usize, usize)> { + if limit == 0 || !lo.is_finite() || !hi.is_finite() { + return None; + } + let max_i = (limit - 1) as isize; + let a = lo.floor() as isize; + let b = hi.ceil() as isize; + if b < 0 || a > max_i { + return None; + } + let min_u = a.max(0) as usize; + let max_u = b.min(max_i) as usize; + (min_u <= max_u).then_some((min_u, max_u)) +} + #[allow(clippy::too_many_arguments)] pub(super) fn rasterize_particles( out: &mut [u8], + scratch_accum: &mut Vec, + scratch_cmds: &mut Vec, dims: [u32; 2], px_scale: f64, comp: &Comp, @@ -127,25 +204,47 @@ pub(super) fn rasterize_particles( return; } - let props_map = collect_emitter_render_props(comp, emitter_nodes, particles, time, expr); let w = dims[0] as usize; let h = dims[1] as usize; + if w == 0 || h == 0 { + return; + } let w_f = w as f64; let h_f = h as f64; - // Accumulate in linear-ish float premultiplied RGBA for clean blending, then pack to u8. - let mut accum = vec![0.0f32; w * h * 4]; + let props_list = collect_emitter_render_props(comp, emitter_nodes, time, expr, sprites); + if props_list.is_empty() { + return; + } + + scratch_cmds.clear(); + if scratch_cmds.capacity() < particles.len() { + scratch_cmds.reserve(particles.len() - scratch_cmds.capacity()); + } + + let mut dirty_y0 = h; + let mut dirty_y1 = 0usize; + let mut last_hash = u64::MAX; + let mut last_idx = usize::MAX; for p in particles { if !p.alive { continue; } - let Some(props) = props_map.get(&p.emitter_hash) else { - continue; + let props_idx = if p.emitter_hash == last_hash && last_idx < props_list.len() { + last_idx + } else { + let Some(idx) = props_list.iter().position(|pr| pr.emitter_hash == p.emitter_hash) + else { + continue; + }; + last_hash = p.emitter_hash; + last_idx = idx; + idx }; + let props = &props_list[props_idx]; let life_frac = (p.age / p.lifespan.max(1.0)).clamp(0.0, 1.0); - // Fusion's SizeOverLife LUT maps 0.5 -> 1.0x (0.0 -> 0x, 1.0 -> 2x). let size_mult = props .size_over_life .map(|sp| (2.0 * sp.eval(life_frac)).max(0.0)) @@ -183,76 +282,428 @@ pub(super) fn rasterize_particles( continue; } - // Fusion 2D particle coordinates: X in [-0.5, +0.5], Y-up with same unit scale as X. let cx = (p.pos[0] * depth_scale + 0.5) * w_f; let cy = h_f * 0.5 - p.pos[1] * depth_scale * w_f; if props.style == ParticleStyleKind::Bitmap { - let (sprite, nominal) = match &props.tiny_sprite { - Some((nominal, sprite)) => (Some(sprite), *nominal), - None => { - let sprite = sprites.get(&props.emitter_id); - (sprite, sprite.map_or([0.0; 2], |s| [s.size[0] as f64, s.size[1] as f64])) + if let Some((_, nominal)) = props.resolved_sprite() { + let draw_w = size_world * nominal[0] * px_scale; + let draw_h = size_world * nominal[1] * px_scale; + if draw_w < 0.5 || draw_h < 0.5 { + continue; } - }; - if let Some(sprite) = sprite.filter(|s| { - s.size[0] > 0 - && s.size[1] > 0 - && s.rgba.len() >= (s.size[0] as usize).saturating_mul(s.size[1] as usize).saturating_mul(4) - }) { - draw_bitmap_particle( - &mut accum, - w, - h, - cx, - cy, - size_world * nominal[0] * px_scale, - size_world * nominal[1] * px_scale, - p.rot_z, - [cr, cg, cb, ca], - sprite, - ); + let hw = draw_w * 0.5; + let hh = draw_h * 0.5; + let (rx, ry) = if p.rot_z.abs() <= 1e-6 { + (hw + 1.0, hh + 1.0) + } else { + let theta = p.rot_z.to_radians(); + let ca_t = theta.cos().abs(); + let sa_t = theta.sin().abs(); + (hw * ca_t + hh * sa_t + 1.0, hw * sa_t + hh * ca_t + 1.0) + }; + let Some((min_x, max_x)) = clip_bounds(cx - rx, cx + rx, w) else { + continue; + }; + let Some((min_y, max_y)) = clip_bounds(cy - ry, cy + ry, h) else { + continue; + }; + dirty_y0 = dirty_y0.min(min_y); + dirty_y1 = dirty_y1.max(max_y + 1); + scratch_cmds.push(DrawCmd { + min_x, + max_x, + min_y, + max_y, + color: [cr, cg, cb, ca], + shape: DrawShape::Bitmap { + emitter_idx: props_idx, + cx, + cy, + draw_w, + draw_h, + rot_z_deg: p.rot_z, + }, + }); continue; } } match props.style { ParticleStyleKind::Point => { - blend_pixel(&mut accum, w, h, cx.floor(), cy.floor(), [cr, cg, cb, ca]); + let ix = cx.floor() as isize; + let iy = cy.floor() as isize; + if ix < 0 || iy < 0 || ix >= w as isize || iy >= h as isize { + continue; + } + let ux = ix as usize; + let uy = iy as usize; + dirty_y0 = dirty_y0.min(uy); + dirty_y1 = dirty_y1.max(uy + 1); + scratch_cmds.push(DrawCmd { + min_x: ux, + max_x: ux, + min_y: uy, + max_y: uy, + color: [cr, cg, cb, ca], + shape: DrawShape::Point, + }); } ParticleStyleKind::Blob | ParticleStyleKind::Bitmap => { let sigma = BLOB_SIGMA_PER_SIZE * size_world * px_scale; - draw_soft_particle(&mut accum, w, h, cx, cy, sigma, [cr, cg, cb, ca], |_, _| 1.0); + if sigma <= 1e-6 { + continue; + } + let inv_two_sigma_sq = 0.5 / (sigma * sigma); + let bound = (4.0 * sigma).min((((ca as f64) * 1.0e5).ln().max(0.0) / inv_two_sigma_sq).sqrt()); + let Some((min_x, max_x)) = clip_bounds(cx - bound, cx + bound, w) else { + continue; + }; + let Some((min_y, max_y)) = clip_bounds(cy - bound, cy + bound, h) else { + continue; + }; + dirty_y0 = dirty_y0.min(min_y); + dirty_y1 = dirty_y1.max(max_y + 1); + scratch_cmds.push(DrawCmd { + min_x, + max_x, + min_y, + max_y, + color: [cr, cg, cb, ca], + shape: DrawShape::Blob { + cx, + cy, + inv_two_sigma_sq, + }, + }); } ParticleStyleKind::NGon => { let sigma = BLOB_SIGMA_PER_SIZE * size_world * px_scale; + if sigma <= 1e-6 { + continue; + } + let inv_two_sigma_sq = 0.5 / (sigma * sigma); + let bound = (4.0 * sigma).min((((ca as f64) * 1.0e5).ln().max(0.0) / inv_two_sigma_sq).sqrt()); + let Some((min_x, max_x)) = clip_bounds(cx - bound, cx + bound, w) else { + continue; + }; + let Some((min_y, max_y)) = clip_bounds(cy - bound, cy + bound, h) else { + continue; + }; let sides = props.ngon_sides; let spike_period = std::f64::consts::TAU / sides; let phase = std::f64::consts::FRAC_PI_2 + p.rot_z.to_radians(); - // Spike sharpness fitted to Fusion 21.1: alpha mass is 0.18/0.48/0.78 of a blob for 3/5/8 sides. let sharpness = 4.5 * (3.0 / sides).powf(2.8); - draw_soft_particle(&mut accum, w, h, cx, cy, sigma, [cr, cg, cb, ca], |dx, dy| { - // Distance to the nearest spike, as a fraction of half the spike period. - let angle = (-dy).atan2(dx) - phase; - let off = angle.rem_euclid(spike_period); - let to_spike = off.min(spike_period - off); - (1.0 - to_spike / (0.5 * spike_period)).powf(sharpness) + dirty_y0 = dirty_y0.min(min_y); + dirty_y1 = dirty_y1.max(max_y + 1); + scratch_cmds.push(DrawCmd { + min_x, + max_x, + min_y, + max_y, + color: [cr, cg, cb, ca], + shape: DrawShape::NGon { + cx, + cy, + inv_two_sigma_sq, + inv_half_period: 2.0 / spike_period, + spike_period, + phase, + sharpness, + }, }); } ParticleStyleKind::Brush => {} } } - for (dst, &src) in out.iter_mut().zip(accum.iter()) { - *dst = (src.clamp(0.0, 1.0) * 255.0 + 0.5) as u8; + if scratch_cmds.is_empty() || dirty_y0 >= dirty_y1 { + return; } + + let needed_floats = w * h * 4; + if scratch_accum.len() < needed_floats { + scratch_accum.resize(needed_floats, 0.0); + } + + rasterize_bands( + out, + &mut scratch_accum[..needed_floats], + w, + dirty_y0, + dirty_y1, + scratch_cmds, + &props_list, + ); } -#[allow(clippy::too_many_arguments)] -fn draw_bitmap_particle( +fn rasterize_bands( + out: &mut [u8], accum: &mut [f32], w: usize, - h: usize, + dirty_y0: usize, + dirty_y1: usize, + cmds: &[DrawCmd], + props_list: &[EmitterRenderProps<'_>], +) { + #[cfg(not(target_arch = "wasm32"))] + { + let dirty_rows = dirty_y1 - dirty_y0; + let dirty_pixels = dirty_rows * w; + if dirty_pixels >= 120_000 && dirty_rows >= 32 && cmds.len() >= 16 { + let workers = std::thread::available_parallelism() + .map(|n| n.get()) + .unwrap_or(1) + .min(8) + .min(dirty_rows / 16); + if workers > 1 { + let stride = w * 4; + let rows_per_band = dirty_rows.div_ceil(workers); + let accum_dirty = &mut accum[dirty_y0 * stride..dirty_y1 * stride]; + let out_dirty = &mut out[dirty_y0 * stride..dirty_y1 * stride]; + std::thread::scope(|scope| { + let mut a_rest = accum_dirty; + let mut o_rest = out_dirty; + let mut band_y0 = dirty_y0; + while band_y0 < dirty_y1 { + let take_rows = rows_per_band.min(dirty_y1 - band_y0); + let take_elems = take_rows * stride; + let (a_band, a_next) = a_rest.split_at_mut(take_elems); + let (o_band, o_next) = o_rest.split_at_mut(take_elems); + a_rest = a_next; + o_rest = o_next; + let band_y1 = band_y0 + take_rows; + scope.spawn(move || { + rasterize_single_band( + o_band, + a_band, + w, + band_y0, + band_y1, + cmds, + props_list, + ); + }); + band_y0 = band_y1; + } + }); + return; + } + } + } + + let stride = w * 4; + let start = dirty_y0 * stride; + let end = dirty_y1 * stride; + rasterize_single_band( + &mut out[start..end], + &mut accum[start..end], + w, + dirty_y0, + dirty_y1, + cmds, + props_list, + ); +} + +fn rasterize_single_band( + out_band: &mut [u8], + accum_band: &mut [f32], + w: usize, + band_y0: usize, + band_y1: usize, + cmds: &[DrawCmd], + props_list: &[EmitterRenderProps<'_>], +) { + let stride = w * 4; + let mut wx_heap: Vec = Vec::new(); + let mut wx_stack = [0.0f32; 64]; + + for cmd in cmds { + if cmd.max_y < band_y0 || cmd.min_y >= band_y1 { + continue; + } + let y_lo = cmd.min_y.max(band_y0); + let y_hi = cmd.max_y.min(band_y1 - 1); + let x_lo = cmd.min_x; + let x_hi = cmd.max_x; + + match cmd.shape { + DrawShape::Point => { + let pa = cmd.color[3]; + let off = (y_lo - band_y0) * stride + x_lo * 4; + let dst = &mut accum_band[off..off + 4]; + if pa >= 1.0 - 1e-5 { + dst[0] = cmd.color[0]; + dst[1] = cmd.color[1]; + dst[2] = cmd.color[2]; + dst[3] = 1.0; + } else { + let inv_a = 1.0 - pa; + dst[0] = cmd.color[0] * pa + dst[0] * inv_a; + dst[1] = cmd.color[1] * pa + dst[1] * inv_a; + dst[2] = cmd.color[2] * pa + dst[2] * inv_a; + dst[3] = pa + dst[3] * inv_a; + } + } + DrawShape::Blob { + cx, + cy, + inv_two_sigma_sq, + } => { + let span_x = x_hi - x_lo + 1; + let wx: &mut [f32] = if span_x <= wx_stack.len() { + &mut wx_stack[..span_x] + } else { + wx_heap.resize(span_x, 0.0); + &mut wx_heap[..span_x] + }; + for (i, w_slot) in wx.iter_mut().enumerate() { + let dx = (x_lo + i) as f64 + 0.5 - cx; + *w_slot = (-(dx * dx) * inv_two_sigma_sq).exp() as f32; + } + + let sa = cmd.color[3]; + let sr = cmd.color[0] * sa; + let sg = cmd.color[1] * sa; + let sb = cmd.color[2] * sa; + let row_x_start = x_lo * 4; + let row_x_end = (x_hi + 1) * 4; + + for py in y_lo..=y_hi { + let dy = py as f64 + 0.5 - cy; + let wy = (-(dy * dy) * inv_two_sigma_sq).exp() as f32; + let row_a = sa * wy; + if row_a <= 1e-5 { + continue; + } + let row_r = sr * wy; + let row_g = sg * wy; + let row_b = sb * wy; + let row_off = (py - band_y0) * stride; + let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end]; + for (dst, &gx) in row_pixels.chunks_exact_mut(4).zip(wx.iter()) { + let pa = row_a * gx; + if pa <= 1e-5 { + continue; + } + let inv_a = 1.0 - pa; + dst[0] = row_r * gx + dst[0] * inv_a; + dst[1] = row_g * gx + dst[1] * inv_a; + dst[2] = row_b * gx + dst[2] * inv_a; + dst[3] = pa + dst[3] * inv_a; + } + } + } + DrawShape::NGon { + cx, + cy, + inv_two_sigma_sq, + inv_half_period, + spike_period, + phase, + sharpness, + } => { + let span_x = x_hi - x_lo + 1; + let wx: &mut [f32] = if span_x <= wx_stack.len() { + &mut wx_stack[..span_x] + } else { + wx_heap.resize(span_x, 0.0); + &mut wx_heap[..span_x] + }; + for (i, w_slot) in wx.iter_mut().enumerate() { + let dx = (x_lo + i) as f64 + 0.5 - cx; + *w_slot = (-(dx * dx) * inv_two_sigma_sq).exp() as f32; + } + + let sa = cmd.color[3]; + let cr = cmd.color[0]; + let cg = cmd.color[1]; + let cb = cmd.color[2]; + let row_x_start = x_lo * 4; + let row_x_end = (x_hi + 1) * 4; + + for py in y_lo..=y_hi { + let dy = py as f64 + 0.5 - cy; + let wy = (-(dy * dy) * inv_two_sigma_sq).exp() as f32; + let row_a = sa * wy; + if row_a <= 1e-5 { + continue; + } + let row_off = (py - band_y0) * stride; + let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end]; + for (i, dst) in row_pixels.chunks_exact_mut(4).enumerate() { + let env_a = row_a * wx[i]; + if env_a <= 1e-5 { + continue; + } + let dx = (x_lo + i) as f64 + 0.5 - cx; + let angle = (-dy).atan2(dx) - phase; + let off = angle.rem_euclid(spike_period); + let to_spike = off.min(spike_period - off); + let shape_w = (1.0 - to_spike * inv_half_period).powf(sharpness) as f32; + let pa = env_a * shape_w; + if pa <= 1e-5 { + continue; + } + let inv_a = 1.0 - pa; + dst[0] = cr * pa + dst[0] * inv_a; + dst[1] = cg * pa + dst[1] * inv_a; + dst[2] = cb * pa + dst[2] * inv_a; + dst[3] = pa + dst[3] * inv_a; + } + } + } + DrawShape::Bitmap { + emitter_idx, + cx, + cy, + draw_w, + draw_h, + rot_z_deg, + } => { + let Some((sprite, _)) = props_list[emitter_idx].resolved_sprite() else { + continue; + }; + draw_bitmap_band( + accum_band, + stride, + band_y0, + y_lo, + y_hi, + x_lo, + x_hi, + cx, + cy, + draw_w, + draw_h, + rot_z_deg, + cmd.color, + sprite, + ); + } + } + } + + // Pack premultiplied f32 -> u8 and simultaneously reset `accum_band` to 0.0 + // while the cache lines are hot so `scratch_accum` stays zeroed for the next frame. + for (dst, src) in out_band.iter_mut().zip(accum_band.iter_mut()) { + let v = *src; + *src = 0.0; + *dst = (v.clamp(0.0, 1.0) * 255.0 + 0.5) as u8; + } +} + +#[allow(clippy::too_many_arguments)] +#[inline] +fn draw_bitmap_band( + accum_band: &mut [f32], + stride: usize, + band_y0: usize, + y_lo: usize, + y_hi: usize, + x_lo: usize, + x_hi: usize, cx: f64, cy: f64, draw_w: f64, @@ -261,170 +712,233 @@ fn draw_bitmap_particle( tint: [f32; 4], sprite: &SpriteImage, ) { - if draw_w < 0.5 || draw_h < 0.5 { - return; - } - - let hw = draw_w * 0.5; - let hh = draw_h * 0.5; - let theta = rot_z_deg.to_radians(); - let cos_t = theta.cos(); - let sin_t = theta.sin(); - - let rx = hw * cos_t.abs() + hh * sin_t.abs() + 1.0; - let ry = hw * sin_t.abs() + hh * cos_t.abs() + 1.0; - - let min_x = ((cx - rx).floor() as isize).max(0) as usize; - let max_x = ((cx + rx).ceil() as isize).min(w as isize - 1); - let min_y = ((cy - ry).floor() as isize).max(0) as usize; - let max_y = ((cy + ry).ceil() as isize).min(h as isize - 1); - if max_x < min_x as isize || max_y < min_y as isize { - return; - } - let inv_dw = 1.0 / draw_w; let inv_dh = 1.0 / draw_h; let edge_u = inv_dw * 0.5; let edge_v = inv_dh * 0.5; + let inv_2edge_u = 1.0 / (2.0 * edge_u); + let inv_2edge_v = 1.0 / (2.0 * edge_v); let sw_i = sprite.size[0] as usize; let sh_i = sprite.size[1] as usize; + let row_x_start = x_lo * 4; + let row_x_end = (x_hi + 1) * 4; - for py in min_y..=(max_y as usize) { - let dy = (py as f64 + 0.5) - cy; - let row_off = py * w * 4; - for px in min_x..=(max_x as usize) { - let dx = (px as f64 + 0.5) - cx; - // Inverse rotate into sprite local space (CCW in Y-up). - let lx = dx * cos_t - dy * sin_t; - let ly = dx * sin_t + dy * cos_t; + // Fast path: axis-aligned (unrotated) sprite. + if rot_z_deg.abs() <= 1e-6 { + let u0 = (x_lo as f64 + 0.5 - cx) * inv_dw + 0.5; + if sw_i == 1 && sh_i == 1 { + let s0 = sprite.rgba[0] as f32 * INV_255 * tint[0] * tint[3]; + let s1 = sprite.rgba[1] as f32 * INV_255 * tint[1] * tint[3]; + let s2 = sprite.rgba[2] as f32 * INV_255 * tint[2] * tint[3]; + let s3 = sprite.rgba[3] as f32 * INV_255 * tint[3]; + if s3 <= 1e-5 { + return; + } + for py in y_lo..=y_hi { + let v = (py as f64 + 0.5 - cy) * inv_dh + 0.5; + if v <= -edge_v || v >= 1.0 + edge_v { + continue; + } + let cov_v = ((v + edge_v) * inv_2edge_v) + .min((1.0 + edge_v - v) * inv_2edge_v) + .clamp(0.0, 1.0); + if cov_v <= 1e-4 { + continue; + } + let cov_vf = cov_v as f32; + let row_off = (py - band_y0) * stride; + let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end]; + let mut u = u0; + for dst in row_pixels.chunks_exact_mut(4) { + if u > -edge_u && u < 1.0 + edge_u { + let cov_u = ((u + edge_u) * inv_2edge_u) + .min((1.0 + edge_u - u) * inv_2edge_u) + .clamp(0.0, 1.0); + let cov = cov_u as f32 * cov_vf; + if cov > 1e-4 { + let pa = s3 * cov; + if pa > 1e-5 { + let inv_a = 1.0 - pa; + dst[0] = s0 * cov + dst[0] * inv_a; + dst[1] = s1 * cov + dst[1] * inv_a; + dst[2] = s2 * cov + dst[2] * inv_a; + dst[3] = pa + dst[3] * inv_a; + } + } + } + u += inv_dw; + } + } + return; + } + + let sw_f = sw_i as f64; + let sh_f = sh_i as f64; + let sw_max = (sw_i - 1) as f64; + let sh_max = (sh_i - 1) as f64; + let tr = tint[0] * INV_255; + let tg = tint[1] * INV_255; + let tb = tint[2] * INV_255; + let ta = tint[3] * INV_255; - let u = lx * inv_dw + 0.5; - let v = ly * inv_dh + 0.5; - if u <= -edge_u || u >= 1.0 + edge_u || v <= -edge_v || v >= 1.0 + edge_v { + for py in y_lo..=y_hi { + let v = (py as f64 + 0.5 - cy) * inv_dh + 0.5; + if v <= -edge_v || v >= 1.0 + edge_v { continue; } - - // Anti-aliased border coverage (0.5px feather at edges). - let cov_u = ((u + edge_u) / (2.0 * edge_u)) - .min((1.0 + edge_u - u) / (2.0 * edge_u)) + let cov_v = ((v + edge_v) * inv_2edge_v) + .min((1.0 + edge_v - v) * inv_2edge_v) .clamp(0.0, 1.0); - let cov_v = ((v + edge_v) / (2.0 * edge_v)) - .min((1.0 + edge_v - v) / (2.0 * edge_v)) - .clamp(0.0, 1.0); - let cov = (cov_u * cov_v) as f32; - if cov <= 1e-4 { + if cov_v <= 1e-4 { continue; } + let fy = (v.clamp(0.0, 1.0) * sh_f - 0.5).clamp(0.0, sh_max); + let y0 = fy.floor() as usize; + let y1 = (y0 + 1).min(sh_i - 1); + let ty = (fy - y0 as f64) as f32; + let one_minus_ty = 1.0 - ty; + let row0 = y0 * sw_i; + let row1 = y1 * sw_i; + let cov_vf = cov_v as f32; - let sample = sample_sprite_bilinear( - &sprite.rgba, - sw_i, - sh_i, - u.clamp(0.0, 1.0), - v.clamp(0.0, 1.0), - ); - let alpha_scale = tint[3] * cov; - let pa = sample[3] * alpha_scale; - if pa <= 1e-5 { - continue; - } - let pr = sample[0] * tint[0] * alpha_scale; - let pg = sample[1] * tint[1] * alpha_scale; - let pb = sample[2] * tint[2] * alpha_scale; + let row_off = (py - band_y0) * stride; + let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end]; + let mut u = u0; + for dst in row_pixels.chunks_exact_mut(4) { + if u > -edge_u && u < 1.0 + edge_u { + let cov_u = ((u + edge_u) * inv_2edge_u) + .min((1.0 + edge_u - u) * inv_2edge_u) + .clamp(0.0, 1.0); + let cov = cov_u as f32 * cov_vf; + if cov > 1e-4 { + let fx = (u.clamp(0.0, 1.0) * sw_f - 0.5).clamp(0.0, sw_max); + let x0 = fx.floor() as usize; + let x1 = (x0 + 1).min(sw_i - 1); + let tx = (fx - x0 as f64) as f32; + let omt = 1.0 - tx; - let idx = row_off + px * 4; - let inv_a = 1.0 - pa; - accum[idx] = pr + accum[idx] * inv_a; - accum[idx + 1] = pg + accum[idx + 1] * inv_a; - accum[idx + 2] = pb + accum[idx + 2] * inv_a; - accum[idx + 3] = pa + accum[idx + 3] * inv_a; + let w00 = omt * one_minus_ty; + let w10 = tx * one_minus_ty; + let w01 = omt * ty; + let w11 = tx * ty; + + let i00 = (row0 + x0) * 4; + let i10 = (row0 + x1) * 4; + let i01 = (row1 + x0) * 4; + let i11 = (row1 + x1) * 4; + + let s_a = sprite.rgba[i00 + 3] as f32 * w00 + + sprite.rgba[i10 + 3] as f32 * w10 + + sprite.rgba[i01 + 3] as f32 * w01 + + sprite.rgba[i11 + 3] as f32 * w11; + let pa = s_a * ta * cov; + if pa > 1e-5 { + let s_r = sprite.rgba[i00] as f32 * w00 + + sprite.rgba[i10] as f32 * w10 + + sprite.rgba[i01] as f32 * w01 + + sprite.rgba[i11] as f32 * w11; + let s_g = sprite.rgba[i00 + 1] as f32 * w00 + + sprite.rgba[i10 + 1] as f32 * w10 + + sprite.rgba[i01 + 1] as f32 * w01 + + sprite.rgba[i11 + 1] as f32 * w11; + let s_b = sprite.rgba[i00 + 2] as f32 * w00 + + sprite.rgba[i10 + 2] as f32 * w10 + + sprite.rgba[i01 + 2] as f32 * w01 + + sprite.rgba[i11 + 2] as f32 * w11; + let inv_a = 1.0 - pa; + dst[0] = s_r * (tr * cov * tint[3]) + dst[0] * inv_a; + dst[1] = s_g * (tg * cov * tint[3]) + dst[1] * inv_a; + dst[2] = s_b * (tb * cov * tint[3]) + dst[2] * inv_a; + dst[3] = pa + dst[3] * inv_a; + } + } + } + u += inv_dw; + } } + return; } -} -#[inline] -fn sample_sprite_bilinear(rgba: &[u8], w: usize, h: usize, u: f64, v: f64) -> [f32; 4] { - let fx = (u * w as f64 - 0.5).clamp(0.0, (w - 1) as f64); - let fy = (v * h as f64 - 0.5).clamp(0.0, (h - 1) as f64); - let x0 = fx.floor() as usize; - let y0 = fy.floor() as usize; - let x1 = (x0 + 1).min(w - 1); - let y1 = (y0 + 1).min(h - 1); - let tx = (fx - x0 as f64) as f32; - let ty = (fy - y0 as f64) as f32; + // General rotated bitmap path with incremental scanline UV stepping. + let theta = rot_z_deg.to_radians(); + let cos_t = theta.cos(); + let sin_t = theta.sin(); + let du_dx = cos_t * inv_dw; + let dv_dx = sin_t * inv_dh; + let dx0 = (x_lo as f64 + 0.5) - cx; + let sw_f = sw_i as f64; + let sh_f = sh_i as f64; + let sw_max = (sw_i - 1) as f64; + let sh_max = (sh_i - 1) as f64; + let tr = tint[0] * tint[3] * INV_255; + let tg = tint[1] * tint[3] * INV_255; + let tb = tint[2] * tint[3] * INV_255; + let ta = tint[3] * INV_255; - let i00 = (y0 * w + x0) * 4; - let i10 = (y0 * w + x1) * 4; - let i01 = (y1 * w + x0) * 4; - let i11 = (y1 * w + x1) * 4; + for py in y_lo..=y_hi { + let dy = (py as f64 + 0.5) - cy; + let mut u = (dx0 * cos_t - dy * sin_t) * inv_dw + 0.5; + let mut v = (dx0 * sin_t + dy * cos_t) * inv_dh + 0.5; + let row_off = (py - band_y0) * stride; + let row_pixels = &mut accum_band[row_off + row_x_start..row_off + row_x_end]; - let w00 = (1.0 - tx) * (1.0 - ty) * (1.0 / 255.0); - let w10 = tx * (1.0 - ty) * (1.0 / 255.0); - let w01 = (1.0 - tx) * ty * (1.0 / 255.0); - let w11 = tx * ty * (1.0 / 255.0); + for dst in row_pixels.chunks_exact_mut(4) { + if u > -edge_u && u < 1.0 + edge_u && v > -edge_v && v < 1.0 + edge_v { + let cov_u = ((u + edge_u) * inv_2edge_u) + .min((1.0 + edge_u - u) * inv_2edge_u) + .clamp(0.0, 1.0); + let cov_v = ((v + edge_v) * inv_2edge_v) + .min((1.0 + edge_v - v) * inv_2edge_v) + .clamp(0.0, 1.0); + let cov = (cov_u * cov_v) as f32; + if cov > 1e-4 { + let fx = (u.clamp(0.0, 1.0) * sw_f - 0.5).clamp(0.0, sw_max); + let fy = (v.clamp(0.0, 1.0) * sh_f - 0.5).clamp(0.0, sh_max); + let x0 = fx.floor() as usize; + let y0 = fy.floor() as usize; + let x1 = (x0 + 1).min(sw_i - 1); + let y1 = (y0 + 1).min(sh_i - 1); + let tx = (fx - x0 as f64) as f32; + let ty = (fy - y0 as f64) as f32; - [ - rgba[i00] as f32 * w00 - + rgba[i10] as f32 * w10 - + rgba[i01] as f32 * w01 - + rgba[i11] as f32 * w11, - rgba[i00 + 1] as f32 * w00 - + rgba[i10 + 1] as f32 * w10 - + rgba[i01 + 1] as f32 * w01 - + rgba[i11 + 1] as f32 * w11, - rgba[i00 + 2] as f32 * w00 - + rgba[i10 + 2] as f32 * w10 - + rgba[i01 + 2] as f32 * w01 - + rgba[i11 + 2] as f32 * w11, - rgba[i00 + 3] as f32 * w00 - + rgba[i10 + 3] as f32 * w10 - + rgba[i01 + 3] as f32 * w01 - + rgba[i11 + 3] as f32 * w11, - ] -} + let w00 = (1.0 - tx) * (1.0 - ty); + let w10 = tx * (1.0 - ty); + let w01 = (1.0 - tx) * ty; + let w11 = tx * ty; -/// Source-over blends one premultiplied-accumulator pixel; out-of-bounds coordinates are ignored. -#[inline] -fn blend_pixel(accum: &mut [f32], w: usize, h: usize, x: f64, y: f64, color: [f32; 4]) { - if x < 0.0 || y < 0.0 || x >= w as f64 || y >= h as f64 { - return; - } - let pa = color[3].clamp(0.0, 1.0); - if pa <= 1e-5 { - return; - } - let idx = (y as usize * w + x as usize) * 4; - let inv_a = 1.0 - pa; - accum[idx] = color[0] * pa + accum[idx] * inv_a; - accum[idx + 1] = color[1] * pa + accum[idx + 1] * inv_a; - accum[idx + 2] = color[2] * pa + accum[idx + 2] * inv_a; - accum[idx + 3] = pa + accum[idx + 3] * inv_a; -} + let i00 = (y0 * sw_i + x0) * 4; + let i10 = (y0 * sw_i + x1) * 4; + let i01 = (y1 * sw_i + x0) * 4; + let i11 = (y1 * sw_i + x1) * 4; -/// Gaussian falloff sampled at pixel centers out to `4 sigma`, scaled by `shape(dx, dy)`. -#[allow(clippy::too_many_arguments)] -fn draw_soft_particle( - accum: &mut [f32], - w: usize, - h: usize, - cx: f64, - cy: f64, - sigma: f64, - color: [f32; 4], - shape: impl Fn(f64, f64) -> f64, -) { - let bound = 4.0 * sigma; - let min_x = ((cx - bound).floor() as isize).max(0); - let max_x = ((cx + bound).ceil() as isize).min(w as isize - 1); - let min_y = ((cy - bound).floor() as isize).max(0); - let max_y = ((cy + bound).ceil() as isize).min(h as isize - 1); - let inv_two_sigma_sq = 0.5 / (sigma * sigma); - for py in min_y..=max_y { - let dy = (py as f64 + 0.5) - cy; - for px in min_x..=max_x { - let dx = (px as f64 + 0.5) - cx; - let cov = ((-(dx * dx + dy * dy) * inv_two_sigma_sq).exp() * shape(dx, dy)) as f32; - blend_pixel(accum, w, h, px as f64, py as f64, [color[0], color[1], color[2], color[3] * cov]); + let s_a = sprite.rgba[i00 + 3] as f32 * w00 + + sprite.rgba[i10 + 3] as f32 * w10 + + sprite.rgba[i01 + 3] as f32 * w01 + + sprite.rgba[i11 + 3] as f32 * w11; + let pa = s_a * ta * cov; + if pa > 1e-5 { + let s_r = sprite.rgba[i00] as f32 * w00 + + sprite.rgba[i10] as f32 * w10 + + sprite.rgba[i01] as f32 * w01 + + sprite.rgba[i11] as f32 * w11; + let s_g = sprite.rgba[i00 + 1] as f32 * w00 + + sprite.rgba[i10 + 1] as f32 * w10 + + sprite.rgba[i01 + 1] as f32 * w01 + + sprite.rgba[i11 + 1] as f32 * w11; + let s_b = sprite.rgba[i00 + 2] as f32 * w00 + + sprite.rgba[i10 + 2] as f32 * w10 + + sprite.rgba[i01 + 2] as f32 * w01 + + sprite.rgba[i11 + 2] as f32 * w11; + let inv_a = 1.0 - pa; + dst[0] = s_r * (tr * cov) + dst[0] * inv_a; + dst[1] = s_g * (tg * cov) + dst[1] * inv_a; + dst[2] = s_b * (tb * cov) + dst[2] * inv_a; + dst[3] = pa + dst[3] * inv_a; + } + } + } + u += du_dx; + v += dv_dx; } } } diff --git a/crates/engine/src/particles/sim.rs b/crates/engine/src/particles/sim.rs index 2d8e2202e8c1015eb9183cae5efd86ffad87bc00..815d5af3048ae74f9fbc8680293f9376fa8aa587 100644 --- a/crates/engine/src/particles/sim.rs +++ b/crates/engine/src/particles/sim.rs @@ -1,5 +1,3 @@ -//! Per-frame particle emission, regions, forces, collisions, and simulation stepping. - use std::collections::HashSet; use model::{Comp, ExprEngine, Node}; @@ -141,24 +139,44 @@ fn emit_particles( let base_b = comp.eval_number(node, "ParticleStyle.Blue", t, 1.0, expr); let base_a = comp.eval_number(node, "ParticleStyle.Alpha", t, 1.0, expr); - let color_var = comp.eval_number(node, "ParticleStyle.ColorVariance", t, 0.0, expr) > 0.5; - let r_lo = (base_r + comp.eval_number(node, "ParticleStyle.RedLow", t, 0.0, expr)).clamp(0.0, 1.0); - let r_hi = (base_r + comp.eval_number(node, "ParticleStyle.RedHigh", t, 0.0, expr)).clamp(0.0, 1.0); - let g_lo = (base_g + comp.eval_number(node, "ParticleStyle.GreenLow", t, 0.0, expr)).clamp(0.0, 1.0); - let g_hi = (base_g + comp.eval_number(node, "ParticleStyle.GreenHigh", t, 0.0, expr)).clamp(0.0, 1.0); - let b_lo = (base_b + comp.eval_number(node, "ParticleStyle.BlueLow", t, 0.0, expr)).clamp(0.0, 1.0); - let b_hi = (base_b + comp.eval_number(node, "ParticleStyle.BlueHigh", t, 0.0, expr)).clamp(0.0, 1.0); - let a_lo = (base_a + comp.eval_number(node, "ParticleStyle.AlphaLow", t, 0.0, expr)).clamp(0.0, 1.0); - let a_hi = (base_a + comp.eval_number(node, "ParticleStyle.AlphaHigh", t, 0.0, expr)).clamp(0.0, 1.0); + let red_lo_off = comp.eval_number(node, "ParticleStyle.RedLow", t, 0.0, expr); + let red_hi_off = comp.eval_number(node, "ParticleStyle.RedHigh", t, 0.0, expr); + let green_lo_off = comp.eval_number(node, "ParticleStyle.GreenLow", t, 0.0, expr); + let green_hi_off = comp.eval_number(node, "ParticleStyle.GreenHigh", t, 0.0, expr); + let blue_lo_off = comp.eval_number(node, "ParticleStyle.BlueLow", t, 0.0, expr); + let blue_hi_off = comp.eval_number(node, "ParticleStyle.BlueHigh", t, 0.0, expr); + let alpha_lo_off = comp.eval_number(node, "ParticleStyle.AlphaLow", t, 0.0, expr); + let alpha_hi_off = comp.eval_number(node, "ParticleStyle.AlphaHigh", t, 0.0, expr); + let color_var = comp.eval_number(node, "ParticleStyle.ColorVariance", t, 0.0, expr) > 0.5 + || red_lo_off.abs() > 1e-9 + || red_hi_off.abs() > 1e-9 + || green_lo_off.abs() > 1e-9 + || green_hi_off.abs() > 1e-9 + || blue_lo_off.abs() > 1e-9 + || blue_hi_off.abs() > 1e-9 + || alpha_lo_off.abs() > 1e-9 + || alpha_hi_off.abs() > 1e-9; + + let r_lo = (base_r + red_lo_off).clamp(0.0, 1.0); + let r_hi = (base_r + red_hi_off).clamp(0.0, 1.0); + let g_lo = (base_g + green_lo_off).clamp(0.0, 1.0); + let g_hi = (base_g + green_hi_off).clamp(0.0, 1.0); + let b_lo = (base_b + blue_lo_off).clamp(0.0, 1.0); + let b_hi = (base_b + blue_hi_off).clamp(0.0, 1.0); + let a_lo = (base_a + alpha_lo_off).clamp(0.0, 1.0); + let a_hi = (base_a + alpha_hi_off).clamp(0.0, 1.0); + + // Fusion's ParticleStyle.Size defaults to 0.1 across all styles. let size_base = comp - .eval_number(node, "ParticleStyle.Size", t, 1.0, expr) + .eval_number(node, "ParticleStyle.Size", t, 0.1, expr) .max(0.0); let size_var = comp .eval_number(node, "ParticleStyle.SizeVariance", t, 0.0, expr) .max(0.0); let region = RegionSpec::from_node(comp, node, t, expr); + state.particles.reserve(emit_count); for _ in 0..emit_count { let mut pos = region.sample(&mut rng); @@ -516,11 +534,18 @@ impl RegionSpec { if r_pos > radius && r_next > radius { return None; } - let ref_v = if r_pos > 1e-9 { dp } else if r_next > 1e-9 { dn } else { [0.0, 1.0, 0.0] }; - 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); + let ref_v = if r_pos > 1e-9 { + dp + } else if r_next > 1e-9 { + dn + } else { + [0.0, 1.0, 0.0] + }; + 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); let mut n = [ref_v[0] / r_len, ref_v[1] / r_len, ref_v[2] / r_len]; if r_pos < radius && r_next >= radius { - // Particle hitting sphere wall from inside n = [-n[0], -n[1], -n[2]]; let pushed = [ center[0] - n[0] * (radius - 1e-5).max(0.0), @@ -536,7 +561,11 @@ impl RegionSpec { ]; Some((pushed, n)) } - Self::Rect { center, width, height } => { + Self::Rect { + center, + width, + height, + } => { let hx = width * 0.5; let hy = height * 0.5; if hy < 1e-6 { @@ -555,15 +584,24 @@ impl RegionSpec { } bounce_aabb(pos, vel, center, [hx, hy, 1e6], false) } - Self::Cube { center, width, height, depth } => { - bounce_aabb(pos, vel, center, [width * 0.5, height * 0.5, depth * 0.5], true) - } + Self::Cube { + center, + width, + height, + depth, + } => bounce_aabb(pos, vel, center, [width * 0.5, height * 0.5, depth * 0.5], true), Self::Point { center } => { let cy = center[1]; let d0 = pos[1] - cy; let d1 = next[1] - cy; if d0 * d1 <= 0.0 || d1.abs() <= 1e-5 { - let ny = if vel[1] < 0.0 { 1.0 } else if vel[1] > 0.0 { -1.0 } else { return None }; + let ny = if vel[1] < 0.0 { + 1.0 + } else if vel[1] > 0.0 { + -1.0 + } else { + return None; + }; let alpha = if (d0 - d1).abs() > 1e-12 { (d0 / (d0 - d1)).clamp(0.0, 1.0) } else { @@ -601,7 +639,6 @@ fn bounce_aabb( } if inside_pos { - // Already inside: push out through the closest face let mut best_axis = 0usize; let mut best_pen = f64::INFINITY; let mut best_sign = 1.0f64; @@ -674,7 +711,7 @@ fn apply_modifier( ) { match node.kind.as_str() { "pPointForce" => { - let strength = comp.eval_number(node, "Strength", t, 0.0, expr); + let strength = comp.eval_number(node, "Strength", t, 0.1, expr); if strength.abs() < 1e-12 { return; } @@ -728,14 +765,14 @@ fn apply_modifier( } } "pDrag" | "pFriction" => { - let damp = if node.kind == "pFriction" { - 1.0 - comp.eval_number(node, "VelocityFriction", t, 0.05, expr) + let vel_fric = if node.kind == "pFriction" || !node.inputs.contains_key("Drag") { + comp.eval_number(node, "VelocityFriction", t, 0.05, expr) } else { - 1.0 - comp.eval_number(node, "Drag", t, 0.05, expr) - } - .clamp(0.0, 1.0); - let spin_damp = if node.kind == "pFriction" { - 1.0 - comp.eval_number(node, "SpinFriction", t, 0.05, expr).clamp(0.0, 1.0) + comp.eval_number(node, "Drag", t, 0.05, expr) + }; + let damp = (1.0 - vel_fric).clamp(0.0, 1.0); + let spin_damp = if node.kind == "pFriction" || node.inputs.contains_key("SpinFriction") { + (1.0 - comp.eval_number(node, "SpinFriction", t, 0.05, expr)).clamp(0.0, 1.0) } else { 1.0 }; @@ -752,11 +789,11 @@ fn apply_modifier( "pTurbulence" => { let sx = comp.eval_number(node, "XStrength", t, 0.1, expr); let sy = comp.eval_number(node, "YStrength", t, 0.1, expr); - let sz = comp.eval_number(node, "ZStrength", t, 0.0, expr); + let sz = comp.eval_number(node, "ZStrength", t, 0.1, expr); if sx.abs() < 1e-12 && sy.abs() < 1e-12 && sz.abs() < 1e-12 { return; } - let density = comp.eval_number(node, "Density", t, 1.0, expr).max(0.01); + let density = comp.eval_number(node, "Density", t, 10.0, expr).max(0.01); let seed = comp.eval_number(node, "RandomSeed", t, 0.0, expr).round() as u64; let time_shift = t * 0.03; @@ -768,8 +805,10 @@ fn apply_modifier( let qy = p.pos[1] * density - time_shift * 0.7; let qz = p.pos[2] * density; let nx = value_noise_3d(qx, qy, qz, seed); - let ny = value_noise_3d(qx + 31.7, qy + 17.3, qz + 47.1, seed ^ 0x517C_C1B7_2722_0A95); - let nz = value_noise_3d(qx - 19.4, qy + 53.9, qz - 11.2, seed ^ 0x9E37_79B9_7F4A_7C15); + let ny = + value_noise_3d(qx + 31.7, qy + 17.3, qz + 47.1, seed ^ 0x517C_C1B7_2722_0A95); + let nz = + value_noise_3d(qx - 19.4, qy + 53.9, qz - 11.2, seed ^ 0x9E37_79B9_7F4A_7C15); p.vel[0] += nx * sx * TURBULENCE_SCALE; p.vel[1] += ny * sy * TURBULENCE_SCALE; p.vel[2] += nz * sz * TURBULENCE_SCALE; diff --git a/scripts/accuracy_ledger.json b/scripts/accuracy_ledger.json index 2662ee9ed920f98ee92909a792c4d2a365d4752b..6595e0f53d580c59339d318054c5b8f1b24e0bd4 100644 --- a/scripts/accuracy_ledger.json +++ b/scripts/accuracy_ledger.json @@ -1247,42 +1247,42 @@ "category": "Transform, Warp & Framing" }, "Cube3D": { - "mean_accuracy": 98.5569, - "min_accuracy": 97.8672, - "mean_alpha_accuracy": 94.9009, - "min_alpha_accuracy": 92.4135, + "mean_accuracy": 99.9049, + "min_accuracy": 99.8407, + "mean_alpha_accuracy": 99.9924, + "min_alpha_accuracy": 99.9084, "frames": 12, - "timestamp": "2026-12-01T17:47:55Z", + "timestamp": "2026-12-01T23:48:11Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 97.8672, - "alpha_accuracy": 92.415 + "accuracy": 99.8845, + "alpha_accuracy": 100.0 }, { "frame": 1, "label": "Left.MtlStdInputs.MaterialID=16, Front.MtlStdInputs.Diffuse.Color.Red=0.22421", - "accuracy": 97.8866, - "alpha_accuracy": 92.415 + "accuracy": 99.9081, + "alpha_accuracy": 100.0 }, { "frame": 2, "label": "Transform3DOp.Translate.Z=-7.91602, Back.MtlStdInputs.ReceivesShadows=0, Front.MtlStdInputs.Transmittance.ColorDetail=0.89888", - "accuracy": 99.8103, - "alpha_accuracy": 99.5835 + "accuracy": 99.915, + "alpha_accuracy": 100.0 }, { "frame": 3, "label": "Right.MtlStdInputs.Diffuse.Color.Blue=0.46754", - "accuracy": 97.9141, - "alpha_accuracy": 92.415 + "accuracy": 99.8845, + "alpha_accuracy": 100.0 }, { "frame": 4, "label": "Back.MtlStdInputs.Specular.Color.Blue=0.70776, SurfaceCubeInputs.Controls.Tangents.Show=1", - "accuracy": 97.8672, - "alpha_accuracy": 92.415 + "accuracy": 99.8845, + "alpha_accuracy": 100.0 }, { "frame": 5, @@ -1293,8 +1293,8 @@ { "frame": 6, "label": "Top.MtlStdInputs.Transmittance.Color.Green=0.54232", - "accuracy": 97.8672, - "alpha_accuracy": 92.415 + "accuracy": 99.8845, + "alpha_accuracy": 100.0 }, { "frame": 7, @@ -1305,20 +1305,20 @@ { "frame": 8, "label": "Top.MtlStdInputs.Specular.Intensity=0.48618, Left.MtlStdInputs.Diffuse.Color.Blue=0.3401, SurfaceCubeInputs.SubdivisionWidth=11", - "accuracy": 97.8954, - "alpha_accuracy": 92.4135 + "accuracy": 99.8874, + "alpha_accuracy": 100.0 }, { "frame": 9, "label": "Transform3DOp.InvertTransform=1", - "accuracy": 97.8672, - "alpha_accuracy": 92.415 + "accuracy": 99.8845, + "alpha_accuracy": 100.0 }, { "frame": 10, "label": "Right.MtlStdInputs.Transmittance.AlphaDetail=0.5861, Top.MtlStdInputs.Transmittance.Saturation=0.56722", - "accuracy": 97.8672, - "alpha_accuracy": 92.415 + "accuracy": 99.8845, + "alpha_accuracy": 100.0 }, { "frame": 11, @@ -1496,47 +1496,47 @@ "category": "Transform, Warp & Framing" }, "DaySky": { - "mean_accuracy": 98.8731, - "min_accuracy": 93.8147, + "mean_accuracy": 99.8635, + "min_accuracy": 99.3055, "mean_alpha_accuracy": 100.0, "min_alpha_accuracy": 100.0, "frames": 12, - "timestamp": "2026-12-01T15:40:16Z", + "timestamp": "2026-12-01T23:48:02Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 99.0831, + "accuracy": 99.8897, "alpha_accuracy": 100.0 }, { "frame": 1, "label": "Day=17, Circumsolar.Intensity=0.74033", - "accuracy": 99.1467, + "accuracy": 99.9022, "alpha_accuracy": 100.0 }, { "frame": 2, "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", - "accuracy": 99.5588, + "accuracy": 99.8984, "alpha_accuracy": 100.0 }, { "frame": 3, "label": "Time=22.45137", - "accuracy": 93.8147, + "accuracy": 99.3055, "alpha_accuracy": 100.0 }, { "frame": 4, "label": "GlobalIn=144, Exposure=0.87893", - "accuracy": 99.1135, + "accuracy": 99.892, "alpha_accuracy": 100.0 }, { "frame": 5, "label": "Longitude=143.9376, Month=September, Circumsolar.Width=0.20021", - "accuracy": 99.4673, + "accuracy": 99.8696, "alpha_accuracy": 100.0 }, { @@ -1554,25 +1554,25 @@ { "frame": 8, "label": "GlobalOut=548, Day=27, Circumsolar.Intensity=0.12047", - "accuracy": 99.3797, + "accuracy": 99.9408, "alpha_accuracy": 100.0 }, { "frame": 9, "label": "Horizon.Brightness=0.90014", - "accuracy": 99.1079, + "accuracy": 99.888, "alpha_accuracy": 100.0 }, { "frame": 10, "label": "Latitude=70.22675, Turbidity=0.26902", - "accuracy": 99.4541, + "accuracy": 99.9051, "alpha_accuracy": 100.0 }, { "frame": 11, "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", - "accuracy": 98.3517, + "accuracy": 99.8711, "alpha_accuracy": 100.0 } ], @@ -2492,12 +2492,12 @@ "category": "Generators" }, "FilmGrain": { - "mean_accuracy": 96.2094, + "mean_accuracy": 96.3089, "min_accuracy": 91.7395, "mean_alpha_accuracy": 100.0, "min_alpha_accuracy": 100.0, "frames": 12, - "timestamp": "2026-12-01T18:59:00Z", + "timestamp": "2026-12-01T23:49:26Z", "per_frame": [ { "frame": 0, @@ -2514,37 +2514,37 @@ { "frame": 2, "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", - "accuracy": 96.5892, + "accuracy": 96.587, "alpha_accuracy": 100.0 }, { "frame": 3, "label": "BlueXSize=1.46911", - "accuracy": 96.632, + "accuracy": 96.6373, "alpha_accuracy": 100.0 }, { "frame": 4, "label": "RedYSize=3.4556, GreenXSize=1.41648", - "accuracy": 96.6088, + "accuracy": 96.6201, "alpha_accuracy": 100.0 }, { "frame": 5, "label": "TimeLockSeed=1, GreenOffset=-0.0103, BlueStrength=4.07106", - "accuracy": 95.6434, + "accuracy": 96.6551, "alpha_accuracy": 100.0 }, { "frame": 6, "label": "BlueOffset=-0.02686", - "accuracy": 96.6281, + "accuracy": 96.6155, "alpha_accuracy": 100.0 }, { "frame": 7, "label": "RedXSize=1.93192, LogProcessing=0", - "accuracy": 95.6357, + "accuracy": 95.8466, "alpha_accuracy": 100.0 }, { @@ -2568,7 +2568,7 @@ { "frame": 11, "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", - "accuracy": 96.6445, + "accuracy": 96.6146, "alpha_accuracy": 100.0 } ], @@ -3737,12 +3737,12 @@ "category": "3D Pipeline" }, "MtlBlinn": { - "mean_accuracy": 99.1714, - "min_accuracy": 95.8793, + "mean_accuracy": 99.5709, + "min_accuracy": 97.8704, "mean_alpha_accuracy": 94.9089, "min_alpha_accuracy": 48.6462, "frames": 12, - "timestamp": "2026-12-01T17:48:05Z", + "timestamp": "2026-12-01T23:49:17Z", "per_frame": [ { "frame": 0, @@ -3765,7 +3765,7 @@ { "frame": 3, "label": "Diffuse.Opacity=0.93702", - "accuracy": 97.0419, + "accuracy": 98.7846, "alpha_accuracy": 96.4366 }, { @@ -3813,7 +3813,7 @@ { "frame": 11, "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", - "accuracy": 95.8793, + "accuracy": 98.9311, "alpha_accuracy": 93.8235 } ], @@ -3903,12 +3903,12 @@ "category": "3D Pipeline" }, "MtlPhong": { - "mean_accuracy": 98.8657, - "min_accuracy": 91.2276, + "mean_accuracy": 99.4048, + "min_accuracy": 96.5864, "mean_alpha_accuracy": 91.0109, "min_alpha_accuracy": 8.5935, "frames": 12, - "timestamp": "2026-12-01T17:48:14Z", + "timestamp": "2026-12-01T23:49:09Z", "per_frame": [ { "frame": 0, @@ -3949,7 +3949,7 @@ { "frame": 6, "label": "Diffuse.Opacity=0.73887", - "accuracy": 91.2276, + "accuracy": 97.6971, "alpha_accuracy": 87.9675 }, { @@ -4235,84 +4235,84 @@ "category": "Time, Routing & Utility" }, "Plasma": { - "mean_accuracy": 98.0516, - "min_accuracy": 77.8272, - "mean_alpha_accuracy": 98.0419, - "min_alpha_accuracy": 77.6996, + "mean_accuracy": 99.8692, + "min_accuracy": 98.4626, + "mean_alpha_accuracy": 99.8702, + "min_alpha_accuracy": 98.4736, "frames": 12, - "timestamp": "2026-12-01T15:45:00Z", + "timestamp": "2026-12-01T23:47:54Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 99.946, - "alpha_accuracy": 99.9469 + "accuracy": 99.9981, + "alpha_accuracy": 99.9984 }, { "frame": 1, "label": "Phase=0.21449, Operation=2", - "accuracy": 99.3417, - "alpha_accuracy": 99.3492 + "accuracy": 99.9882, + "alpha_accuracy": 99.9873 }, { "frame": 2, "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]", - "accuracy": 99.9466, - "alpha_accuracy": 99.9458 + "accuracy": 99.998, + "alpha_accuracy": 99.9979 }, { "frame": 3, "label": "Circle4Type=1", - "accuracy": 99.8825, - "alpha_accuracy": 99.8836 + "accuracy": 99.998, + "alpha_accuracy": 99.9979 }, { "frame": 4, "label": "Circle4Scale=6.22018, Scale=1.53596", - "accuracy": 99.9498, - "alpha_accuracy": 99.9505 + "accuracy": 99.9979, + "alpha_accuracy": 99.9979 }, { "frame": 5, "label": "AlphaPhase=0.33794, Circle2Center=[0.9242, 0.4649], Circle3Center=[0.62, 0.423]", - "accuracy": 99.9473, - "alpha_accuracy": 99.947 + "accuracy": 99.998, + "alpha_accuracy": 99.9982 }, { "frame": 6, "label": "Circle3Type=0", - "accuracy": 99.9432, - "alpha_accuracy": 99.9447 + "accuracy": 99.998, + "alpha_accuracy": 99.9981 }, { "frame": 7, "label": "RedPhase=0.39531, Circle4Center=[0.2463, 0.1526]", - "accuracy": 99.9467, - "alpha_accuracy": 99.9472 + "accuracy": 99.998, + "alpha_accuracy": 99.9981 }, { "frame": 8, "label": "Circle1Type=0, Circle3Scale=6.13489, Circle2Type=0", - "accuracy": 99.9929, - "alpha_accuracy": 99.9927 + "accuracy": 99.998, + "alpha_accuracy": 99.9981 }, { "frame": 9, "label": "Circle2Scale=9.01932", - "accuracy": 99.9485, - "alpha_accuracy": 99.9484 + "accuracy": 99.998, + "alpha_accuracy": 99.998 }, { "frame": 10, "label": "BluePhase=0.16082, GreenPhase=0.31153", - "accuracy": 99.9466, - "alpha_accuracy": 99.9469 + "accuracy": 99.9981, + "alpha_accuracy": 99.9984 }, { "frame": 11, "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]", - "accuracy": 77.8272, - "alpha_accuracy": 77.6996 + "accuracy": 98.4626, + "alpha_accuracy": 98.4736 } ], "category": "Generators" @@ -5314,84 +5314,84 @@ "category": "Blur, Sharpen & Glow" }, "Text3D": { - "mean_accuracy": 97.9281, - "min_accuracy": 93.6396, - "mean_alpha_accuracy": 97.9066, - "min_alpha_accuracy": 93.6396, + "mean_accuracy": 98.5185, + "min_accuracy": 95.337, + "mean_alpha_accuracy": 98.5028, + "min_alpha_accuracy": 95.337, "frames": 12, - "timestamp": "2026-12-01T18:57:44Z", + "timestamp": "2026-12-01T23:48:17Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 98.4733, - "alpha_accuracy": 98.4733 + "accuracy": 98.8826, + "alpha_accuracy": 98.8826 }, { "frame": 1, "label": "Level1=1, MiterLimit1=2.25293", - "accuracy": 98.4733, - "alpha_accuracy": 98.4733 + "accuracy": 98.8826, + "alpha_accuracy": 98.8826 }, { "frame": 2, "label": "HorizontallyJustified=0.26834, Red1Clone=0.1994, CleanIntersections1=1", - "accuracy": 98.4733, - "alpha_accuracy": 98.4733 + "accuracy": 98.8826, + "alpha_accuracy": 98.8826 }, { "frame": 3, "label": "LinePivot=[0.2658, -0.0958]", - "accuracy": 98.4733, - "alpha_accuracy": 98.4733 + "accuracy": 98.8826, + "alpha_accuracy": 98.8826 }, { "frame": 4, "label": "CharacterSizeX=1.3364, ImageSource1=1", - "accuracy": 98.5892, - "alpha_accuracy": 98.5892 + "accuracy": 99.1562, + "alpha_accuracy": 99.1562 }, { "frame": 5, "label": "LineSizeY=4.18055, BlueBevel=0.54337, UseOneMaterial=0", - "accuracy": 93.6396, - "alpha_accuracy": 93.6396 + "accuracy": 95.337, + "alpha_accuracy": 95.337 }, { "frame": 6, "label": "VerticallyJustified=0.22981", - "accuracy": 98.4733, - "alpha_accuracy": 98.4733 + "accuracy": 98.8826, + "alpha_accuracy": 98.8826 }, { "frame": 7, "label": "ScrollPosition=0.71693, Overlap1=1", - "accuracy": 98.4733, - "alpha_accuracy": 98.4733 + "accuracy": 98.8826, + "alpha_accuracy": 98.8826 }, { "frame": 8, "label": "SpecularRed=0.45963, ColorBrush1=14, Clip=1", - "accuracy": 98.4733, - "alpha_accuracy": 98.4733 + "accuracy": 98.8826, + "alpha_accuracy": 98.8826 }, { "frame": 9, "label": "AlphaBevel=0.47633", - "accuracy": 98.4733, - "alpha_accuracy": 98.4733 + "accuracy": 98.8826, + "alpha_accuracy": 98.8826 }, { "frame": 10, "label": "SelectElement=1, Green1=0.35516", - "accuracy": 98.7313, - "alpha_accuracy": 98.4733 + "accuracy": 99.0704, + "alpha_accuracy": 98.8826 }, { "frame": 11, "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", - "accuracy": 96.3905, - "alpha_accuracy": 96.3905 + "accuracy": 97.5975, + "alpha_accuracy": 97.5975 } ], "category": "3D Pipeline" @@ -6310,333 +6310,333 @@ "category": "Masks" }, "pBounce": { - "mean_accuracy": 98.5555, - "min_accuracy": 98.1757, - "mean_alpha_accuracy": 98.5555, - "min_alpha_accuracy": 98.1757, + "mean_accuracy": 99.8083, + "min_accuracy": 99.6713, + "mean_alpha_accuracy": 99.8083, + "min_alpha_accuracy": 99.6713, "frames": 12, - "timestamp": "2026-12-01T15:48:22Z", + "timestamp": "2026-12-01T23:48:48Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 99.119, - "alpha_accuracy": 99.119 + "accuracy": 99.9599, + "alpha_accuracy": 99.9599 }, { "frame": 1, "label": "Roughness=9.94739, Set13=0", - "accuracy": 98.8851, - "alpha_accuracy": 98.8851 + "accuracy": 99.9249, + "alpha_accuracy": 99.9249 }, { "frame": 2, "label": "Set1=0, Set6=0, Set19=0", - "accuracy": 98.8063, - "alpha_accuracy": 98.8063 + "accuracy": 99.8943, + "alpha_accuracy": 99.8943 }, { "frame": 3, "label": "Set25=0", - "accuracy": 98.7001, - "alpha_accuracy": 98.7001 + "accuracy": 99.8616, + "alpha_accuracy": 99.8616 }, { "frame": 4, "label": "Set28=0, Set21=0", - "accuracy": 98.5436, - "alpha_accuracy": 98.5436 + "accuracy": 99.8464, + "alpha_accuracy": 99.8464 }, { "frame": 5, "label": "Set27=0, Set5=0, Set20=0", - "accuracy": 98.5054, - "alpha_accuracy": 98.5054 + "accuracy": 99.8142, + "alpha_accuracy": 99.8142 }, { "frame": 6, "label": "SetMode=Ignore", - "accuracy": 98.5573, - "alpha_accuracy": 98.5573 + "accuracy": 99.7892, + "alpha_accuracy": 99.7892 }, { "frame": 7, "label": "EndAge=0.49319, Variance=0.31734", - "accuracy": 98.4019, - "alpha_accuracy": 98.4019 + "accuracy": 99.765, + "alpha_accuracy": 99.765 }, { "frame": 8, "label": "RandomSeed=743, Set29=0, Set4=0", - "accuracy": 98.3643, - "alpha_accuracy": 98.3643 + "accuracy": 99.7458, + "alpha_accuracy": 99.7458 }, { "frame": 9, "label": "Set22=0", - "accuracy": 98.3073, - "alpha_accuracy": 98.3073 + "accuracy": 99.7216, + "alpha_accuracy": 99.7216 }, { "frame": 10, "label": "LineRgn.End.Y=-1.35171, Set11=0", - "accuracy": 98.1757, - "alpha_accuracy": 98.1757 + "accuracy": 99.7053, + "alpha_accuracy": 99.7053 }, { "frame": 11, "label": "Roughness=13.26565, Set13=0, Set1=0, Set6=0, Set19=0, Set25=0, Set28=0, Set21=0, Set27=0, Set5=0", - "accuracy": 98.3003, - "alpha_accuracy": 98.3003 + "accuracy": 99.6713, + "alpha_accuracy": 99.6713 } ], "category": "Particles" }, "pDirectionalForce": { - "mean_accuracy": 98.4816, - "min_accuracy": 97.9117, - "mean_alpha_accuracy": 98.4816, - "min_alpha_accuracy": 97.9117, + "mean_accuracy": 99.8136, + "min_accuracy": 99.708, + "mean_alpha_accuracy": 99.8136, + "min_alpha_accuracy": 99.708, "frames": 12, - "timestamp": "2026-12-01T15:48:28Z", + "timestamp": "2026-12-01T23:48:36Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 99.119, - "alpha_accuracy": 99.119 + "accuracy": 99.9599, + "alpha_accuracy": 99.9599 }, { "frame": 1, "label": "Probability=0.84725, Set26=0", - "accuracy": 98.8805, - "alpha_accuracy": 98.8805 + "accuracy": 99.9288, + "alpha_accuracy": 99.9288 }, { "frame": 2, "label": "Strength=0.10884, Set21=0, Set13=0", - "accuracy": 98.7972, - "alpha_accuracy": 98.7972 + "accuracy": 99.8979, + "alpha_accuracy": 99.8979 }, { "frame": 3, "label": "Set4=0", - "accuracy": 98.7043, - "alpha_accuracy": 98.7043 + "accuracy": 99.8778, + "alpha_accuracy": 99.8778 }, { "frame": 4, "label": "EndAge=0.32638, Set3=0", - "accuracy": 98.5449, - "alpha_accuracy": 98.5449 + "accuracy": 99.8432, + "alpha_accuracy": 99.8432 }, { "frame": 5, "label": "Set6=0, Set30=0, Set32=0", - "accuracy": 98.4607, - "alpha_accuracy": 98.4607 + "accuracy": 99.8102, + "alpha_accuracy": 99.8102 }, { "frame": 6, "label": "RegionMode=Ignore", - "accuracy": 98.4911, - "alpha_accuracy": 98.4911 + "accuracy": 99.7909, + "alpha_accuracy": 99.7909 }, { "frame": 7, "label": "StartAge=0.58407, Set5=0", - "accuracy": 98.3235, - "alpha_accuracy": 98.3235 + "accuracy": 99.7666, + "alpha_accuracy": 99.7666 }, { "frame": 8, "label": "Set25=0, Set14=0, Set9=0", - "accuracy": 98.2251, - "alpha_accuracy": 98.2251 + "accuracy": 99.7358, + "alpha_accuracy": 99.7358 }, { "frame": 9, "label": "Set10=0", - "accuracy": 98.1312, - "alpha_accuracy": 98.1312 + "accuracy": 99.7281, + "alpha_accuracy": 99.7281 }, { "frame": 10, "label": "Set18=0, Set31=0", - "accuracy": 97.9117, - "alpha_accuracy": 97.9117 + "accuracy": 99.7164, + "alpha_accuracy": 99.7164 }, { "frame": 11, "label": "Probability=0.09316, Set26=0, Strength=-0.05223, Set21=0, Set13=0, Set4=0, EndAge=0.62652, Set3=0, Set6=0, Set30=0", - "accuracy": 98.1898, - "alpha_accuracy": 98.1898 + "accuracy": 99.708, + "alpha_accuracy": 99.708 } ], "category": "Particles" }, "pDrag": { - "mean_accuracy": 98.6098, - "min_accuracy": 98.31, - "mean_alpha_accuracy": 98.6098, - "min_alpha_accuracy": 98.31, + "mean_accuracy": 99.8245, + "min_accuracy": 99.7331, + "mean_alpha_accuracy": 99.8245, + "min_alpha_accuracy": 99.7331, "frames": 12, - "timestamp": "2026-12-01T15:48:35Z", + "timestamp": "2026-12-01T23:49:01Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 99.1184, - "alpha_accuracy": 99.1184 + "accuracy": 99.9591, + "alpha_accuracy": 99.9591 }, { "frame": 1, "label": "Region=CubeRgn, Set2=0", - "accuracy": 98.8878, - "alpha_accuracy": 98.8878 + "accuracy": 99.9231, + "alpha_accuracy": 99.9231 }, { "frame": 2, "label": "Set15=0, Set25=0, Set12=0", - "accuracy": 98.8104, - "alpha_accuracy": 98.8104 + "accuracy": 99.8991, + "alpha_accuracy": 99.8991 }, { "frame": 3, "label": "Set13=0", - "accuracy": 98.7067, - "alpha_accuracy": 98.7067 + "accuracy": 99.8714, + "alpha_accuracy": 99.8714 }, { "frame": 4, "label": "Set1=0, Set19=0", - "accuracy": 98.563, - "alpha_accuracy": 98.563 + "accuracy": 99.8478, + "alpha_accuracy": 99.8478 }, { "frame": 5, "label": "SpinFriction=0.90166, Set30=0, SetMode=DontAffect", - "accuracy": 98.5434, - "alpha_accuracy": 98.5434 + "accuracy": 99.8246, + "alpha_accuracy": 99.8246 }, { "frame": 6, "label": "Set3=0", - "accuracy": 98.6045, - "alpha_accuracy": 98.6045 + "accuracy": 99.7949, + "alpha_accuracy": 99.7949 }, { "frame": 7, "label": "Set21=0, Probability=0.09181", - "accuracy": 98.4676, - "alpha_accuracy": 98.4676 + "accuracy": 99.778, + "alpha_accuracy": 99.778 }, { "frame": 8, "label": "Set20=0, Set16=0, RandomSeed=915", - "accuracy": 98.4425, - "alpha_accuracy": 98.4425 + "accuracy": 99.7742, + "alpha_accuracy": 99.7742 }, { "frame": 9, "label": "StartAge=0.05488", - "accuracy": 98.4165, - "alpha_accuracy": 98.4165 + "accuracy": 99.7445, + "alpha_accuracy": 99.7445 }, { "frame": 10, "label": "Set17=0, Set22=0", - "accuracy": 98.31, - "alpha_accuracy": 98.31 + "accuracy": 99.7443, + "alpha_accuracy": 99.7443 }, { "frame": 11, "label": "Region=LineRgn, Set2=0, Set15=0, Set25=0, Set12=0, Set13=0, Set1=0, Set19=0, SpinFriction=0.63321, Set30=0", - "accuracy": 98.4467, - "alpha_accuracy": 98.4467 + "accuracy": 99.7331, + "alpha_accuracy": 99.7331 } ], "category": "Particles" }, "pEmitter": { - "mean_accuracy": 98.2475, - "min_accuracy": 97.0471, - "mean_alpha_accuracy": 98.2482, - "min_alpha_accuracy": 97.0471, + "mean_accuracy": 99.8132, + "min_accuracy": 99.6732, + "mean_alpha_accuracy": 99.8121, + "min_alpha_accuracy": 99.6732, "frames": 12, - "timestamp": "2026-12-01T15:48:42Z", + "timestamp": "2026-12-01T23:48:24Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 99.0113, - "alpha_accuracy": 99.0113 + "accuracy": 99.9564, + "alpha_accuracy": 99.9564 }, { "frame": 1, "label": "Set24=1, Set14=1", - "accuracy": 98.7924, - "alpha_accuracy": 98.7924 + "accuracy": 99.9309, + "alpha_accuracy": 99.9309 }, { "frame": 2, "label": "RotationZ=134.28566, RotationXVariance=145.73754, VelocityVariance=0.49077", - "accuracy": 97.6235, - "alpha_accuracy": 97.6235 + "accuracy": 99.8807, + "alpha_accuracy": 99.8807 }, { "frame": 3, "label": "SpinZVariance=90.70891", - "accuracy": 98.6042, - "alpha_accuracy": 98.6042 + "accuracy": 99.862, + "alpha_accuracy": 99.862 }, { "frame": 4, "label": "SphereRgn.Rotate.Z=31.10569, ParticleStyle.RedHigh=-0.43584", - "accuracy": 98.6261, - "alpha_accuracy": 98.6346 + "accuracy": 99.8546, + "alpha_accuracy": 99.842 }, { "frame": 5, "label": "Set18=1, TimeLockSeed=1, Set7=1", - "accuracy": 98.5158, - "alpha_accuracy": 98.5158 + "accuracy": 99.8199, + "alpha_accuracy": 99.8199 }, { "frame": 6, "label": "Set3=1", - "accuracy": 98.4437, - "alpha_accuracy": 98.4437 + "accuracy": 99.8074, + "alpha_accuracy": 99.8074 }, { "frame": 7, "label": "ParticleStyle.BlueHigh=0.10081, Set17=1", - "accuracy": 98.4191, - "alpha_accuracy": 98.4191 + "accuracy": 99.7962, + "alpha_accuracy": 99.7962 }, { "frame": 8, "label": "ParticleStyle.GreenLow=0.74792, InheritVelocityVariance=0.8157, InheritVelocity=1.28612", - "accuracy": 98.4047, - "alpha_accuracy": 98.4047 + "accuracy": 99.7598, + "alpha_accuracy": 99.7598 }, { "frame": 9, "label": "ParticleStylePoint.SubPixelRendered=1", - "accuracy": 98.2948, - "alpha_accuracy": 98.2948 + "accuracy": 99.7425, + "alpha_accuracy": 99.7425 }, { "frame": 10, "label": "AlwaysFaceCamera=0, AngleVariance=149.8772", - "accuracy": 97.0471, - "alpha_accuracy": 97.0471 + "accuracy": 99.6732, + "alpha_accuracy": 99.6732 }, { "frame": 11, "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", - "accuracy": 97.1871, - "alpha_accuracy": 97.1871 + "accuracy": 99.6747, + "alpha_accuracy": 99.6747 } ], "category": "Particles" @@ -6808,250 +6808,250 @@ "category": "Particles" }, "pPointForce": { - "mean_accuracy": 98.5158, - "min_accuracy": 97.9994, - "mean_alpha_accuracy": 98.5158, - "min_alpha_accuracy": 97.9994, + "mean_accuracy": 99.7975, + "min_accuracy": 99.6424, + "mean_alpha_accuracy": 99.7975, + "min_alpha_accuracy": 99.6424, "frames": 12, - "timestamp": "2026-12-01T15:49:02Z", + "timestamp": "2026-12-01T23:48:42Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 99.119, - "alpha_accuracy": 99.119 + "accuracy": 99.9599, + "alpha_accuracy": 99.9599 }, { "frame": 1, "label": "EndAge=0.6275, Set13=0", - "accuracy": 98.8842, - "alpha_accuracy": 98.8842 + "accuracy": 99.9335, + "alpha_accuracy": 99.9335 }, { "frame": 2, "label": "Set19=0, StartAge=0.3012, Set24=0", - "accuracy": 98.8076, - "alpha_accuracy": 98.8076 + "accuracy": 99.8894, + "alpha_accuracy": 99.8894 }, { "frame": 3, "label": "Set11=0", - "accuracy": 98.6889, - "alpha_accuracy": 98.6889 + "accuracy": 99.8816, + "alpha_accuracy": 99.8816 }, { "frame": 4, "label": "Set1=0, Set10=0", - "accuracy": 98.5319, - "alpha_accuracy": 98.5319 + "accuracy": 99.8456, + "alpha_accuracy": 99.8456 }, { "frame": 5, "label": "Set12=0, Set29=0, Set28=0", - "accuracy": 98.4815, - "alpha_accuracy": 98.4815 + "accuracy": 99.8069, + "alpha_accuracy": 99.8069 }, { "frame": 6, "label": "Set20=0", - "accuracy": 98.5125, - "alpha_accuracy": 98.5125 + "accuracy": 99.7751, + "alpha_accuracy": 99.7751 }, { "frame": 7, "label": "Set26=0, Translate.Z=-7.72739", - "accuracy": 98.404, - "alpha_accuracy": 98.404 + "accuracy": 99.7727, + "alpha_accuracy": 99.7727 }, { "frame": 8, "label": "Set2=0, Probability=0.84479, Set30=0", - "accuracy": 98.2762, - "alpha_accuracy": 98.2762 + "accuracy": 99.7243, + "alpha_accuracy": 99.7243 }, { "frame": 9, "label": "Set32=0", - "accuracy": 98.1689, - "alpha_accuracy": 98.1689 + "accuracy": 99.6953, + "alpha_accuracy": 99.6953 }, { "frame": 10, "label": "Set22=0, Set6=0", - "accuracy": 97.9994, - "alpha_accuracy": 97.9994 + "accuracy": 99.6432, + "alpha_accuracy": 99.6432 }, { "frame": 11, "label": "EndAge=0.79341, Set13=0, Set19=0, StartAge=0.81852, Set24=0, Set11=0, Set1=0, Set10=0, Set12=0, Set29=0", - "accuracy": 98.3149, - "alpha_accuracy": 98.3149 + "accuracy": 99.6424, + "alpha_accuracy": 99.6424 } ], "category": "Particles" }, "pRender": { - "mean_accuracy": 98.4485, - "min_accuracy": 97.7268, - "mean_alpha_accuracy": 98.4485, - "min_alpha_accuracy": 97.7268, + "mean_accuracy": 99.6839, + "min_accuracy": 98.4009, + "mean_alpha_accuracy": 99.6839, + "min_alpha_accuracy": 98.4009, "frames": 12, - "timestamp": "2026-12-01T15:49:08Z", + "timestamp": "2026-12-01T23:48:30Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 99.119, - "alpha_accuracy": 99.119 + "accuracy": 99.9599, + "alpha_accuracy": 99.9599 }, { "frame": 1, "label": "PreGenerateFrames=90, ObjectID.Set19=4", - "accuracy": 97.7268, - "alpha_accuracy": 97.7268 + "accuracy": 98.4009, + "alpha_accuracy": 98.4009 }, { "frame": 2, "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", - "accuracy": 98.7439, - "alpha_accuracy": 98.7439 + "accuracy": 99.9397, + "alpha_accuracy": 99.9397 }, { "frame": 3, "label": "RotationOrder=4", - "accuracy": 98.7015, - "alpha_accuracy": 98.7015 + "accuracy": 99.8654, + "alpha_accuracy": 99.8654 }, { "frame": 4, "label": "ObjectID.Set15=23, Glow=0.09235", - "accuracy": 98.5458, - "alpha_accuracy": 98.5458 + "accuracy": 99.846, + "alpha_accuracy": 99.846 }, { "frame": 5, "label": "ObjectID.Set26=22, MaterialID.Set11=3, ShowGrid=1", - "accuracy": 98.5078, - "alpha_accuracy": 98.5078 + "accuracy": 99.8147, + "alpha_accuracy": 99.8147 }, { "frame": 6, "label": "ObjectID.Set23=15", - "accuracy": 98.5608, - "alpha_accuracy": 98.5608 + "accuracy": 99.7969, + "alpha_accuracy": 99.7969 }, { "frame": 7, "label": "ObjectID.Set18=15, GridBlue=0.40469", - "accuracy": 98.404, - "alpha_accuracy": 98.404 + "accuracy": 99.7727, + "alpha_accuracy": 99.7727 }, { "frame": 8, "label": "OutputMode=ThreeD, GenerateZBuffer=1, ObjectID.Set1=2", - "accuracy": 98.368, - "alpha_accuracy": 98.368 + "accuracy": 99.7773, + "alpha_accuracy": 99.7773 }, { "frame": 9, "label": "MaterialID.Set22=21", - "accuracy": 98.3152, - "alpha_accuracy": 98.3152 + "accuracy": 99.7519, + "alpha_accuracy": 99.7519 }, { "frame": 10, "label": "ObjectID.Set32=10, Rotate.X=-76.18976", - "accuracy": 97.9746, - "alpha_accuracy": 97.9746 + "accuracy": 99.7909, + "alpha_accuracy": 99.7909 }, { "frame": 11, "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", - "accuracy": 98.4146, - "alpha_accuracy": 98.4146 + "accuracy": 99.4911, + "alpha_accuracy": 99.4911 } ], "category": "Particles" }, "pTurbulence": { - "mean_accuracy": 98.5835, - "min_accuracy": 98.2654, - "mean_alpha_accuracy": 98.5835, - "min_alpha_accuracy": 98.2654, + "mean_accuracy": 99.8163, + "min_accuracy": 99.6958, + "mean_alpha_accuracy": 99.8163, + "min_alpha_accuracy": 99.6958, "frames": 12, - "timestamp": "2026-12-01T15:49:15Z", + "timestamp": "2026-12-01T23:48:55Z", "per_frame": [ { "frame": 0, "label": "defaults", - "accuracy": 99.119, - "alpha_accuracy": 99.119 + "accuracy": 99.9599, + "alpha_accuracy": 99.9599 }, { "frame": 1, "label": "SetMode=DontAffect, ZStrength=0.24941", - "accuracy": 98.8854, - "alpha_accuracy": 98.8854 + "accuracy": 99.9277, + "alpha_accuracy": 99.9277 }, { "frame": 2, "label": "Set5=0, TimeLockSeed=1, Set12=0", - "accuracy": 98.8075, - "alpha_accuracy": 98.8075 + "accuracy": 99.896, + "alpha_accuracy": 99.896 }, { "frame": 3, "label": "Set16=0", - "accuracy": 98.7008, - "alpha_accuracy": 98.7008 + "accuracy": 99.8682, + "alpha_accuracy": 99.8682 }, { "frame": 4, "label": "Set21=0, Set19=0", - "accuracy": 98.5508, - "alpha_accuracy": 98.5508 + "accuracy": 99.8482, + "alpha_accuracy": 99.8482 }, { "frame": 5, "label": "Set17=0, Set20=0, Set23=0", - "accuracy": 98.5278, - "alpha_accuracy": 98.5278 + "accuracy": 99.8121, + "alpha_accuracy": 99.8121 }, { "frame": 6, "label": "Set11=0", - "accuracy": 98.5823, - "alpha_accuracy": 98.5823 + "accuracy": 99.7999, + "alpha_accuracy": 99.7999 }, { "frame": 7, "label": "RegionMode=NotInside, Set2=0", - "accuracy": 98.4446, - "alpha_accuracy": 98.4446 + "accuracy": 99.7751, + "alpha_accuracy": 99.7751 }, { "frame": 8, "label": "Set27=0, Set25=0, Set6=0", - "accuracy": 98.4108, - "alpha_accuracy": 98.4108 + "accuracy": 99.7596, + "alpha_accuracy": 99.7596 }, { "frame": 9, "label": "Set29=0", - "accuracy": 98.378, - "alpha_accuracy": 98.378 + "accuracy": 99.7468, + "alpha_accuracy": 99.7468 }, { "frame": 10, "label": "Region=MeshRegion, Set13=0", - "accuracy": 98.2654, - "alpha_accuracy": 98.2654 + "accuracy": 99.7064, + "alpha_accuracy": 99.7064 }, { "frame": 11, "label": "SetMode=Ignore, ZStrength=0.41533, Set5=0, TimeLockSeed=1, Set12=0, Set16=0, Set21=0, Set19=0, Set17=0, Set20=0", - "accuracy": 98.3298, - "alpha_accuracy": 98.3298 + "accuracy": 99.6958, + "alpha_accuracy": 99.6958 } ], "category": "Particles" -- 2.54.1