EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge branch 'worktree-agent-aba044eaf08eded94'
Brandon Thomas871362ba96b7
diff --cc crates/render/src/three_d/compose.rsindex b134c88f2,711200727..c2dd4ec07--- a/crates/render/src/three_d/compose.rs+++ b/crates/render/src/three_d/compose.rs@@@ -365,23 -364,6 +365,23 @@@ pub(crate) fn draw_run(r: &Renderer, ctreturn;}let out = (canvas.width, canvas.height);+ let g = gather(r, ctx, run, out);- let casters: Vec<&Item> = g.items.iter().chain(g.extra.iter()).filter(|i| i.mat.casts_shadows != 0 && !i.geos.is_empty()).collect();++ let casters: Vec<&Item> = g.items.iter().chain(g.extra.iter()).filter(|i| r.opts.shadows() && i.mat.casts_shadows != 0 && !i.geos.is_empty()).collect();+ composite(canvas, &g.items, &g.lights, &casters, run[0].id.0 as u32);- for l in run.iter().filter(|l| l.switches.quality == effectcraft_project::Quality::Wireframe) {++ for l in run.iter().filter(|l| r.quality(l) == effectcraft_project::Quality::Wireframe) {+ r.draw_layer(ctx, l, canvas, false);+ }+}++/// The prepared planes of a run: drawn items (stack order), shadow casters outside the run, and+/// the lights.+struct Gathered<'a> {+ items: Vec<Item<'a>>,+ extra: Vec<Item<'a>>,+ lights: Vec<LightState>,+}++fn gather<'a>(r: &Renderer<'a>, ctx: &EvalCtx<'a>, run: &[&'a Layer], out: (u32, u32)) -> Gathered<'a> {// A collapsed precomp's 3D layers are lit by the outer comp's lights.let lights = scene_lights(&r.collapse3d.map_or(*ctx, |c| c.parent));let mut items: Vec<Item> = run@@@ -638,83 -624,6 +638,83 @@@ fn occlusion(c: &Item, p: Vec3, l: &Ligout}+// ------------------------------------------------------------------ accelerator export++/// A Classic 3D run prepared for an accelerator ([`Renderer::prepare_3d_run`]): every plane+/// with its geometry, material and buffer, ready for the per-pixel depth sort, lighting and+/// ray-cast shadows of [`draw_run`] on another device.+#[derive(Clone, Debug)]+pub struct Run3d {+ /// Drawn planes in stack order, then shadow casters from outside the run (`draw` false).+ pub planes: Vec<Plane3d>,+ /// Indices (into `planes`) of the shadow casters, in the CPU's order.+ pub casters: Vec<usize>,+ pub lights: Vec<LightState>,+ /// Dissolve seed of the run.+ pub seed: u32,+}++/// One plane of a [`Run3d`].+#[derive(Clone, Debug)]+pub struct Plane3d {+ /// The layer buffer (blending space; depth of field already applied).+ pub buf: Arc<Buf>,+ pub bicubic: bool,+ /// One per motion-blur sub-sample (equal weights).+ pub geos: Vec<Geo>,+ pub mat: Material,+ pub opacity: f32,+ pub draw: bool,+ /// Screen-space track matte factor (output size, row-major).+ pub matte: Option<Arc<Vec<f32>>>,+ pub preserve: bool,+ /// World → layer, and the (blurred) buffer's layer-space bounds.+ pub winv: Mat4,+ pub bounds: [f64; 4],+ /// Output pixel bounds of all geometries.+ pub bbox: [i64; 4],+ /// Stack order (coplanar fragments draw lower orders first).+ pub order: usize,+ pub layer_id: u32,+ pub mode: BlendMode,+}++/// Prepare a run of 3D layers for an accelerator. `None` when the run must be drawn on the CPU+/// (adjustment, wireframe or environment background layers, Advanced 3D).+pub(crate) fn gpu_run(r: &Renderer, ctx: &EvalCtx, run: &[&Layer], out: (u32, u32)) -> Option<Run3d> {- if run.is_empty() || run.iter().any(|l| l.switches.adjustment || l.environment_background || l.switches.quality == effectcraft_project::Quality::Wireframe)++ if run.is_empty() || run.iter().any(|l| l.switches.adjustment || l.environment_background || r.quality(l) == effectcraft_project::Quality::Wireframe)+ {+ return None;+ }+ if ctx.comp.renderer == effectcraft_project::Renderer::Advanced3D && r.collapse3d.is_none() {+ return None;+ }+ let g = gather(r, ctx, run, out);+ let planes: Vec<Plane3d> = g+ .items+ .into_iter()+ .chain(g.extra)+ .map(|it| Plane3d {+ layer_id: it.layer.id.0 as u32,+ mode: it.layer.blend_mode,+ buf: it.buf,+ bicubic: it.bicubic,+ geos: it.geos,+ mat: it.mat,+ opacity: it.opacity,+ draw: it.draw,+ matte: it.matte,+ preserve: it.preserve,+ winv: it.winv,+ bounds: it.bounds,+ bbox: it.bbox,+ order: it.order,+ })+ .collect();- let casters = planes.iter().enumerate().filter(|(_, p)| p.mat.casts_shadows != 0 && !p.geos.is_empty()).map(|(i, _)| i).collect();++ let casters = planes.iter().enumerate().filter(|(_, p)| r.opts.shadows() && p.mat.casts_shadows != 0 && !p.geos.is_empty()).map(|(i, _)| i).collect();+ Some(Run3d { planes, casters, lights: g.lights, seed: run[0].id.0 as u32 })+}+// ------------------------------------------------------------------ auxiliary render pass/// One surface seen through an output pixel (aux pass).