Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,25 @@ in-place tests' world, rows given back; two models in a shared pose posed again
(tests/render/data/arm.glb, a skinned strip of two materials); `geometry/emitter-model-live` (a model's emitting
section that is not its first, the model a unit under software traversal).

**A posed skinned model is a mesh of its own (2026-11-21).** Models in the same pose (the same clip and time) shared
one mesh, found by the build; one of them taking another pose had to leave it, and that rebuilt the scene (and a
rebuild grouped whichever models then happened to be in one pose). A model alone in its pose was no mesh at all:
world-space triangles, skinned on the CPU. Now every posed skinned model is an instance of a mesh of its own
(`scene::Skinned`), skinned by the pass at each new pose, never shared: another clip or time is in place whatever the
others do, and the model is hidden and shown in place by its instance (hidden, a new pose skins nothing; shown, it
is skinned as it is posed then). What the pass reads of a model is still one copy for all its placements. The
grouping, its key and the switch that turned it off are gone.
Still a rebuild: a skinned model added or removed; one hidden when the scene was built, shown; every pose under
software traversal (the next step). Still world-space triangles skinned on the CPU: a model with emitting triangles.
Measured, a crowd of 150 walkers (8 walk phases), hardware traversal, the builds in turn at 60 fps: a frame's commit
3.3 ms with a mesh a walker, against 2.1 with the 8 shared meshes and 2.9 before the pass; the BLAS builds 0.6 ms
against 0.24. With the CPU skin the same 150 meshes cost 20 ms of commit (40 fps): the reason the pass came first.
Tests: two models in one pose are two meshes skinned from one copy of the model's corners, posed again in place,
and one posed alone in place; one hidden, posed and moved while hidden, shown (under software traversal, hidden and
shown by a rebuild); four models of two files, each mesh's triangles, attributes and BLAS input on the GPU against
the CPU skin, one posed alone and the others' left as they were, one moved alone. 10 mutations of the new logic:
nine fail a test natively, the tenth (a model hidden where it has no instance to mask) under software traversal.

