Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Add backdrop scenes

Bitti69be0b5d9670
diff --git a/src-tauri/src/project/scenes.rs b/src-tauri/src/project/scenes.rs
index 8bb785d..7b36d52 100644
--- a/src-tauri/src/project/scenes.rs
+++ b/src-tauri/src/project/scenes.rs
@@ -44,6 +44,8 @@ pub(crate) struct GenerationJob {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) scene_type: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) backdrop_color: Option<String>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) pose_video_reference_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) start_video_reference_id: Option<String>,
@@ -155,6 +157,7 @@ impl GenerationJob {
Self {
id: id.to_string(),
scene_type: None,
+ backdrop_color: None,
pose_video_reference_id: None,
start_video_reference_id: None,
end_video_reference_id: None,
diff --git a/src-tauri/src/project/validation/scenes.rs b/src-tauri/src/project/validation/scenes.rs
index 3fa40f6..733a822 100644
--- a/src-tauri/src/project/validation/scenes.rs
+++ b/src-tauri/src/project/validation/scenes.rs
@@ -22,11 +22,14 @@ pub(super) fn validate(config: &mut ProjectConfig) -> Result<(), String> {
if job.scene_type.as_deref().is_some_and(|value| {
!matches!(
value,
- "first-last-frame" | "continue" | "animate" | "pose" | "character-replace" | "extend" | "bridge"
+ "first-last-frame" | "continue" | "animate" | "pose" | "character-replace" | "extend" | "bridge" | "backdrop"
)
}) {
return Err(format!("Scene '{}' has an unsupported scene type.", job.id));
}
+ if job.backdrop_color.as_deref().is_some_and(|value| !matches!(value, "green" | "blue" | "black" | "white")) {
+ return Err(format!("Scene '{}' has an unsupported backdrop color.", job.id));
+ }
if [
&job.start_video_reference_id,
&job.end_video_reference_id,
diff --git a/src-tauri/src/tests/scenes.rs b/src-tauri/src/tests/scenes.rs
index 2ab948e..91eab4a 100644
--- a/src-tauri/src/tests/scenes.rs
+++ b/src-tauri/src/tests/scenes.rs
@@ -323,10 +323,12 @@ fn scene_types_and_character_replacement_inputs_survive_save_and_reopen() {
"character-replace",
"extend",
"bridge",
+ "backdrop",
] {
let mut config = scene_fixture();
let job = &mut config.generation_jobs[0];
job.scene_type = Some(scene_type.into());
+ job.backdrop_color = Some("blue".into());
job.pose_video_reference_id = Some("pose-video".into());
job.start_video_reference_id = Some("start-video".into());
job.end_video_reference_id = Some("end-video".into());
@@ -337,6 +339,7 @@ fn scene_types_and_character_replacement_inputs_survive_save_and_reopen() {
let normalized = validate_and_normalize_config(config).unwrap();
let saved = serde_json::to_string(&normalized).unwrap();
let restored: ProjectConfig = serde_json::from_str(&saved).unwrap();
+ assert_eq!(restored.generation_jobs[0].backdrop_color.as_deref(), Some("blue"));
assert_eq!(
restored.generation_jobs[0]
.pose_video_reference_id
diff --git a/src/components/workspace/SceneEditor.tsx b/src/components/workspace/SceneEditor.tsx
index bbcb7a6..8ac27d8 100644
--- a/src/components/workspace/SceneEditor.tsx
+++ b/src/components/workspace/SceneEditor.tsx
@@ -1,4 +1,5 @@
import { Audio16, Dismiss12, Image16, ImageAdd16, Text16, Video16 } from "../ui/icons";
+import { BACKDROP_OPTIONS, type BackdropColor } from "../../lib/backdrop";
import { useId, useMemo, useState, type ReactNode } from "react";
import { ComboBox, InfoBar, PropRow, PropSection, ToggleSwitch } from "../ui";
import {
@@ -263,6 +264,7 @@ function CharacterReplaceInputs({ shot, references, disabled, onChange }: {
const SCENE_TYPES: { value: SceneType; label: string }[] = [
{ value: "first-last-frame", label: "First & last frame" },
+ { value: "backdrop", label: "Backdrop" },
{ value: "continue", label: "Continue" },
{ value: "animate", label: "Animate" },
{ value: "pose", label: "Pose" },
@@ -294,6 +296,7 @@ export function SceneInspector({ job, shots, references, folderPath = "", scenes
}) {
const animate = sceneType === "animate";
const continuing = sceneType === "continue";
+ const backdrop = sceneType === "backdrop";
const pose = sceneType === "pose";
const characterReplace = sceneType === "character-replace";
const transition = isVideoTransition({ sceneType });
@@ -324,6 +327,13 @@ export function SceneInspector({ job, shots, references, folderPath = "", scenes
onChange={(value) => onChange({ sceneType: value as SceneType, usePreviousSceneLastFrame: undefined,
...(value === "animate" ? { endFrameReferenceId: undefined } : {}) })} />
</PropRow>
+ {backdrop && <>
+ <PropRow label="Backdrop color" htmlFor={`${id}-backdrop`}>
+ <ComboBox id={`${id}-backdrop`} aria-label="Scene backdrop color" value={job.backdropColor ?? "green"} disabled={disabled}
+ options={BACKDROP_OPTIONS} onChange={(value) => onChange({ backdropColor: value as BackdropColor })} />
+ </PropRow>
+ <p className="prop-caption">Generate the described action on a flat backdrop. Apply Chroma key to the resulting clip to remove it. Choose a color absent from the subject.</p>
+ </>}
{continuing && <>
<PropRow label="Source scene" htmlFor={`${id}-source-scene`} tooltip="Uses the selected scene’s saved latents. Generate it first, or use Generate all.">
<ComboBox id={`${id}-source-scene`} aria-label="Source scene for continuation" disabled={disabled}
@@ -407,7 +417,7 @@ export function SceneInspector({ job, shots, references, folderPath = "", scenes
/>
</PropRow>}
{!animate && !chosen && defaultLook && <p className="prop-caption">Using project Look: {look.options.find((option) => option.id === defaultLook)?.label ?? defaultLook}.</p>}
- {!transition && !pose && !continuing && <>
+ {!transition && !pose && !continuing && !backdrop && <>
<PropRow label={animate ? "Repainted frame" : "Start frame"} htmlFor={`${id}-start`} tooltip={animate ? "A frame of the driving video with the character repainted. Keep its pose, framing, background and lighting." : undefined}>
<ReferenceSelector
id={`${id}-start`}
@@ -429,7 +439,7 @@ export function SceneInspector({ job, shots, references, folderPath = "", scenes
{addImageButton(animate ? "Add repainted frame" : "Add start frame", onAddStartFrame)}
</PropRow>
</>}
- {!animate && !transition && !pose && !continuing && <PropRow label="Last frame" htmlFor={`${id}-end`}>
+ {!animate && !transition && !pose && !continuing && !backdrop && <PropRow label="Last frame" htmlFor={`${id}-end`}>
<ReferenceSelector id={`${id}-end`} value={job.endFrameReferenceId ?? ""} disabled={disabled} aria-label="Last frame for this scene"
references={references} accept={["image"]} folderPath={folderPath}
onChange={(value) => onChange({ endFrameReferenceId: value || undefined })} />
diff --git a/src/lib/backdrop.ts b/src/lib/backdrop.ts
new file mode 100644
index 0000000..7021249
--- /dev/null
+++ b/src/lib/backdrop.ts
@@ -0,0 +1,7 @@
+export const BACKDROP_COLORS = { green: "#00ff00", blue: "#0000ff", black: "#000000", white: "#ffffff" } as const;
+export type BackdropColor = keyof typeof BACKDROP_COLORS;
+export const BACKDROP_OPTIONS = Object.keys(BACKDROP_COLORS).map((value) => ({ value, label: value[0].toUpperCase() + value.slice(1) }));
+
+export function backdropDirection(color: BackdropColor): string {
+ return `Generate the described subject and action against a uniform, solid ${color} (${BACKDROP_COLORS[color]}) backdrop for background keying. Keep this exact backdrop color consistent across every frame and every shot, filling all space behind the subject. No scenery, floor, horizon, gradients, texture, backdrop shadows or reflections. Light the subject independently, with clear edges and no ${color} color spill. Keep the subject fully inside the frame. Reference images guide the subject's appearance only; replace their backgrounds with this solid backdrop.`;
+}
diff --git a/src/lib/project.backdrop.test.ts b/src/lib/project.backdrop.test.ts
new file mode 100644
index 0000000..5678f4a
--- /dev/null
+++ b/src/lib/project.backdrop.test.ts
@@ -0,0 +1,25 @@
+import { expect, it } from "vitest";
+import { compileGenerationJobPrompt, createDraftGenerationJob, generationJobSchema, sceneGenerationReferences, type ProjectReference } from "./project";
+import { BACKDROP_COLORS } from "./backdrop";
+
+it.each(["green", "blue", "black", "white"] as const)("compiles and preserves a %s backdrop without stale frame anchors", (backdropColor) => {
+ const job = { ...createDraftGenerationJob("A dancer spins.", { sceneType: "backdrop" }), backdropColor,
+ startFrameReferenceId: "old", endFrameReferenceId: "old", usePreviousSceneLastFrame: true };
+ const references: ProjectReference[] = [{ id: "old", name: "Old setting", kind: "text", description: "A forest", intendedUse: [],
+ images: [{ id: "image", name: "Forest", sourcePath: "C:/forest.png" }], createdAt: "2026-10-09T00:00:00Z" }];
+ expect(generationJobSchema.parse(JSON.parse(JSON.stringify(job)))).toEqual(job);
+ expect(sceneGenerationReferences(job, references)).toEqual([]);
+ const prompt = compileGenerationJobPrompt(job, references);
+ expect(prompt).toContain(`solid ${backdropColor} (${BACKDROP_COLORS[backdropColor]})`);
+ expect(prompt).toContain("A dancer spins.");
+ expect(prompt).not.toContain("<Picture");
+ expect(prompt).toBe(compileGenerationJobPrompt(job, sceneGenerationReferences(job, references)));
+});
+
+it("uses green by default and retains explicitly cited subject references", () => {
+ const job = createDraftGenerationJob("@[ref:subject] spins.", { sceneType: "backdrop" });
+ const references: ProjectReference[] = [{ id: "subject", name: "Dancer", kind: "text", description: "A red robot", intendedUse: [], createdAt: "2026-10-09T00:00:00Z" }];
+ expect(sceneGenerationReferences(job, references)).toEqual(references);
+ expect(compileGenerationJobPrompt(job, references)).toContain("solid green");
+ expect(generationJobSchema.safeParse({ ...job, backdropColor: "red" }).success).toBe(false);
+});
diff --git a/src/lib/project.ts b/src/lib/project.ts
index cef8482..90ca205 100644
--- a/src/lib/project.ts
+++ b/src/lib/project.ts
@@ -1,4 +1,5 @@
import { z } from "zod";
+import { backdropDirection, type BackdropColor } from "./backdrop";
import { createImageScene, imageSceneReferenceIds, imageSceneSchema } from "./imageScene";
import { effectEnabledSchema, effectSchemas, isEffectOn } from "./effectSettings";
import { normalizeShotTagSelection, shotTagClauses, SHOT_TAG_ID_PATTERN, type ShotTagClauses, type ShotTagSelection } from "./shot-tags";
@@ -441,7 +442,7 @@ export const SCENE_MIN_SECONDS = 0;
* length is read as — the length every shot has always been generated at. */
export const DEFAULT_SCENE_SECONDS = 6;
-export const sceneTypeSchema = z.enum(["first-last-frame", "continue", "animate", "pose", "character-replace", "extend", "bridge"]);
+export const sceneTypeSchema = z.enum(["first-last-frame", "continue", "animate", "pose", "character-replace", "extend", "bridge", "backdrop"]);
export type SceneType = z.infer<typeof sceneTypeSchema>;
export const DEFAULT_CONTINUATION_OVERLAP = 22;
export const MAX_CONTINUATION_OVERLAP = 362;
@@ -528,6 +529,7 @@ export function shotReferenceIds(shot: Pick<SceneShot, "action" | "speech">): st
export const generationJobSchema = z.object({
id: idSchema,
sceneType: sceneTypeSchema.nullish(),
+ backdropColor: z.enum(["green", "blue", "black", "white"]).nullish(),
poseVideoReferenceId: idSchema.nullish(),
startVideoReferenceId: idSchema.nullish(),
endVideoReferenceId: idSchema.nullish(),
@@ -963,6 +965,10 @@ export function audioReferenceBlocker(job: GenerationJob, bound: ProjectReferenc
* order. Frame anchors use their first image, even on a multi-image reference;
* the same anchor selected for both ends is sent only once. */
export function sceneGenerationReferences(job: GenerationJob, references: ProjectReference[]): ProjectReference[] {
+ if (job.sceneType === "backdrop") {
+ const cited = sceneShots(job).flatMap(shotReferenceIds);
+ return references.filter((reference) => cited.includes(reference.id));
+ }
if (job.sceneType === "pose") {
// Optional guidance is explicit in the prompt. Old bindings and frame
// anchors belong to other modes and must not redefine the target scene.
@@ -1084,6 +1090,7 @@ const addedStop = (text: string): PromptSegment[] => (endSentence(text) === text
* to show the same bytes for both. */
export interface ScenePrompt {
shots: readonly SceneShot[];
+ backdropColor?: BackdropColor;
poseVideoReferenceId?: string | null;
videoTransition?: "extend" | "bridge";
startFrameReferenceId?: string | null;
@@ -1226,6 +1233,9 @@ export function compileMiniMaxH3PromptSegments(
}
export function compileGenerationJobSegments(job: GenerationJob, references: ProjectReference[] = [], defaultLook?: string | null): PromptSegment[] {
+ if (job.sceneType === "backdrop") return compileScenePromptSegments({
+ shots: sceneShots(job), soundscape: job.soundscape, music: job.music, backdropColor: job.backdropColor ?? "green",
+ }, sceneGenerationReferences(job, references), defaultLook);
if (job.sceneType === "continue") return compileScenePromptSegments({
shots: sceneShots(job), soundscape: job.soundscape, music: job.music,
}, sceneGenerationReferences(job, references), defaultLook);
@@ -1466,6 +1476,7 @@ export function compileScenePromptSegments(scene: ScenePrompt, references: Proje
// T2VA — base guide §2.2 field list and order.
return [
frame("integrated_multimodal_description: "),
+ ...(scene.backdropColor ? [frame(`${backdropDirection(scene.backdropColor)} `)] : []),
...compiled.flatMap((shot) => [
frame(shot.index === 0 ? marker(shot) : ` ${marker(shot)}`),
...(shot.index === 0 ? [styleSegment, frame(", ")] : []),
@@ -1638,10 +1649,12 @@ export function compileScenePromptSegments(scene: ScenePrompt, references: Proje
...definitions,
frame("\n\nsummary:\n"),
...summary,
+ ...(scene.backdropColor ? [frame(` ${backdropDirection(scene.backdropColor)}`)] : []),
frame(`\n\nretention_analysis:\n${retention.join("\n")}`),
...(scene.videoTransition ? [frame("\n<Video 1>: partially_preserved - continue from its ending state without copying its completed action."),
...(scene.videoTransition === "bridge" ? [frame("\n<Video 2>: partially_preserved - approach its opening state with continuous motion; do not repeat the ending clip.")] : [])] : []),
frame("\n\ndetailed_description:\n"),
+ ...(scene.backdropColor ? [frame(`${backdropDirection(scene.backdropColor)}\n`)] : []),
...detailed,
frame("\n\noverall_soundscape:\n"),
soundSegment,