Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge branch 'main' into worktree-agent-a4b0610bd14276508

Brandon Thomasa4f4d72f27c5
diff --cc apps/effectcraft-cli/src/main.rs
index ca9042337,fa7311c9e..27a118de6
--- a/apps/effectcraft-cli/src/main.rs
+++ b/apps/effectcraft-cli/src/main.rs
@@@ -786,20 -816,122 +816,125 @@@ fn adjustment_bench_comp(p: &mut effect
Some(p.add_item("Adjustment Layers (bench)", effectcraft_engine::color::Label::None, None, ItemKind::Comp(comp.into())))
}
+ /// `bench --gpu`'s Advanced 3D comp (1920×1080): a ground plane, PBR primitives, extruded
+ /// bevelled text, a shadow-casting spot light, a point light and an environment light, seen
+ /// through a depth-of-field camera (hexagonal iris, highlights) with a motion-blurred sphere.
+ fn adv3d_bench_comp(p: &mut effectcraft_engine::project::Project) -> Option<ItemId> {
+ use effectcraft_engine::keyframe::{Keyframe, TextDoc, Value};
+ use effectcraft_engine::project::build::{self, Ids};
+ use effectcraft_engine::project::{Comp, ItemKind, Layer, LayerSource, LightKind, PrimitiveKind, Renderer as R3, Solid};
+ let (w, h) = (1920u32, 1080u32);
+ let mut comp = Comp::new(w, h, effectcraft_time::FrameRate::FPS_30, Tick::from_seconds_f64(10.0));
+ comp.renderer = R3::Advanced3D;
+ comp.enable_motion_blur = true;
+ comp.motion_blur_samples = 8;
+ let mut layers: Vec<Layer> = vec![];
+ let mut add = |p: &mut effectcraft_engine::project::Project, comp: &Comp, src: LayerSource, edit: &dyn Fn(&mut Layer)| {
+ let mut l = build::layer(p, comp, "L", src, (w, h), None);
+ edit(&mut l);
+ layers.insert(0, l);
+ };
+ fn set(l: &mut Layer, path: &str, v: Value) {
+ if let Some(pr) = l.props.prop_mut(path) {
+ pr.value = v;
+ }
+ }
+ add(p, &comp, LayerSource::Primitive { kind: PrimitiveKind::Plane }, &|l| {
+ set(l, "geometryOptions/width", Value::Scalar(6000.0));
+ set(l, "geometryOptions/height", Value::Scalar(6000.0));
+ set(l, "transform/position", Value::Vec3([960.0, 800.0, 0.0]));
+ set(l, "transform/rotationX", Value::Scalar(90.0));
+ });
+ for (i, kind) in [PrimitiveKind::Sphere, PrimitiveKind::Torus, PrimitiveKind::Cube, PrimitiveKind::Sphere].into_iter().enumerate() {
+ add(p, &comp, LayerSource::Primitive { kind }, &|l| {
+ let x = 400.0 + 380.0 * i as f64;
+ set(l, "geometryOptions/radius", Value::Scalar(140.0));
+ set(l, "geometryOptions/tubeRadius", Value::Scalar(45.0));
+ for k in ["width", "height", "depth"] {
+ set(l, &format!("geometryOptions/{k}"), Value::Scalar(220.0));
+ }
+ set(l, "transform/position", Value::Vec3([x, 640.0, 300.0 * i as f64 - 300.0]));
+ set(l, "transform/rotationX", Value::Scalar(35.0));
+ set(l, "transform/rotationY", Value::Scalar(25.0));
+ set(l, "materialOptions/metallic", Value::Scalar(if i % 2 == 1 { 100.0 } else { 0.0 }));
+ set(l, "materialOptions/roughness", Value::Scalar(30.0));
+ set(l, "materialOptions/castsShadows", Value::Enum(1));
+ if i == 0 {
+ l.switches.motion_blur = true;
+ if let Some(pr) = l.props.prop_mut("transform/position") {
+ pr.keys = vec![
+ Keyframe::new(Tick::ZERO, Value::Vec3([x, 640.0, -300.0])),
+ Keyframe::new(Tick::from_seconds_f64(10.0), Value::Vec3([x + 300.0 * 60.0, 640.0, -300.0])),
+ ];
+ }
+ }
+ });
+ }
+ add(p, &comp, LayerSource::Text, &|l| {
+ l.switches.three_d = true;
+ let doc = TextDoc { text: "EffectCraft".into(), size: 180.0, fill: [0.95, 0.75, 0.2, 1.0], apply_fill: true, ..Default::default() };
+ set(l, "text/sourceText", Value::Text(Box::new(doc)));
+ let mut next = 900_000u64;
+ l.props.children.push(build::extrusion_geometry_options(&mut Ids(&mut next)).into());
+ set(l, "geometryOptions/extrusionDepth", Value::Scalar(40.0));
+ set(l, "geometryOptions/bevelStyle", Value::Enum(1));
+ set(l, "transform/position", Value::Vec3([960.0, 260.0, 200.0]));
+ set(l, "transform/rotationY", Value::Scalar(-15.0));
+ });
+ let env = p.add_item(
+ "Environment (bench)",
+ effectcraft_engine::color::Label::None,
+ None,
+ ItemKind::Solid(Solid { color: [0.55, 0.65, 0.9], width: 64, height: 32, pixel_aspect: 1.0 }),
+ );
+ add(p, &comp, LayerSource::Solid { item: env }, &|l| {
+ l.environment = true;
+ l.switches.three_d = true;
+ });
+ add(p, &comp, LayerSource::Light { kind: LightKind::Environment }, &|l| set(l, "lightOptions/intensity", Value::Scalar(40.0)));
+ add(p, &comp, LayerSource::Light { kind: LightKind::Spot }, &|l| {
+ set(l, "transform/position", Value::Vec3([500.0, -600.0, -900.0]));
+ set(l, "transform/poi", Value::Vec3([960.0, 640.0, 0.0]));
+ set(l, "lightOptions/castsShadows", Value::Bool(true));
+ set(l, "lightOptions/coneAngle", Value::Scalar(100.0));
+ set(l, "lightOptions/shadowDiffusion", Value::Scalar(8.0));
+ });
+ add(p, &comp, LayerSource::Light { kind: LightKind::Point }, &|l| {
+ set(l, "transform/position", Value::Vec3([1500.0, 200.0, -500.0]));
+ set(l, "lightOptions/intensity", Value::Scalar(50.0));
+ });
+ add(p, &comp, LayerSource::Camera, &|l| {
+ let zoom = match l.props.prop_mut("cameraOptions/zoom").map(|pr| pr.value.clone()) {
+ Some(Value::Scalar(z)) => z,
+ _ => 2666.7,
+ };
+ set(l, "cameraOptions/dof", Value::Bool(true));
+ set(l, "cameraOptions/focusDistance", Value::Scalar(zoom));
+ set(l, "cameraOptions/aperture", Value::Scalar(120.0));
+ set(l, "cameraOptions/irisShape", Value::Enum(4));
+ set(l, "cameraOptions/highlightGain", Value::Scalar(20.0));
+ set(l, "cameraOptions/highlightThreshold", Value::Scalar(200.0));
+ });
+ comp.layers = layers;
+ Some(p.add_item("Advanced 3D (bench)", effectcraft_engine::color::Label::None, None, ItemKind::Comp(comp.into())))
+ }
+
/// `bench --gpu`: CPU vs GPU ms/frame for every comp (or `--comp`) at Full and Half. "cold"
/// renders everything (no layer cache); "warm" reuses the layer cache (playback / scrubbing of
-/// unchanged layers: compositing cost); "viewer" is the GPU display path without readback.
+/// unchanged layers: compositing cost); "viewer" is the GPU display path without readback;
+/// "auto" is Backend::Auto (Mercury GPU Acceleration) choosing per comp from measured times,
+/// warm; "up/dn MB" are the GPU's uploads / readbacks per warm GPU frame.
fn bench_gpu(s: &Session, args: &Args) -> Result<(), Failure> {
use effectcraft_render::Backend;
let gpu = effectcraft_gpu::Gpu::headless().ok_or_else(|| Failure::Error("--gpu: no usable GPU adapter".into()))?;
let n = args.num("--n")?.unwrap_or(10.0).max(1.0) as usize;
// Every comp, plus an adjustment-layer comp built for the benchmark (the main comp under a
- // full-frame adjustment layer with a GPU effect stack).
+ // full-frame adjustment layer with a GPU effect stack) and an Advanced 3D comp (`--adv3d`:
+ // that one only).
let mut project = (*s.project).clone();
+ project.settings.gpu_acceleration = true;
let comps: Vec<ItemId> = match args.opt("--comp") {
+ _ if args.flag("--adv3d") => adv3d_bench_comp(&mut project).into_iter().collect(),
Some(_) => s.active_comp_id().into_iter().collect(),
None => {
let mut v: Vec<ItemId> = s.project.comps().map(|(id, _)| *id).collect();
diff --cc crates/effects/src/lib.rs
index 3486454d5,8432a88d4..feed53bf6
--- a/crates/effects/src/lib.rs
+++ b/crates/effects/src/lib.rs
@@@ -71,9 -72,9 +72,10 @@@ pub use color_fx::
levels_channel_ids, levels_channel_settings, levels_channels_identity, levels_clip,
};
pub use color2::{Curve, auto_correct_settings, equalize_tables, luma_clip_points, shadow_highlight_amounts};
+ pub use color3::OffsetCurve;
pub use distort::transform_shutter;
-pub use distort2::{MAGNIFY_MODES, parse_mesh};
+pub use distort2::{MAGNIFY_MODES, bezier_grid, parse_mesh};
+pub use distort3::{RESHAPE_POINTS, ReshapeSetup, SmearSetup, reshape_setup, smear_setup};
pub use distort4::liquify_mesh;
use effectcraft_keyframe::Value;
use effectcraft_project::build::Ids;
diff --cc crates/gpu/src/context.rs
index 1de302ce0,677e76da7..3d8d29164
--- a/crates/gpu/src/context.rs
+++ b/crates/gpu/src/context.rs
@@@ -624,52 -405,14 +624,52 @@@ impl<'g> Enc<'g>
Enc { g, enc: None, pending: 0 }
}
- fn encoder(&mut self) -> &mut wgpu::CommandEncoder {
+ pub(crate) fn encoder(&mut self) -> &mut wgpu::CommandEncoder {
let g = self.g;
- self.enc.get_or_insert_with(|| g.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("effectcraft") }))
+ &mut self
+ .enc
+ .get_or_insert_with(|| {
+ let id = g.pool.lock().map(|mut p| p.open()).unwrap_or(0);
+ (g.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("effectcraft") }), id)
+ })
+ .0
}
- /// A new zeroed image.
- pub fn image(&self, w: u32, h: u32) -> GpuImage {
- self.g.image(w, h)
+ /// A new zeroed image (pooled; a reused texture is cleared by a kernel).
+ pub fn image(&mut self, w: u32, h: u32) -> GpuImage {
+ let (img, reused) = self.g.pooled(w, h);
+ if reused {
+ self.fill(&img, 0.0);
+ }
+ img
+ }
+
+ /// A new image for a kernel that writes every pixel of it (pooled; contents undefined).
+ /// Under test it starts out as NaNs, so a kernel that skips pixels fails the CPU oracle.
+ pub fn scratch(&mut self, w: u32, h: u32) -> GpuImage {
+ let (img, _) = self.g.pooled(w, h);
+ if cfg!(test) {
+ self.fill(&img, f32::NAN);
+ }
+ img
+ }
+
+ /// A transparent image to read from (shared per size; never written).
+ pub fn zeros(&self, w: u32, h: u32) -> GpuImage {
+ let (w, h) = (w.max(1), h.max(1));
+ let Ok(mut z) = self.g.zeros.lock() else { return self.g.image(w, h) };
+ if z.len() > 8 && !z.contains_key(&(w, h)) {
+ z.clear();
+ }
+ z.entry((w, h)).or_insert_with(|| self.g.image(w, h)).clone()
+ }
+
+ /// Set every pixel of `img` to `v`.
+ fn fill(&mut self, img: &GpuImage, v: f32) {
+ let mut p = Params::default();
+ p.f[0] = [v; 4];
+ let dummy = GpuImage::new(self.g.dummy.clone(), 1, 1);
+ self.pixels("fill", &p, &dummy, None, img, None);
}
/// Run kernel `entry` writing `out` (dispatched over `groups` workgroups).