**Meshes that deform are skinned on the GPU (2026-11-21).** A new pose of a shared pose's mesh was skinned on the
CPU and every triangle of it sent again: 180 bytes each (its vertices, its shading attributes, the BLAS's input).
Now the CPU sends the pose's matrices (48 bytes a joint) and a compute pass skins the mesh where it lies
Expand Down
2 changes: 1 addition & 1 deletion docs/RUNTIME.md
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ procedural objects (`trace_procs`: the ray into the object's space, a tree of it
as vertex colours are; gpu.rs `KernelVariant::flags`): the file's walk, a call at the end of the still walk, and the still
walk's stack declaration taken out ("The stack"). A scene without units has none of it; hardware traversal's
kernel never does.
- Still flattened, as before: meshes that deform (a pose shared by a crowd), every instance of a scene with more
- Still flattened, as before: meshes that deform (a posed skinned model's), every instance of a scene with more
of them than a top tree holds (2^18), and every instance of an offline render (`prepare`; a live session's scene
goes through `prepare_live`), unless `THREERT_UNITS=1`. `THREERT_UNITS=0` flattens everything, as before this
step (the A/B).
Expand Down
12 changes: 6 additions & 6 deletions renderer/src/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub struct TopBuild {
pub instances: bool,
/// The dynamic groups' BLASes: their triangles were re-transformed.
pub dynamic: bool,
/// Instanced meshes' BLASes: new meshes, a new shared pose.
/// Instanced meshes' BLASes: new meshes, a skinned model's new pose.
pub meshes: Vec<u32>,
/// Procedural BLASes an edit made.
pub procs: Vec<PendingProc>,
Expand Down Expand Up @@ -747,7 +747,7 @@ struct SkinJob {
palette: u32,
}

/// The skinning pass of a scene (shaders/skin.wgsl): the meshes that deform (a job each, `scene::PoseGroup`'s index)
/// The skinning pass of a scene (shaders/skin.wgsl): the meshes that deform (a job each, `scene::Skinned`'s index)
/// are skinned from their models' corners and their poses' palettes into the scene's triangles, attributes and BLAS
/// input. Hardware RT.
pub struct SkinGpu {
Expand Down Expand Up @@ -2474,7 +2474,7 @@ impl Gpu {
.collect()
})
.collect();
// Deforming meshes (shared poses) are rebuilt every new pose: built fast rather than traced fast, as the dynamic
// Deforming meshes (posed skinned models') are rebuilt every new pose: built fast rather than traced fast, as the dynamic
// groups are.
let meshes: Vec<wgpu::Blas> = mesh_sizes
.iter()
Expand Down Expand Up @@ -2705,7 +2705,7 @@ impl Gpu {
};
// The skinning pass (hardware RT: it writes the BLASes' input), a job each mesh that deforms.
let skin = match &accel {
Some(a) if !scene.retained.pose_groups.is_empty() => Some(self.skin_pass(scene, a.pool_first, &b_verts, &b_attrs, &a.verts)),
Some(a) if !scene.retained.skinned.is_empty() => Some(self.skin_pass(scene, a.pool_first, &b_verts, &b_attrs, &a.verts)),
_ => None,
};
self.queue.submit([]);
Expand Down Expand Up @@ -3401,7 +3401,7 @@ impl Gpu {
}
}

/// The skinning pass of `scene`: its pipeline, the models' corners, a job each pose group, and room for a frame's
/// The skinning pass of `scene`: its pipeline, the models' corners, a job each skinned model, and room for a frame's
/// work and every job's palette.
fn skin_pass(&self, scene: &Scene, pool_first: usize, verts: &wgpu::Buffer, attrs: &wgpu::Buffer, blas_verts: &wgpu::Buffer) -> SkinGpu {
let d = &self.device;
Expand All @@ -3415,7 +3415,7 @@ impl Gpu {
}
let corners: Vec<crate::skin::SkinCorner> = scene.skin_sources.iter().flatten().flatten().copied().collect();
let (mut jobs, mut matrices, mut blocks) = (vec![], 0u32, 0u32);
for g in &scene.retained.pose_groups {
for g in &scene.retained.skinned {
let m = &scene.meshes[g.mesh as usize];
jobs.push((SkinJob { first: pool_first as u32 + m.first, count: m.count, source: source_first[g.source as usize], palette: matrices }, g.palette_len));
matrices += g.palette_len;
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ fn unit_trees(sc: &mut scene::Scene) -> Option<Vec<Option<units::MeshTree>>> {
Some(trees)
}

/// With units: the instances of meshes that deform (a pose a crowd shares) are still written out as world-space
/// With units: the instances of meshes that deform (a posed skinned model's) are still written out as world-space
/// triangles, as every instance was. They keep their place among the instances (edits name instances by index) and
/// are no unit.
fn flatten_deforming(sc: &mut scene::Scene) {
Expand Down
87 changes: 45 additions & 42 deletions renderer/src/live/edits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,10 @@ impl LiveCore {
let inst = self.sc.tables.retained.instance(k).filter(|i| i.moves).copied();
let masked = inst.is_some_and(|i| self.sc.instances.get(i.instance as usize).is_some_and(|x| x.masked));
if world.shown(k) || masked {
// Movable models placed as instances move their transform (with a shared pose too); the rest
// Movable models placed as instances move their transform (a posed skinned model too); the rest
// re-transform triangles.
match inst.map(|i| i.instance) {
Some(i) if !changes.poses.contains(&k) || inst.is_some_and(|i| matches!(i.mesh, scene::MeshKind::Pose(_))) => placed.push((k, i)),
Some(i) if !changes.poses.contains(&k) || inst.is_some_and(|i| matches!(i.mesh, scene::MeshKind::Skinned(_))) => placed.push((k, i)),
_ => {
dynamic.insert(k);
}
Expand Down Expand Up @@ -659,12 +659,12 @@ impl LiveCore {
for k in &rigid {
dynamic.remove(k);
}
// Models in a shared pose re-skin their group's mesh (`repose_groups`, its BLAS only); their moves place instances.
let shared: Vec<u32> = dynamic.iter().copied().filter(|k| self.sc.tables.retained.instance(*k).is_some_and(|i| matches!(i.mesh, scene::MeshKind::Pose(_)))).collect();
// Posed skinned models: their meshes skinned again (`repose_skinned`, their BLASes only); their moves place instances.
let shared: Vec<u32> = dynamic.iter().copied().filter(|k| self.sc.tables.retained.instance(*k).is_some_and(|i| matches!(i.mesh, scene::MeshKind::Skinned(_)))).collect();
for k in &shared {
dynamic.remove(k);
}
let shared_ok = shared.is_empty() || (!changes.structural && self.repose_groups(world, &shared, &mut top)?);
let shared_ok = shared.is_empty() || (!changes.structural && self.repose_skinned(world, &shared, &mut top)?);
// Procedural geometry moves its records and TLAS transforms.
if !procs_moved.is_empty() && !changes.structural {
self.move_procs(world, &procs_moved, &mut top);
Expand Down Expand Up @@ -1010,7 +1010,8 @@ impl LiveCore {
}

/// An object shown or hidden by its `visible`, in place: the meshes and models under it (itself, if it is one)
/// each by its instance's mask above the triangles (a posed rigid model's every part's), where no ray sees a
/// each by its instance's mask above the triangles (a posed rigid model's every part's; a posed skinned model's
/// own), where no ray sees a
/// hidden one, and its row's power (`Tables::apply`: a hidden mesh's emitters at no weight). False where
/// something under it is drawn another way, or a mesh is not such an instance (the build flattened it, or an edit
/// took it out while it was hidden): the caller rebuilds.
Expand All @@ -1021,8 +1022,12 @@ impl LiveCore {
crate::world::Kind::Group | crate::world::Kind::Camera(_) => {}
// (One this commit adds is placed as it is, shown or not: `edit_geometry`.)
crate::world::Kind::Mesh { .. } | crate::world::Kind::Model { .. } if changes.added.contains(&k) => {}
crate::world::Kind::Mesh { .. } | crate::world::Kind::Model { animation: None, .. } => {
let Some(r) = self.sc.tables.retained.instance(k).filter(|i| whole(i, &self.sc.instances, &self.sc.meshes)).map(|i| i.instance as usize) else { return false };
// A mesh, a still model, or a posed skinned model (an instance of its own mesh): its instance.
kind @ (crate::world::Kind::Mesh { .. } | crate::world::Kind::Model { .. })
if !matches!(kind, crate::world::Kind::Model { animation: Some(_), .. }) || self.sc.tables.retained.instance(k).is_some_and(|i| matches!(i.mesh, scene::MeshKind::Skinned(_))) =>
{
let skinned = matches!(kind, crate::world::Kind::Model { animation: Some(_), .. });
let Some(r) = self.sc.tables.retained.instance(k).filter(|i| skinned || whole(i, &self.sc.instances, &self.sc.meshes)).map(|i| i.instance as usize) else { return false };
let Some(inst) = self.sc.instances.get_mut(r) else { return false };
if inst.hidden && !inst.masked {
return false;
Expand All @@ -1034,11 +1039,19 @@ impl LiveCore {
continue;
}
let Some(mut top) = gpu::Top::of(&mut self.sc.up.accel, &mut self.sc.up.units) else { return false };
// (Software traversal has a skinned model's triangles in its still tree: no instance to mask.)
if !top.has_mesh(inst.mesh) {
return false;
}
(inst.hidden, inst.masked) = (unseen, unseen);
top.moved(top.inst_base() + r, w, Some((inst.cast_shadow, unseen)));
build.instances = true;
changes.powers.insert(k);
self.weigh_run(r as u32);
// (A skinned model shown is skinned as it is posed now: its mesh kept the pose it was hidden in.)
if skinned && !unseen {
changes.poses.insert(k);
}
}
// A posed rigid model: every part's instance. Shown, it is placed where it stands and posed as it is
// now (`repose_rigid`, this commit: a move while it was hidden placed nothing).
Expand Down Expand Up @@ -1824,52 +1837,42 @@ impl LiveCore {
Ok(true)
}

/// Models in a shared pose (`scene::PoseGroup`): each group whose pose changed is skinned once, in model space, by
/// the skinning pass (gpu.rs `skin`: the CPU sends its pose's matrices); the commit builds their BLASes and the
/// TLAS over their new bounds. False when a group's members no longer share one pose, one is hidden or changed,
/// or its new pose mirrors other primitives than the one its mesh was made for: the caller rebuilds, which groups
/// them again. (The CPU keeps no triangles of such a mesh's pose: `LiveCore::mesh_tris` skins it when asked.)
pub(super) fn repose_groups(&mut self, world: &World, members: &[u32], build: &mut gpu::TopBuild) -> Result<bool> {
/// Posed skinned models (`scene::Skinned`): each whose pose changed is skinned in its own space by the skinning
/// pass (gpu.rs `skin`: the CPU sends its pose's matrices); the commit builds their BLASes and the TLAS over their
/// new bounds. One that is hidden keeps the pose its mesh has: it is skinned when it is shown (`show_meshes`).
/// False when one is another model now, or its new pose mirrors other primitives than the one its mesh was made
/// for: the caller rebuilds. (The CPU keeps no triangles of such a pose: `LiveCore::mesh_tris` skins it when asked.)
pub(super) fn repose_skinned(&mut self, world: &World, ids: &[u32], build: &mut gpu::TopBuild) -> Result<bool> {
use rayon::prelude::*;
if self.sc.up.accel.is_none() || self.sc.up.skin.is_none() {
return Ok(false);
}
let r = &self.sc.tables.retained;
let group = |k: &u32| match r.instance(*k).map(|i| i.mesh) {
Some(scene::MeshKind::Pose(g)) => g,
_ => unreachable!("a pose group's member (`commit`)"),
};
let mut touched: Vec<u32> = members.iter().map(group).collect();
touched.sort_unstable();
touched.dedup();
let mut jobs: Vec<(u32, crate::desc::Animation)> = vec![];
for &g in &touched {
let pg = &r.pose_groups[g as usize];
let mut pose: Option<&crate::desc::Animation> = None;
for (id, _) in &pg.members {
let Some(o) = world.objects.get(id) else { return Ok(false) };
let crate::world::Kind::Model { uri, nodes, animation: Some(a), .. } = &o.kind else { return Ok(false) };
if !world.shown(*id) || *uri != pg.uri || *nodes != pg.nodes || pose.is_some_and(|p| p != a) {
return Ok(false);
}
pose = Some(a);
for id in ids {
let Some(scene::MeshKind::Skinned(g)) = r.instance(*id).map(|i| i.mesh) else { unreachable!("a posed skinned model (`commit`)") };
let sk = &r.skinned[g as usize];
let Some(o) = world.objects.get(id) else { return Ok(false) };
let crate::world::Kind::Model { uri, nodes, animation: Some(a), .. } = &o.kind else { return Ok(false) };
if *uri != sk.uri || *nodes != sk.nodes {
return Ok(false);
}
if let Some(a) = pose.filter(|a| **a != pg.animation) {
if world.shown(*id) && *a != sk.animation {
jobs.push((g, a.clone()));
}
}
if jobs.is_empty() {
return Ok(true);
}
// The poses' matrices (the groups in parallel).
// The poses' matrices (the models in parallel).
let t_skin = Instant::now();
let assets = &self.assets;
let palettes: Vec<Result<Option<Vec<crate::skin::PaletteRows>>>> = jobs
.par_iter()
.map(|(g, a)| {
let pg = &r.pose_groups[*g as usize];
let model = scene::model_gltf(&pg.uri, assets)?;
if model.mirrored(Some(a))? != pg.mirrors {
let sk = &r.skinned[*g as usize];
let model = scene::model_gltf(&sk.uri, assets)?;
if model.mirrored(Some(a))? != sk.mirrors {
return Ok(None);
}
Ok(Some(model.palette(Some(a))?))
Expand All @@ -1887,9 +1890,9 @@ impl LiveCore {
let df = self.sc.dynamic.0;
let (mut lo, mut hi) = (usize::MAX, 0usize);
for (g, _) in &jobs {
let pg = &self.sc.tables.retained.pose_groups[*g as usize];
let k = self.sc.gpu_instances[pg.members[0].1 as usize].info[0] as usize - df;
(lo, hi) = (lo.min(k), hi.max(k + pg.order.len()));
let sk = &self.sc.tables.retained.skinned[*g as usize];
let k = self.sc.gpu_instances[sk.instance as usize].info[0] as usize - df;
(lo, hi) = (lo.min(k), hi.max(k + sk.order.len()));
}
self.keep_prev(self.pose_span.map_or((lo, hi), |(a, b)| (a.min(lo), b.max(hi))));
if !self.g.skin(&self.sc.up, &work) {
Expand All @@ -1898,9 +1901,9 @@ impl LiveCore {
self.pose_span = Some((lo, hi));
self.pose_reposed = true;
for (g, a) in jobs {
let pg = &mut self.sc.tables.retained.pose_groups[g as usize];
pg.animation = a;
build.meshes.push(pg.mesh);
let sk = &mut self.sc.tables.retained.skinned[g as usize];
sk.animation = a;
build.meshes.push(sk.mesh);
}
self.cpu_upload_ms += t_up.elapsed().as_secs_f32() * 1000.0;
Ok(true)
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/live/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl LiveCore {
self.update_light_lod();
// A camera cut (a jump no camera makes in one frame: 2 m or 30 degrees) is not motion: no blur (UE: bCameraCut).
let cut = (self.cam.pos - self.prev_cam.pos).length() > 2.0 || self.cam.fwd.dot(self.prev_cam.fwd) < 0.866;
// (Objects moved this frame: re-posed triangles or moved instances, e.g. walkers in a shared pose.)
// (Objects moved this frame: re-posed triangles or moved instances, e.g. a crowd's walkers.)
let blur = self.blur.0 > 0.0 && (moved || self.reposed || self.pose_reposed || self.inst_moved) && !cut;
// Camera motion is reprojected exactly (disocclusions are rejected per pixel), so history survives motion;
// the cap only bounds smearing of view-dependent shading (glossy reflections).
Expand Down
Loading