EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge main into M13.6
Brandon Thomas404b855986be
diff --cc Cargo.lockindex 0c2e845f5,c3dcb41c6..76a8b1ff5--- a/Cargo.lock+++ b/Cargo.lock@@@ -1405,16 -1409,23 +1409,28 @@@ dependencies =name = "effectcraft-pdf"version = "0.1.0"dependencies = [+ "effectcraft-raster","effectcraft-svg",+ "effectcraft-text",+ "image","kurbo","miniz_oxide 0.8.9",+ "skrifa",+ "zune-jpeg",]+ [[package]]+ name = "effectcraft-plugin"+ version = "0.1.0"+ dependencies = [+ "effectcraft-effects",+ "effectcraft-keyframe",+ "effectcraft-project",+ "effectcraft-raster",+ "serde_json",+ "wasmi",+ ]+[[package]]name = "effectcraft-project"version = "0.1.0"diff --cc crates/gpu/src/tests_3d.rsindex e28ce3bf6,f10368d20..bd9455b9e--- a/crates/gpu/src/tests_3d.rs+++ b/crates/gpu/src/tests_3d.rs@@@ -218,69 -218,3 +218,73 @@@ fn the_gpu_draws_classic_3d_runs_itselflet d = crate::tests::diff(&cpu, &img, 1e-3);assert!(d.over * 200 <= d.total, "{d:?}");}++/// Classic 3D bokeh depth of field runs on the GPU: iris shapes, highlights, fringe, Fast+/// Rectangle and a tilted plane (progressive blur) match the CPU.+#[test]+fn bokeh_depth_of_field_runs_on_the_gpu() {+ let cases: [(&str, &[(&str, Value)]); 4] = [+ ("fast rectangle", &[]),+ ("hexagon + highlights", &[("irisShape", Value::Enum(4)), ("irisRotation", n(15.0)), ("highlightGain", n(40.0)), ("highlightThreshold", n(150.0))]),+ ("round + fringe", &[("irisShape", Value::Enum(6)), ("irisRoundness", n(60.0)), ("irisDiffractionFringe", n(80.0))]),+ ("wide triangle", &[("irisShape", Value::Enum(1)), ("irisAspectRatio", n(2.0))]),+ ];+ for depth in [BitDepth::Bpc8, BitDepth::Bpc32] {+ for (label, vals) in cases {+ // The crossing planes are tilted (±35°): every plane blurs progressively.+ let mut s = crossing(depth, BlendMode::Normal);+ camera(&mut s, [80.0, 50.0, -220.0], Some((180.0, 40.0)));+ for l in &mut s.p.comp_mut(s.cid).unwrap().layers {+ if l.name == "Camera" {+ for (k, v) in vals {+ set(l, &format!("cameraOptions/{k}"), v.clone());+ }+ }+ }+ check(&format!("bokeh {label} {depth:?}"), compare_at(&s, opts(), Tick::ZERO), 0.005);+ // The blur is the GPU's: the prepared planes carry it unapplied.+ if depth == BitDepth::Bpc32+ && let Some(g) = gpu()+ {+ let r = Renderer::new(&s.p, &Pattern, RenderOpts { backend: Backend::Gpu, ..opts() });+ let ctx = r.eval_ctx(s.cid, Tick::ZERO).unwrap();+ let run: Vec<_> = r.visible_layers(&ctx).into_iter().filter(|l| l.is_3d()).collect();+ let prep = r.prepare_3d_run(&ctx, &run, (W, H)).unwrap();+ assert!(prep.planes.iter().filter(|p| p.draw).all(|p| p.dof.is_some()), "{label}: depth of field deferred to the GPU");+ let mut e = crate::context::Enc::new(g.context());+ let canvas = e.image(W, H);+ assert!(crate::classic3d::draw_run(&mut e, &prep, &canvas).is_some(), "{label}: drawn on the GPU");+ }+ }+ }+}++/// A 2D layer whose track matte is a 3D layer: the matte is drawn through the camera on the+/// GPU walk as on the CPU.+#[test]+fn two_d_layer_with_a_three_d_track_matte() {+ for depth in [BitDepth::Bpc8, BitDepth::Bpc32] {+ for kind in [MatteKind::Alpha, MatteKind::Luma] {+ let mut s = scene(depth);+ let bg = s.solid([0.1, 0.12, 0.2], W, H);+ s.push(bg);+ let fill = s.footage(W, H);+ let fid = s.push(fill);+ // The matte: a solid turned in 3D, seen through a camera.+ let m = three_d(s.solid([0.9, 0.9, 0.9], 70, 50), [80.0, 50.0, 30.0], 40.0);+ let mid = s.push(m);+ camera(&mut s, [40.0, 30.0, -200.0], None);+ let layers = &mut s.p.comp_mut(s.cid).unwrap().layers;+ let fi = layers.iter().position(|l| l.id == fid).unwrap();+ layers[fi].track_matte = Some(TrackMatte { layer: mid, kind });+ if let Some(ml) = layers.iter_mut().find(|l| l.id == mid) {+ ml.switches.video = false;+ }+ check(&format!("3d matte {kind:?} {depth:?}"), compare_at(&s, opts(), Tick::ZERO), 0.005);++ // The same with the Advanced 3D renderer (its CPU path draws 3D mattes through the++ // camera with composite_iso_with).++ s.p.comp_mut(s.cid).unwrap().renderer = effectcraft_project::Renderer::Advanced3D;++ check(&format!("3d matte {kind:?} {depth:?} (Advanced 3D)"), compare_at(&s, opts(), Tick::ZERO), 0.005);+ }+ }+}diff --cc crates/render/src/lib.rsindex d590eaf97,6204b763c..003071e1d--- a/crates/render/src/lib.rs+++ b/crates/render/src/lib.rs@@@ -363,8 -395,9 +395,11 @@@ pub struct Renderer<'a>/// Switches inherited from the precomp layers this comp is rendered through (see/// [`RenderOpts::nested_switches`]): the worst quality and whether motion blur is allowed.pub(crate) inherited: Option<(Quality, bool)>,+ /// Classic 3D depth of field is left to an accelerator ([`three_d::Plane3d::dof`]).+ pub(crate) defer_dof: bool,+ /// This renderer draws into the top-level frame's canvas (the top comp, or a collapsed+ /// precomp drawn straight into it): the region of interest's offset applies.+ top: bool,}/// How a collapsed precomp's 3D layers are placed in the parent (see `Renderer::collapse_into`).@@@ -409,7 -442,7 +444,8 @@@ impl<'a> Renderer<'a>opacity_mul: 1.0,collapse3d: None,inherited: None,+ defer_dof: false,+ top: true,}}@@@ -444,7 -477,7 +480,7 @@@/// A renderer for nested work (precomps, layers read by effects): one level deeper.fn nested(&self) -> Renderer<'a> {- Renderer { depth: self.depth + 1, outer: None, opacity_mul: 1.0, collapse3d: None, defer_dof: false, ..*self }- Renderer { depth: self.depth + 1, outer: None, opacity_mul: 1.0, collapse3d: None, top: false, ..*self }++ Renderer { depth: self.depth + 1, outer: None, opacity_mul: 1.0, collapse3d: None, defer_dof: false, top: false, ..*self }}/// The nested comp of a precomp layer whose transformations collapse into this comp: thediff --cc crates/render/src/three_d/compose.rsindex dd28816ed,1f5470b36..c6c04299d--- a/crates/render/src/three_d/compose.rs+++ b/crates/render/src/three_d/compose.rs@@@ -231,23 -218,13 +233,23 @@@ fn prepare_with<'a>let world = outer * ctx.world_matrix(layer) * local;// Depth of field: a bokeh blur by each buffer pixel's circle of confusion (constant for a// layer facing the camera, progressive for a tilted one).+ let mut plane_dof = None;+ let mut bounds = buf_bounds(&buf);if let Some(dof) = cam.dof.filter(|_| !ctx.comp.draft_3d && !r.opts.draft) {- buf = dof_blur(&cam, &dof, world, buf);+ if r.defer_dof {+ // An accelerator blurs: hand it the radius map of the padded buffer.+ if let Some((pd, padded_bounds)) = dof_plan(&cam, &dof, world, &buf) {+ plane_dof = Some(pd);+ bounds = padded_bounds;+ }+ } else {+ buf = dof_blur(&cam, &dof, world, buf);+ bounds = buf_bounds(&buf);+ }}- let bounds = buf_bounds(&buf);let n = if in_run { mb_samples(r, ctx, layer) } else { 1 };let geos: Vec<Geo> = if n <= 1 {- geo(&cam, world, bounds, comp, s, out).into_iter().collect()+ geo(&cam, world, bounds, comp, s, out, r.out_offset()).into_iter().collect()} else {let fd = ctx.comp.frame_duration().seconds();let angle = ctx.comp.shutter_angle / 360.0;diff --cc crates/ui-egui/src/panels/forms.rsindex 8e03609c7,8d2df3474..2bbe2f437--- a/crates/ui-egui/src/panels/forms.rs+++ b/crates/ui-egui/src/panels/forms.rs@@@ -146,14 -136,19 +146,27 @@@ pub fn open_form(app: &mut EffectcraftA1,)],),+ // PDF / Illustrator files: Import Kind and the page.+ "file.import" if !has(p, &["importAs", "page"]) && is_pdf(p) => (+ "Import PDF / Illustrator File".into(),+ vec![+ Field::choice("importAs", "Import Kind", &[("Footage", json!("footage")), ("Composition", json!("composition"))], 0),+ Field::num("page", "Page", 1.0),+ ],+ ),+ // Puppet tool ▸ Record Options.+ "puppet.recordOptions" if !has(p, &["speed", "smoothing", "useDraftDeformation", "showMesh"]) => {+ let o = &s.state.puppet;+ (+ "Puppet Record Options".into(),+ vec![+ Field::num("speed", "Speed (%)", o.record_speed),+ Field::num("smoothing", "Smoothing", o.record_smoothing),+ Field::bool("useDraftDeformation", "Use Draft Deformation", o.record_draft),+ Field::bool("showMesh", "Show Mesh", o.record_show_mesh),+ ],+ )+ }"layer.setTransform" if !has(p, &["value"]) => {let prop = p.get("prop").and_then(Value::as_str).unwrap_or("position");let cur = layer.and_then(|l| l.transform()).and_then(|tr| tr.get(if prop == "anchorPoint" { "anchor" } else { prop })).map(|pr| pr.value_at(lt));