Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

feat(background): animate image wallpapers with the same three motions

EtienneLescotf0b06f17bd8f
diff --git a/crates/compositor/src/compositor_linux.rs b/crates/compositor/src/compositor_linux.rs
index 593de6628..6c20a3910 100644
--- a/crates/compositor/src/compositor_linux.rs
+++ b/crates/compositor/src/compositor_linux.rs
@@ -47,7 +47,7 @@ use crate::frame_geometry::{
tilted_screen_cb, CursorPlacement, CursorPlanInput, FrameGeometryInput, ShadowCaster,
SpriteShape,
};
-use crate::scene::{Scene, SceneBackground};
+use crate::scene::{Scene, SceneBackground, WallpaperMotion};
const LAYER_WGSL: &str = include_str!("vk_shaders/layer.wgsl");
const BLUR_WGSL: &str = include_str!("vk_shaders/blur.wgsl");
@@ -1472,6 +1472,10 @@ impl Compositor {
///
/// Err plutot qu'un repli maison : chaque appelant a son propre message et
/// son propre repli, et un echec silencieux redonnerait le noir qu'on corrige.
+ ///
+ /// `motion` anime l'image au temps programme `programme_t` ; la bulle webcam
+ /// passe `WallpaperMotion::None`.
+ #[allow(clippy::too_many_arguments)]
fn image_bg_draw(
&self,
path: &str,
@@ -1479,6 +1483,8 @@ impl Compositor {
quad_px: [f32; 2],
radius_px: f32,
aspect: f32,
+ motion: WallpaperMotion,
+ programme_t: f32,
dummy: &wgpu::TextureView,
) -> Result<BgDraw> {
let (tex, iw, ih) = self.cached_image(path)?;
@@ -1491,12 +1497,15 @@ impl Compositor {
let vis = ai / aspect;
[0.0, (1.0 - vis) * 0.5, 1.0, 1.0 - (1.0 - vis) * 0.5]
};
+ let (anim, mb) = crate::frame_geometry::wallpaper_motion_slots(motion, programme_t, aspect);
let cb = LayerCB {
dst,
src,
quad_px,
radius_px,
mode: 6.0,
+ fx: [0.0, 0.0, anim[0], anim[1]],
+ mb,
..Default::default()
};
let view = tex.create_view(&wgpu::TextureViewDescriptor::default());
@@ -1556,11 +1565,12 @@ impl Compositor {
..crate::frame_geometry::gradient_layer(stops, offsets, BLACK)
})
}
- Some(SceneBackground::Image { path }) => {
+ Some(SceneBackground::Image { path, .. }) => {
// Le cover-fit se mesure sur la BULLE, pas sur la sortie : c'est
// elle que l'image doit remplir sans etirement.
let aspect = if quad_px[1] > 0.0 { quad_px[0] / quad_px[1] } else { 1.0 };
- match self.image_bg_draw(path, dst, quad_px, radius_px, aspect, dummy) {
+ let still = WallpaperMotion::None;
+ match self.image_bg_draw(path, dst, quad_px, radius_px, aspect, still, 0.0, dummy) {
Ok(d) => d,
Err(e) => {
// Meme contrat que le fond d'ecran : un chemin casse est
@@ -2087,7 +2097,7 @@ impl Compositor {
// cfg.bg_blur) floute ensuite ce fond, avant l'ecran.
enum BgLayer {
Gradient(LayerCB),
- Image(String),
+ Image(String, WallpaperMotion),
}
let (bg_clear, bg_layer) = match scene_ref.as_ref().map(|s| s.background.clone()) {
Some(SceneBackground::Color { color }) => {
@@ -2096,7 +2106,7 @@ impl Compositor {
Some(SceneBackground::Gradient { angle_deg, stops, offsets, motion }) => {
let a = angle_deg.to_radians();
let (anim, mb) =
- crate::frame_geometry::gradient_motion_slots(motion, g.programme_t, rw / rh);
+ crate::frame_geometry::wallpaper_motion_slots(motion, g.programme_t, rw / rh);
let cb = LayerCB {
dst: [0.0, 0.0, 1.0, 1.0],
quad_px: [rw, rh],
@@ -2106,8 +2116,8 @@ impl Compositor {
};
([0.0, 0.0, 0.0, 1.0], Some(BgLayer::Gradient(cb)))
}
- Some(SceneBackground::Image { path }) => {
- ([0.0, 0.0, 0.0, 1.0], Some(BgLayer::Image(path)))
+ Some(SceneBackground::Image { path, motion }) => {
+ ([0.0, 0.0, 0.0, 1.0], Some(BgLayer::Image(path, motion)))
}
None => (lp.bg_color, None),
};
@@ -2277,10 +2287,10 @@ impl Compositor {
}
// Le wallpaper couvre tout le cadre, donc dst plein et pas de coins :
// `image_bg_draw` sert aussi la bulle webcam, qui elle en a.
- BgLayer::Image(path) => {
- match self
- .image_bg_draw(&path, [0.0, 0.0, 1.0, 1.0], [0.0, 0.0], 0.0, rw / rh, &dummy)
- {
+ BgLayer::Image(path, motion) => {
+ let full = [0.0, 0.0, 1.0, 1.0];
+ let t = g.programme_t;
+ match self.image_bg_draw(&path, full, [0.0, 0.0], 0.0, rw / rh, motion, t, &dummy) {
Ok(d) => Some(d),
Err(e) => {
eprintln!("[fond image] \"{path}\" : {e:#}");
diff --git a/crates/compositor/src/compositor_macos.rs b/crates/compositor/src/compositor_macos.rs
index 59e871154..c6b1c240c 100644
--- a/crates/compositor/src/compositor_macos.rs
+++ b/crates/compositor/src/compositor_macos.rs
@@ -37,7 +37,7 @@ pub use crate::frame_geometry::{
use crate::frame_geometry::{parse_hex, FrameGeometryInput, ShadowCaster,
SCREEN_SHADOW_SPREAD_FRAC, WEBCAM_SHADOW_OFFSET_FRAC, WEBCAM_SHADOW_OPACITY,
WEBCAM_SHADOW_SPREAD_FRAC};
-use crate::scene::{Scene, SceneBackground};
+use crate::scene::{Scene, SceneBackground, WallpaperMotion};
use anyhow::{anyhow, Result};
use metal::foreign_types::ForeignType;
use std::cell::RefCell;
@@ -1083,13 +1083,17 @@ impl Compositor {
enc: &metal::RenderCommandEncoderRef,
path: &str,
output_aspect: f32,
+ motion: WallpaperMotion,
+ programme_t: f32,
) -> Result<()> {
- self.draw_image_in(enc, path, [0.0, 0.0, 1.0, 1.0], [0.0, 0.0], 0.0, output_aspect)
+ let full = [0.0, 0.0, 1.0, 1.0];
+ self.draw_image_in(enc, path, full, [0.0, 0.0], 0.0, output_aspect, motion, programme_t)
}
/// `draw_image_bg` pour un rect quelconque — la bulle webcam s'en sert avec ses coins
/// arrondis. `output_aspect` est le ratio du RECT visé, pas celui de la sortie : le crop
- /// « cover » se calcule contre la zone qu'on remplit.
+ /// « cover » se calcule contre la zone qu'on remplit. `motion` anime l'image au temps
+ /// programme `programme_t` ; la bulle passe `WallpaperMotion::None`.
#[allow(clippy::too_many_arguments)]
unsafe fn draw_image_in(
&self,
@@ -1099,6 +1103,8 @@ impl Compositor {
quad_px: [f32; 2],
radius_px: f32,
output_aspect: f32,
+ motion: WallpaperMotion,
+ programme_t: f32,
) -> Result<()> {
let (tex, iw, ih) = self.cached_image(path)?;
let ai = iw as f32 / ih.max(1) as f32;
@@ -1110,6 +1116,7 @@ impl Compositor {
let vis = ai / ao; // rogne verticalement
(0.0, (1.0 - vis) * 0.5, 1.0, 1.0 - (1.0 - vis) * 0.5)
};
+ let (anim, mb) = crate::frame_geometry::wallpaper_motion_slots(motion, programme_t, ao);
enc.set_fragment_texture(2, Some(&tex));
self.draw_solid(
enc,
@@ -1119,6 +1126,8 @@ impl Compositor {
quad_px,
radius_px,
mode: 6.0,
+ fx: [0.0, 0.0, anim[0], anim[1]],
+ mb,
..Default::default()
},
);
@@ -1173,11 +1182,14 @@ impl Compositor {
},
);
}
- Some(SceneBackground::Image { path }) => {
+ Some(SceneBackground::Image { path, .. }) => {
// Même contrat que le fond d'écran : un chemin cassé est loggé puis remplacé par
// du noir. Un fallback silencieux redonnerait le bug qu'on corrige.
let aspect = if quad_px[1] > 0.0 { quad_px[0] / quad_px[1] } else { 1.0 };
- if let Err(e) = self.draw_image_in(enc, path, dst, quad_px, radius_px, aspect) {
+ let still = WallpaperMotion::None;
+ if let Err(e) =
+ self.draw_image_in(enc, path, dst, quad_px, radius_px, aspect, still, 0.0)
+ {
eprintln!("[compositor] fond webcam \"{path}\" : {e:#}");
self.draw_solid(enc, &solid(BLACK));
}
@@ -2222,7 +2234,7 @@ impl Compositor {
Some(SceneBackground::Gradient { angle_deg, stops, offsets, motion }) => {
let a = angle_deg.to_radians();
let (anim, mb) =
- crate::frame_geometry::gradient_motion_slots(motion, g.programme_t, rw / rh);
+ crate::frame_geometry::wallpaper_motion_slots(motion, g.programme_t, rw / rh);
self.draw_solid(
enc,
&LayerCB {
@@ -2233,10 +2245,10 @@ impl Compositor {
},
);
}
- Some(SceneBackground::Image { path }) => {
+ Some(SceneBackground::Image { path, motion }) => {
// Repli couleur en cas d'échec, mais LOGGÉ : un fallback silencieux masquerait
// un chemin cassé.
- if let Err(e) = self.draw_image_bg(enc, &path, rw / rh) {
+ if let Err(e) = self.draw_image_bg(enc, &path, rw / rh, motion, g.programme_t) {
eprintln!("[compositor] wallpaper image \"{path}\" : {e:#}");
self.draw_solid(
enc,
diff --git a/crates/compositor/src/compositor_windows.rs b/crates/compositor/src/compositor_windows.rs
index 77b2713dc..c86c45b72 100644
--- a/crates/compositor/src/compositor_windows.rs
+++ b/crates/compositor/src/compositor_windows.rs
@@ -16,7 +16,7 @@ use crate::frame_geometry::{
WEBCAM_SHADOW_OPACITY, WEBCAM_SHADOW_SPREAD_FRAC,
};
use crate::cursor::CursorTrack;
-use crate::scene::{Scene, SceneBackground, SceneCrop, SceneCursorSprite};
+use crate::scene::{Scene, SceneBackground, SceneCrop, SceneCursorSprite, WallpaperMotion};
use crate::d3d::Gpu;
use crate::ffi::AVFrame;
use anyhow::{bail, Result};
@@ -1085,13 +1085,22 @@ impl Compositor {
Ok((srv, w, h))
}
- unsafe fn draw_image_bg(&self, path: &str, output_aspect: f32) -> Result<()> {
- self.draw_image_in(path, [0.0, 0.0, 1.0, 1.0], [0.0, 0.0], 0.0, output_aspect)
+ unsafe fn draw_image_bg(
+ &self,
+ path: &str,
+ output_aspect: f32,
+ motion: WallpaperMotion,
+ programme_t: f32,
+ ) -> Result<()> {
+ let full = [0.0, 0.0, 1.0, 1.0];
+ self.draw_image_in(path, full, [0.0, 0.0], 0.0, output_aspect, motion, programme_t)
}
/// `draw_image_bg` pour un rect quelconque — la bulle webcam s'en sert avec ses coins
/// arrondis. `output_aspect` est le ratio du RECT visé, pas celui de la sortie : le crop
- /// « cover » se calcule contre la zone qu'on remplit.
+ /// « cover » se calcule contre la zone qu'on remplit. `motion` anime l'image au temps
+ /// programme `programme_t` ; la bulle passe `WallpaperMotion::None`.
+ #[allow(clippy::too_many_arguments)]
unsafe fn draw_image_in(
&self,
path: &str,
@@ -1099,6 +1108,8 @@ impl Compositor {
quad_px: [f32; 2],
radius_px: f32,
output_aspect: f32,
+ motion: WallpaperMotion,
+ programme_t: f32,
) -> Result<()> {
let (srv, iw, ih) = self.cached_image(path)?;
let ai = iw as f32 / ih as f32;
@@ -1116,12 +1127,15 @@ impl Compositor {
let vis = ai / ao; // rogne verticalement
(0.0, (1.0 - vis) * 0.5, 1.0, 1.0 - (1.0 - vis) * 0.5)
};
+ let (anim, mb) = crate::frame_geometry::wallpaper_motion_slots(motion, programme_t, ao);
self.upload_cb(&LayerCB {
dst,
src: [u0, v0, u1, v1],
quad_px,
radius_px,
mode: 6.0,
+ fx: [0.0, 0.0, anim[0], anim[1]],
+ mb,
..Default::default()
});
self.ctx.PSSetShaderResources(2, Some(&[Some(srv)]));
@@ -1174,11 +1188,14 @@ impl Compositor {
..crate::frame_geometry::gradient_layer(stops, offsets, BLACK)
});
}
- Some(SceneBackground::Image { path }) => {
+ Some(SceneBackground::Image { path, .. }) => {
// Même contrat que le fond d'écran : un chemin cassé est loggé puis remplacé par
// du noir. Un fallback silencieux redonnerait le bug qu'on corrige.
let aspect = if quad_px[1] > 0.0 { quad_px[0] / quad_px[1] } else { 1.0 };
- if let Err(e) = self.draw_image_in(path, dst, quad_px, radius_px, aspect) {
+ let still = WallpaperMotion::None;
+ if let Err(e) =
+ self.draw_image_in(path, dst, quad_px, radius_px, aspect, still, 0.0)
+ {
eprintln!("[compositor] fond webcam \"{}\" : {:#}", path, e);
self.draw_solid(&solid(BLACK));
}
@@ -1923,7 +1940,7 @@ impl Compositor {
// 0° = vers le haut, 90° = vers la droite.
let a = angle_deg.to_radians();
let dir = [a.sin(), -a.cos()];
- let (anim, mb) = crate::frame_geometry::gradient_motion_slots(
+ let (anim, mb) = crate::frame_geometry::wallpaper_motion_slots(
motion,
g.programme_t,
self.rw() / self.rh(),
@@ -1935,11 +1952,12 @@ impl Compositor {
..crate::frame_geometry::gradient_layer(&stops, &offsets, lp.bg_color)
});
}
- SceneBackground::Image { path } => {
+ SceneBackground::Image { path, motion } => {
// image bg (cover-fit, mise en cache) ; fallback couleur si chargement échoue
// (loggé — un fallback silencieux masquerait un chemin cassé, cf. le panic
// borrow qu'on a déjà eu : toute panne doit être visible/traçable).
- if let Err(e) = self.draw_image_bg(&path, self.rw() / self.rh()) {
+ let aspect = self.rw() / self.rh();
+ if let Err(e) = self.draw_image_bg(&path, aspect, motion, g.programme_t) {
eprintln!("[compositor] wallpaper image \"{}\" : {:#}", path, e);
self.draw_solid(&LayerCB {
dst: [0.0, 0.0, 1.0, 1.0],
diff --git a/crates/compositor/src/frame_geometry.rs b/crates/compositor/src/frame_geometry.rs
index a79c5f527..59d5ae31f 100644
--- a/crates/compositor/src/frame_geometry.rs
+++ b/crates/compositor/src/frame_geometry.rs
@@ -1568,21 +1568,22 @@ fn same_source_path(a: &str, b: &str) -> bool {
/// Période commune des mouvements de fond (s). Chaque période du shader (6, 10, 12, 15, 20,
/// 30 s) la divise, donc replier le temps dessus ne crée aucun raccord visible — et garde au
/// shader un temps borné, là où un `f32` de plusieurs heures perdrait la finesse du bruit.
-pub const GRADIENT_MOTION_PERIOD_S: f32 = 120.0;
+pub const WALLPAPER_MOTION_PERIOD_S: f32 = 120.0;
-/// Emplacements libres du mode 5 pour le fond animé : `fx.zw` = (temps programme replié, indice
-/// du mouvement), `mb.x` = aspect w/h de la sortie (les nappes de l'aurore restent rondes).
+/// Emplacements libres des modes 5 (dégradé) et 6 (image) pour le fond animé : `fx.zw` = (temps
+/// programme replié, indice du mouvement), `mb.x` = aspect w/h du rect rempli (les nappes de
+/// l'aurore restent rondes).
///
-/// `GradientMotion::None` rend les zéros d'avant l'animation, emplacement pour emplacement : le
-/// dégradé immobile reste celui d'aujourd'hui, octet pour octet. Fonction pure du temps
+/// `WallpaperMotion::None` rend les zéros d'avant l'animation, emplacement pour emplacement : le
+/// fond immobile reste celui d'aujourd'hui, octet pour octet. Fonction pure du temps
/// programme, jamais d'un état porté de frame en frame — preview et export, lecture et seek
/// tombent sur la même image.
-pub fn gradient_motion_slots(
- motion: crate::scene::GradientMotion,
+pub fn wallpaper_motion_slots(
+ motion: crate::scene::WallpaperMotion,
programme_t: f32,
aspect: f32,
) -> ([f32; 2], [f32; 4]) {
- use crate::scene::GradientMotion as M;
+ use crate::scene::WallpaperMotion as M;
let index = match motion {
M::None => return ([0.0, 0.0], [0.0; 4]),
M::Drift => 1.0,
@@ -1590,7 +1591,7 @@ pub fn gradient_motion_slots(
M::Waves => 3.0,
};
(
- [programme_t.rem_euclid(GRADIENT_MOTION_PERIOD_S), index],
+ [programme_t.rem_euclid(WALLPAPER_MOTION_PERIOD_S), index],
[aspect, 0.0, 0.0, 0.0],
)
}
@@ -6795,17 +6796,17 @@ mod tests {
/// Sans mouvement, les emplacements restent les zéros d'avant (dégradé inchangé) ; avec,
/// le temps est replié sur la période commune et l'indice suit l'ordre du shader.
#[test]
- fn gradient_motion_slots_are_zero_when_still_and_wrap_the_clock() {
- use crate::scene::GradientMotion as M;
- assert_eq!(gradient_motion_slots(M::None, 37.5, 16.0 / 9.0), ([0.0, 0.0], [0.0; 4]));
- let (fx, mb) = gradient_motion_slots(M::Drift, 125.0, 2.0);
+ fn wallpaper_motion_slots_are_zero_when_still_and_wrap_the_clock() {
+ use crate::scene::WallpaperMotion as M;
+ assert_eq!(wallpaper_motion_slots(M::None, 37.5, 16.0 / 9.0), ([0.0, 0.0], [0.0; 4]));
+ let (fx, mb) = wallpaper_motion_slots(M::Drift, 125.0, 2.0);
assert_eq!(fx, [5.0, 1.0]);
assert_eq!(mb, [2.0, 0.0, 0.0, 0.0]);
- assert_eq!(gradient_motion_slots(M::Aurora, 0.0, 1.0).0[1], 2.0);
- assert_eq!(gradient_motion_slots(M::Waves, 240.0, 1.0).0, [0.0, 3.0]);
+ assert_eq!(wallpaper_motion_slots(M::Aurora, 0.0, 1.0).0[1], 2.0);
+ assert_eq!(wallpaper_motion_slots(M::Waves, 240.0, 1.0).0, [0.0, 3.0]);
// Chaque période du shader divise la période de repli : pas de raccord au bouclage.
for p in [6.0, 10.0, 12.0, 15.0, 20.0, 30.0] {
- assert_eq!(GRADIENT_MOTION_PERIOD_S % p, 0.0, "période {p}");
+ assert_eq!(WALLPAPER_MOTION_PERIOD_S % p, 0.0, "période {p}");
}
}
diff --git a/crates/compositor/src/scene.rs b/crates/compositor/src/scene.rs
index 1b7ee7cc7..1130b0250 100644
--- a/crates/compositor/src/scene.rs
+++ b/crates/compositor/src/scene.rs
@@ -290,18 +290,24 @@ pub enum SceneBackground {
/// Absent pour un fond immobile : l'app n'émet la clé que si un mouvement est choisi,
/// donc la scène d'un projet sans animation ne bouge pas d'un octet.
#[serde(default)]
- motion: GradientMotion,
+ motion: WallpaperMotion,
+ },
+ Image {
+ path: String,
+ /// Comme pour le dégradé : absent pour un fond immobile.
+ #[serde(default)]
+ motion: WallpaperMotion,
},
- Image { path: String },
}
-/// Mouvement lent d'un fond dégradé (`settings.wallpaperMotion`), lu par le mode 5 dans `fx.w`.
+/// Mouvement du fond d'écran (`settings.wallpaperMotion`), lu dans `fx.w` par le mode 5 (dégradé)
+/// et le mode 6 (image). Une couleur unie n'en porte pas : rien n'y bougerait.
///
/// Une valeur inconnue (projet ouvert par une version plus ancienne que celle qui l'a écrit)
/// retombe sur `None` au lieu de faire échouer le parse de toute la scène.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "lowercase")]
-pub enum GradientMotion {
+pub enum WallpaperMotion {
Drift,
Aurora,
Waves,
@@ -819,7 +825,7 @@ mod tests {
assert_eq!(angle_deg, 135.0);
assert_eq!(stops.len(), 2);
assert!(offsets.is_empty(), "une scène sans offsets reste lisible");
- assert_eq!(motion, GradientMotion::None);
+ assert_eq!(motion, WallpaperMotion::None);
}
_ => panic!("expected gradient"),
}
@@ -895,17 +901,23 @@ mod tests {
}
#[test]
- fn gradient_motion_parses_and_tolerates_an_unknown_value() {
+ fn wallpaper_motion_parses_and_tolerates_an_unknown_value() {
let motion_of = |json: &str| match serde_json::from_str::<SceneBackground>(json).expect("parse") {
- SceneBackground::Gradient { motion, .. } => motion,
- _ => panic!("expected gradient"),
+ SceneBackground::Gradient { motion, .. }
+ | SceneBackground::Image { motion, .. } => motion,
+ _ => panic!("expected gradient or image"),
};
- let g = |m: &str| format!(r##"{{"kind":"gradient","angleDeg":90,"stops":["#000","#fff"]{m}}}"##);
- assert_eq!(motion_of(&g("")), GradientMotion::None);
- assert_eq!(motion_of(&g(r#","motion":"drift""#)), GradientMotion::Drift);
- assert_eq!(motion_of(&g(r#","motion":"aurora""#)), GradientMotion::Aurora);
- assert_eq!(motion_of(&g(r#","motion":"waves""#)), GradientMotion::Waves);
- assert_eq!(motion_of(&g(r#","motion":"plasma""#)), GradientMotion::None);
+ let g: fn(&str) -> String =
+ |m| format!(r##"{{"kind":"gradient","angleDeg":90,"stops":["#000","#fff"]{m}}}"##);
+ let i: fn(&str) -> String =
+ |m| format!(r#"{{"kind":"image","path":"/wallpapers/wallpaper1.jpg"{m}}}"#);
+ for bg in [g, i] {
+ assert_eq!(motion_of(&bg("")), WallpaperMotion::None);
+ assert_eq!(motion_of(&bg(r#","motion":"drift""#)), WallpaperMotion::Drift);
+ assert_eq!(motion_of(&bg(r#","motion":"aurora""#)), WallpaperMotion::Aurora);
+ assert_eq!(motion_of(&bg(r#","motion":"waves""#)), WallpaperMotion::Waves);
+ assert_eq!(motion_of(&bg(r#","motion":"plasma""#)), WallpaperMotion::None);
+ }
}
#[test]
diff --git a/crates/compositor/src/shaders.hlsl b/crates/compositor/src/shaders.hlsl
index bdfbaa074..a14c0acb0 100644
--- a/crates/compositor/src/shaders.hlsl
+++ b/crates/compositor/src/shaders.hlsl
@@ -355,6 +355,19 @@ float3 lighten(float3 c, float k)
return k > 0.0 ? c + (1.0 - c) * k : c * (1.0 + k);
}
+// Les trois nappes de l'aurore : leur poids gaussien (1 au centre) en `p`, position centrée et
+// corrigée de l'aspect, sur des Lissajous de 10 à 20 s. Le dégradé et l'image en partagent la
+// course.
+float3 aurora_blobs(float2 p, float time, float aspect)
+{
+ const float TAU = 6.2831853;
+ float2 b0 = float2(0.35 * aspect * sin(TAU * time / 10.0), 0.25 * sin(TAU * time / 15.0 + 1.0));
+ float2 b1 = float2(0.30 * aspect * sin(TAU * time / 12.0 + 2.0), 0.22 * cos(TAU * time / 20.0));
+ float2 b2 = float2(0.25 * aspect * cos(TAU * time / 15.0 + 4.0), 0.28 * sin(TAU * time / 12.0 + 3.0));
+ return float3(exp(-dot(p - b0, p - b0) / 0.176), exp(-dot(p - b1, p - b1) / 0.132),
+ exp(-dot(p - b2, p - b2) / 0.11));
+}
+
// Mouvements 2 (aurore) et 3 (vagues) du mode 5, sur la rampe de ses stops.
// `gp` 0..1 sur le quad, `dir`/`denom` ceux du dégradé, `time` = temps programme replié sur
// 120 s (toutes les périodes ci-dessous le divisent), `aspect` = w/h de la sortie. Amples et
@@ -376,13 +389,11 @@ float3 gradient_motion(float2 gp, float2 dir, float denom, float4 k0, float4 k1,
float ph = TAU * time / 30.0;
float n = value_noise(p * 1.8 + 1.5 * float2(cos(ph), sin(ph)));
float3 g = ramp4(saturate(0.5 + u + 0.6 * (n - 0.5)), k0, k1, k2, k3);
- float2 b0 = float2(0.35 * aspect * sin(TAU * time / 10.0), 0.25 * sin(TAU * time / 15.0 + 1.0));
- float2 b1 = float2(0.30 * aspect * sin(TAU * time / 12.0 + 2.0), 0.22 * cos(TAU * time / 20.0));
- float2 b2 = float2(0.25 * aspect * cos(TAU * time / 15.0 + 4.0), 0.28 * sin(TAU * time / 12.0 + 3.0));
+ float3 blobs = aurora_blobs(p, time, aspect);
float3 light = lighten(k3.rgb, 0.15);
- g = lerp(g, light, 0.7 * exp(-dot(p - b0, p - b0) / 0.176));
- g = lerp(g, lighten(k0.rgb, -0.15), 0.7 * exp(-dot(p - b1, p - b1) / 0.132));
- g = lerp(g, light, 0.6 * exp(-dot(p - b2, p - b2) / 0.11));
+ g = lerp(g, light, 0.7 * blobs.x);
+ g = lerp(g, lighten(k0.rgb, -0.15), 0.7 * blobs.y);
+ g = lerp(g, light, 0.6 * blobs.z);
return g;
}
// Vagues : trois bandes sinus perpendiculaires à l'axe, qui avancent d'une bande en 6 s,
@@ -392,6 +403,42 @@ float3 gradient_motion(float2 gp, float2 dir, float denom, float4 k0, float4 k1,
return lighten(ramp4(saturate(0.5 + u + 0.18 * w), k0, k1, k2, k3), 0.07 * w);
}
+// Les mêmes mouvements sur une image (mode 6). `q` = position -0.5..0.5 dans le cadre, donc dans
+// le rect « cover » de l'image ; `time`, `motion`, `aspect` comme au mode 5. Rend `q` déplacé
+// (xy) et l'éclairage à appliquer à la couleur lue (z, cf. `lighten`). Chaque mouvement zoome
+// l'image d'au moins 6 % et ne déplace jamais la lecture de plus que la marge ainsi gagnée : il
+// ne lit rien hors de l'image.
+float3 image_motion(float2 q, float time, float motion, float aspect)
+{
+ const float TAU = 6.2831853;
+ if (motion < 1.5)
+ {
+ // Dérive : zoom lent entre 8 et 22 % (20 s), panoramique sur les trois quarts de la marge
+ // qu'il laisse (15 et 24 s). Sûre sur une photo, elle ne déforme rien.
+ float z = 1.15 + 0.07 * sin(TAU * time / 20.0);
+ float m = 0.375 * (1.0 - 1.0 / z);
+ return float3(q / z + m * float2(sin(TAU * time / 15.0), cos(TAU * time / 24.0)), 0.0);
+ }
+ if (motion < 2.5)
+ {
+ // Aurore : l'image s'écoule sous un bruit de ±3 % (marge 3,7 %, origine qui tourne en
+ // 30 s), et les nappes de l'aurore l'éclairent ou l'assombrissent au passage.
+ float2 p = float2(q.x * aspect, q.y);
+ float ph = TAU * time / 30.0;
+ float2 c = p * 1.6 + 1.5 * float2(cos(ph), sin(ph));
+ float2 flow = float2(value_noise(c), value_noise(c + float2(5.2, 1.3))) - 0.5;
+ float3 blobs = aurora_blobs(p, time, aspect);
+ return float3(q / 1.08 + 0.06 * flow, 0.12 * (blobs.x - blobs.y + 0.85 * blobs.z));
+ }
+ // Vagues : les bandes du dégradé, sur la diagonale à 135° des dégradés proposés, ondulent
+ // l'image de ±0,85 % (marge 2,8 %) et éclairent leurs crêtes.
+ float2 d = float2(0.7071068, 0.7071068);
+ float u = dot(q, d) / 1.4142136;
+ float v = dot(q, float2(-d.y, d.x)) / 1.4142136;
+ float w = sin(TAU * (3.0 * u + 0.04 * sin(TAU * (1.5 * v + time / 10.0)) - time / 6.0));
+ return float3(q / 1.06 + 0.012 * w * d, 0.07 * w);
+}
+
// Couverture d'une pastille (disque) adoucie sur ~1.5 px, pour la barre de titre du mode 14.
float disc_cov(float2 p, float2 c, float r)
{
@@ -2489,10 +2536,21 @@ float4 ps_main(VSOut i) : SV_Target
// mode 6 : wallpaper image RGBA (cover-fit). src = rect uv déjà calculé (crop de
// recouvrement), i.uv l'interpole. Opaque.
+ // Fond animé : mêmes emplacements qu'au mode 5 (fx.z temps, fx.w mouvement, mb.x aspect).
+ // fx.w = 0 lit l'image telle quelle, à l'octet près.
if (mode > 5.5)
{
+ float2 uv = i.uv;
+ float light = 0.0;
+ if (fx.w > 0.5)
+ {
+ float2 size = src.zw - src.xy;
+ float3 m = image_motion((i.uv - src.xy) / size - 0.5, fx.z, fx.w, mb.x);
+ uv = src.xy + (m.xy + 0.5) * size;
+ light = m.z;
+ }
float a = quad_round_alpha(i.local, quad_px, radius_px);
- return float4(texImg.Sample(samp, i.uv).rgb * a, a); // prémultiplié
+ return float4(lighten(texImg.Sample(samp, uv).rgb, light) * a, a); // prémultiplié
}
// mode 5 : gradient linéaire jusqu'à 4 stops (parité web wallpaper dégradé). Nœuds
diff --git a/crates/compositor/src/shaders.metal b/crates/compositor/src/shaders.metal
index 907eb91b5..ef377d81e 100644
--- a/crates/compositor/src/shaders.metal
+++ b/crates/compositor/src/shaders.metal
@@ -469,6 +469,17 @@ inline float3 lighten(float3 c, float k)
return k > 0.0 ? c + (1.0 - c) * k : c * (1.0 + k);
}
+// Les trois nappes de l'aurore. Miroir de `aurora_blobs` côté HLSL.
+inline float3 aurora_blobs(float2 p, float time, float aspect)
+{
+ const float TAU = 6.2831853;
+ float2 b0 = float2(0.35 * aspect * sin(TAU * time / 10.0), 0.25 * sin(TAU * time / 15.0 + 1.0));
+ float2 b1 = float2(0.30 * aspect * sin(TAU * time / 12.0 + 2.0), 0.22 * cos(TAU * time / 20.0));
+ float2 b2 = float2(0.25 * aspect * cos(TAU * time / 15.0 + 4.0), 0.28 * sin(TAU * time / 12.0 + 3.0));
+ return float3(exp(-dot(p - b0, p - b0) / 0.176), exp(-dot(p - b1, p - b1) / 0.132),
+ exp(-dot(p - b2, p - b2) / 0.11));
+}
+
// Mouvements 2 (aurore) et 3 (vagues) du mode 5. Miroir ligne pour ligne de
// `gradient_motion` côté HLSL (commentaires complets là-bas).
inline float3 gradient_motion(float2 gp, float2 dir, float denom, float4 k0, float4 k1,
@@ -483,13 +494,11 @@ inline float3 gradient_motion(float2 gp, float2 dir, float denom, float4 k0, flo
float ph = TAU * time / 30.0;
float n = value_noise(p * 1.8 + 1.5 * float2(cos(ph), sin(ph)));
float3 g = ramp4(clamp(0.5 + u + 0.6 * (n - 0.5), 0.0, 1.0), k0, k1, k2, k3);
- float2 b0 = float2(0.35 * aspect * sin(TAU * time / 10.0), 0.25 * sin(TAU * time / 15.0 + 1.0));
- float2 b1 = float2(0.30 * aspect * sin(TAU * time / 12.0 + 2.0), 0.22 * cos(TAU * time / 20.0));
- float2 b2 = float2(0.25 * aspect * cos(TAU * time / 15.0 + 4.0), 0.28 * sin(TAU * time / 12.0 + 3.0));
+ float3 blobs = aurora_blobs(p, time, aspect);
float3 light = lighten(k3.rgb, 0.15);
- g = mix(g, light, 0.7 * exp(-dot(p - b0, p - b0) / 0.176));
- g = mix(g, lighten(k0.rgb, -0.15), 0.7 * exp(-dot(p - b1, p - b1) / 0.132));
- g = mix(g, light, 0.6 * exp(-dot(p - b2, p - b2) / 0.11));
+ g = mix(g, light, 0.7 * blobs.x);
+ g = mix(g, lighten(k0.rgb, -0.15), 0.7 * blobs.y);
+ g = mix(g, light, 0.6 * blobs.z);
return g;
}
// Vagues : trois bandes sinus perpendiculaires à l'axe (6 s), ondulées (10 s), crêtes éclairées.
@@ -498,6 +507,36 @@ inline float3 gradient_motion(float2 gp, float2 dir, float denom, float4 k0, flo
return lighten(ramp4(clamp(0.5 + u + 0.18 * w, 0.0, 1.0), k0, k1, k2, k3), 0.07 * w);
}
+// Les mêmes mouvements sur une image (mode 6). Miroir ligne pour ligne de `image_motion` côté
+// HLSL (commentaires complets là-bas) : rend `q` déplacé (xy) et l'éclairage (z).
+inline float3 image_motion(float2 q, float time, float motion, float aspect)
+{
+ const float TAU = 6.2831853;
+ if (motion < 1.5)
+ {
+ // Dérive : zoom lent entre 8 et 22 % (20 s), panoramique dans sa marge (15 et 24 s).
+ float z = 1.15 + 0.07 * sin(TAU * time / 20.0);
+ float m = 0.375 * (1.0 - 1.0 / z);
+ return float3(q / z + m * float2(sin(TAU * time / 15.0), cos(TAU * time / 24.0)), 0.0);
+ }
+ if (motion < 2.5)
+ {
+ // Aurore : écoulement sous un bruit de ±3 %, éclairé par les nappes.
+ float2 p = float2(q.x * aspect, q.y);
+ float ph = TAU * time / 30.0;
+ float2 c = p * 1.6 + 1.5 * float2(cos(ph), sin(ph));
+ float2 flow = float2(value_noise(c), value_noise(c + float2(5.2, 1.3))) - 0.5;
+ float3 blobs = aurora_blobs(p, time, aspect);
+ return float3(q / 1.08 + 0.06 * flow, 0.12 * (blobs.x - blobs.y + 0.85 * blobs.z));
+ }
+ // Vagues : bandes à 135° qui ondulent l'image de ±0,85 % et éclairent leurs crêtes.
+ float2 d = float2(0.7071068, 0.7071068);
+ float u = dot(q, d) / 1.4142136;
+ float v = dot(q, float2(-d.y, d.x)) / 1.4142136;
+ float w = sin(TAU * (3.0 * u + 0.04 * sin(TAU * (1.5 * v + time / 10.0)) - time / 6.0));
+ return float3(q / 1.06 + 0.012 * w * d, 0.07 * w);
+}
+
// ============ Curseur MODÉLISÉ (mode 15) ============
// Port ligne pour ligne de `cursor_model` (HLSL), dont les commentaires font foi ; seules
// différences : `layer` et les textures arrivent en paramètres (le sprite en texture(2), son
@@ -2263,10 +2302,23 @@ fragment float4 ps_main(VSOut i [[stage_in]],
// l'alpha valait 0 et le fond image était rigoureusement invisible : un fond noir,
// qu'on lit comme « le compositeur ne dessine pas le wallpaper » plutôt que comme
// « le wallpaper est dessiné avec alpha 0 ».
+ //
+ // Fond animé : mêmes emplacements qu'au mode 5 (fx.z temps, fx.w mouvement, mb.x aspect).
+ // fx.w = 0 lit l'image telle quelle, à l'octet près.
if (layer.mode > 5.5 && layer.mode < 6.5)
{
+ float2 uv = i.uv;
+ float light = 0.0;
+ if (layer.fx.w > 0.5)
+ {
+ float2 size = layer.src.zw - layer.src.xy;
+ float3 m = image_motion((i.uv - layer.src.xy) / size - 0.5, layer.fx.z, layer.fx.w,
+ layer.mb.x);
+ uv = layer.src.xy + (m.xy + 0.5) * size;
+ light = m.z;
+ }
float a = quad_round_alpha(i.local, layer.quad_px, layer.radius_px);
- return float4(texImg.sample(samp, i.uv).rgb * a, a); // prémultiplié
+ return float4(lighten(texImg.sample(samp, uv).rgb, light) * a, a); // prémultiplié
}
// mode 5 : gradient linéaire jusqu'à 4 stops (parité web wallpaper dégradé). Nœuds
diff --git a/crates/compositor/src/vk_shaders/layer.wgsl b/crates/compositor/src/vk_shaders/layer.wgsl
index 69f1026d6..4549c4740 100644
--- a/crates/compositor/src/vk_shaders/layer.wgsl
+++ b/crates/compositor/src/vk_shaders/layer.wgsl
@@ -429,6 +429,16 @@ fn lighten(c: vec3<f32>, k: f32) -> vec3<f32> {
return select(c * (1.0 + k), c + (vec3<f32>(1.0) - c) * k, k > 0.0);
}
+// Les trois nappes de l'aurore. Miroir de `aurora_blobs` cote HLSL.
+fn aurora_blobs(p: vec2<f32>, time: f32, aspect: f32) -> vec3<f32> {
+ let TAU = 6.2831853;
+ let b0 = vec2<f32>(0.35 * aspect * sin(TAU * time / 10.0), 0.25 * sin(TAU * time / 15.0 + 1.0));
+ let b1 = vec2<f32>(0.30 * aspect * sin(TAU * time / 12.0 + 2.0), 0.22 * cos(TAU * time / 20.0));
+ let b2 = vec2<f32>(0.25 * aspect * cos(TAU * time / 15.0 + 4.0), 0.28 * sin(TAU * time / 12.0 + 3.0));
+ return vec3<f32>(exp(-dot(p - b0, p - b0) / 0.176), exp(-dot(p - b1, p - b1) / 0.132),
+ exp(-dot(p - b2, p - b2) / 0.11));
+}
+
// Mouvements 2 (aurore) et 3 (vagues) du mode 5. Miroir ligne pour ligne de
// `gradient_motion` cote HLSL (commentaires complets la-bas).
fn gradient_motion(gp: vec2<f32>, dir: vec2<f32>, denom: f32, k0: vec4<f32>, k1: vec4<f32>,
@@ -441,13 +451,11 @@ fn gradient_motion(gp: vec2<f32>, dir: vec2<f32>, denom: f32, k0: vec4<f32>, k1:
let ph = TAU * time / 30.0;
let n = value_noise(p * 1.8 + 1.5 * vec2<f32>(cos(ph), sin(ph)));
var g = ramp4(clamp(0.5 + u + 0.6 * (n - 0.5), 0.0, 1.0), k0, k1, k2, k3);
- let b0 = vec2<f32>(0.35 * aspect * sin(TAU * time / 10.0), 0.25 * sin(TAU * time / 15.0 + 1.0));
- let b1 = vec2<f32>(0.30 * aspect * sin(TAU * time / 12.0 + 2.0), 0.22 * cos(TAU * time / 20.0));
- let b2 = vec2<f32>(0.25 * aspect * cos(TAU * time / 15.0 + 4.0), 0.28 * sin(TAU * time / 12.0 + 3.0));
+ let blobs = aurora_blobs(p, time, aspect);
let light = lighten(k3.rgb, 0.15);
- g = mix(g, light, 0.7 * exp(-dot(p - b0, p - b0) / 0.176));
- g = mix(g, lighten(k0.rgb, -0.15), 0.7 * exp(-dot(p - b1, p - b1) / 0.132));
- g = mix(g, light, 0.6 * exp(-dot(p - b2, p - b2) / 0.11));
+ g = mix(g, light, 0.7 * blobs.x);
+ g = mix(g, lighten(k0.rgb, -0.15), 0.7 * blobs.y);
+ g = mix(g, light, 0.6 * blobs.z);
return g;
}
// Vagues : trois bandes sinus perpendiculaires a l'axe (6 s), ondulees (10 s), cretes eclairees.
@@ -456,6 +464,33 @@ fn gradient_motion(gp: vec2<f32>, dir: vec2<f32>, denom: f32, k0: vec4<f32>, k1:
return lighten(ramp4(clamp(0.5 + u + 0.18 * w, 0.0, 1.0), k0, k1, k2, k3), 0.07 * w);
}
+// Les memes mouvements sur une image (mode 6). Miroir ligne pour ligne de `image_motion` cote
+// HLSL (commentaires complets la-bas) : rend `q` deplace (xy) et l'eclairage (z).
+fn image_motion(q: vec2<f32>, time: f32, motion: f32, aspect: f32) -> vec3<f32> {
+ let TAU = 6.2831853;
+ if motion < 1.5 {
+ // Derive : zoom lent entre 8 et 22 % (20 s), panoramique dans sa marge (15 et 24 s).
+ let z = 1.15 + 0.07 * sin(TAU * time / 20.0);
+ let m = 0.375 * (1.0 - 1.0 / z);
+ return vec3<f32>(q / z + m * vec2<f32>(sin(TAU * time / 15.0), cos(TAU * time / 24.0)), 0.0);
+ }
+ if motion < 2.5 {
+ // Aurore : ecoulement sous un bruit de +-3 %, eclaire par les nappes.
+ let p = vec2<f32>(q.x * aspect, q.y);
+ let ph = TAU * time / 30.0;
+ let c = p * 1.6 + 1.5 * vec2<f32>(cos(ph), sin(ph));
+ let flow = vec2<f32>(value_noise(c), value_noise(c + vec2<f32>(5.2, 1.3))) - vec2<f32>(0.5);
+ let blobs = aurora_blobs(p, time, aspect);
+ return vec3<f32>(q / 1.08 + 0.06 * flow, 0.12 * (blobs.x - blobs.y + 0.85 * blobs.z));
+ }
+ // Vagues : bandes a 135 deg qui ondulent l'image de +-0,85 % et eclairent leurs cretes.
+ let d = vec2<f32>(0.7071068, 0.7071068);
+ let u = dot(q, d) / 1.4142136;
+ let v = dot(q, vec2<f32>(-d.y, d.x)) / 1.4142136;
+ let w = sin(TAU * (3.0 * u + 0.04 * sin(TAU * (1.5 * v + time / 10.0)) - time / 6.0));
+ return vec3<f32>(q / 1.06 + 0.012 * w * d, 0.07 * w);
+}
+
// Couverture d'une pastille (disque) adoucie sur ~1.5 px, pour la barre de titre du mode 14.
fn disc_cov(p: vec2<f32>, c: vec2<f32>, r: f32) -> f32 {
return 1.0 - smoothstep(r - 0.75, r + 0.75, length(p - c));
@@ -2011,8 +2046,19 @@ fn fs_main(i: VsOut) -> @location(0) vec4<f32> {
// Mode 6 -- fond image (wallpaper RGBA) cover-fit, echantillonne sur
// texY. `src` porte le rect UV cover-fit (calcule cote Rust). Opaque :
// le fond couvre tout le cadre.
+ // Fond anime : memes emplacements qu'au mode 5 (fx.z temps, fx.w mouvement,
+ // mb.x aspect). fx.w = 0 lit l'image telle quelle, a l'octet pres.
+ var uv = i.uv;
+ var light = 0.0;
+ if layer.fx.w > 0.5 {
+ let size = layer.src.zw - layer.src.xy;
+ let m = image_motion((i.uv - layer.src.xy) / size - vec2<f32>(0.5), layer.fx.z,
+ layer.fx.w, layer.mb.x);
+ uv = layer.src.xy + (m.xy + vec2<f32>(0.5)) * size;
+ light = m.z;
+ }
let bg_a = quad_round_alpha(i.local, layer.quad_px, layer.radius_px);
- return vec4<f32>(textureSample(texY, samp, i.uv).rgb * bg_a, bg_a); // premultiplie
+ return vec4<f32>(lighten(textureSample(texY, samp, uv).rgb, light) * bg_a, bg_a); // premultiplie
} else if layer.mode > 7.5 && layer.mode < 8.5 {
// Mode 8 -- ecran tilte (rotation 3D des zoom regions). Le quad projete est
// dessine dans sa BBOX (le VS ne sait tracer qu'un rect) et chaque fragment
diff --git a/crates/compositor/tests/animated_background.rs b/crates/compositor/tests/animated_background.rs
index fb8dc3488..748e605f3 100644
--- a/crates/compositor/tests/animated_background.rs
+++ b/crates/compositor/tests/animated_background.rs
@@ -1,6 +1,6 @@
-//! Un fond dégradé animé (mode 5, `fx.w`) est une fonction pure du temps programme :
-//! immobile, il ne dépend pas de l'instant ; animé, chaque mouvement donne une image propre à
-//! chacun des trois instants fixes, et différente du dégradé immobile.
+//! Un fond animé, dégradé (mode 5) ou image (mode 6), est une fonction pure du temps programme
+//! (`fx.w`) : immobile, il ne dépend pas de l'instant ; animé, chaque mouvement donne une image
+//! propre à chacun des trois instants fixes, et différente du fond immobile.
//!
//! Rend de vraies frames par le compositeur D3D11. Piloté par l'environnement, comme
//! `privacy_blur_under_zoom.rs`, dont il réutilise la source (n'importe quel MP4 d'au moins
@@ -43,8 +43,19 @@ fn write_ppm(path: &std::path::Path, rgba: &[u8], w: u32, h: u32) -> std::io::Re
std::fs::write(path, out)
}
-/// `motion` : fragment JSON inséré tel quel dans le fond (`""` = clé absente).
-fn scene_json(source: &str, motion: &str) -> String {
+/// Le fond, ouvert : `scene_json` y ajoute le mouvement puis referme l'accolade.
+const GRADIENT: &str = r##"{"kind":"gradient","angleDeg":135,"stops":["#2b3a67","#b8577f"]"##;
+
+/// Un fond image du catalogue, lu depuis `public/wallpapers` : le zoom et le déplacement que
+/// chaque mouvement lui applique ne se vérifient que sur une vraie image.
+fn image_background() -> String {
+ let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../../public/wallpapers/wallpaper3.jpg");
+ format!(r#"{{"kind":"image","path":"{}""#, path.replace('\\', "/"))
+}
+
+/// `background` : le fond ouvert (`GRADIENT`, `image_background`) ; `motion` : fragment JSON
+/// inséré tel quel dedans (`""` = clé absente).
+fn scene_json(source: &str, background: &str, motion: &str) -> String {
let s = source.replace('\\', "/");
let clip = format!(
r#"{{"screenPath":"{s}","webcamPath":"","sourceStartSec":0,"sourceEndSec":6,"webcamOffsetSec":0,"hasAudio":false}}"#
@@ -54,7 +65,7 @@ fn scene_json(source: &str, motion: &str) -> String {
"clips": [{clip},{clip},{clip}],
"layout": {{"preset":"no-webcam","webcamSize":1.0,"webcamShape":"rounded","webcamMirror":false,"webcamPosition":null,"webcamReactiveZoom":false}},
"effects": {{"padding":1.0,"blur":false,"shadow":0.0,"roundnessFrac":0.02,"motionBlur":0.0}},
- "background": {{"kind":"gradient","angleDeg":135,"stops":["#2b3a67","#b8577f"]{motion}}},
+ "background": {background}{motion}}},
"zoomRegions": [],
"speedRegions": [],
"cursor": {{"show":false,"size":1,"smoothing":0,"motionBlur":0,"clickBounce":0,"clipToBounds":false,"theme":"default"}},
@@ -64,12 +75,12 @@ fn scene_json(source: &str, motion: &str) -> String {
)
}
-fn render(gpu: &Gpu, source: &str, motion: &str, clip: usize) -> Vec<u8> {
+fn render(gpu: &Gpu, source: &str, background: &str, motion: &str, clip: usize) -> Vec<u8> {
let mut cfg = config::all().pop().expect("au moins une config");
cfg.zoom = false;
cfg.layout_anim = false;
let comp = Compositor::new_sized(gpu, W, H).expect("compositor");
- let scene = Scene::from_json(&scene_json(source, motion)).expect("scene valide");
+ let scene = Scene::from_json(&scene_json(source, background, motion)).expect("scene valide");
comp.set_live_params(live_params_from_scene(&scene));
comp.set_scene(Some(scene.clone()));
comp.clear_cursor();
@@ -100,35 +111,42 @@ fn each_motion_is_a_distinct_pure_function_of_programme_time() {
std::fs::create_dir_all(dir).expect("creer le dossier de sortie");
}
let gpu = Gpu::create(false).expect("device d3d11");
- let shoot = |name: &str, motion: &str, clip: usize| {
- let rgba = render(&gpu, &source, motion, clip);
- if let Some(dir) = &out_dir {
- let file = format!("{name}-t{:02}.ppm", PROGRAMME_TIMES[clip] as u32);
- write_ppm(&dir.join(file), &rgba, W, H).expect("ecrire le ppm");
- }
- let h = hash(&rgba);
- println!("{name:<8} t={:>4} {h:016x}", PROGRAMME_TIMES[clip]);
- h
- };
+ for (kind, background) in [("gradient", GRADIENT.to_string()), ("image", image_background())] {
+ let shoot = |name: &str, motion: &str, clip: usize| {
+ let rgba = render(&gpu, &source, &background, motion, clip);
+ if let Some(dir) = &out_dir {
+ let file = format!("{kind}-{name}-t{:02}.ppm", PROGRAMME_TIMES[clip] as u32);
+ write_ppm(&dir.join(file), &rgba, W, H).expect("ecrire le ppm");
+ }
+ let h = hash(&rgba);
+ println!("{kind:<8} {name:<8} t={:>4} {h:016x}", PROGRAMME_TIMES[clip]);
+ h
+ };
- // Immobile : clé absente, "none" et une valeur inconnue rendent la même image, à tout instant.
- let still = shoot("absent", "", 0);
- for clip in 0..3 {
- assert_eq!(shoot("none", r#","motion":"none""#, clip), still, "none au clip {clip}");
- }
- assert_eq!(shoot("unknown", r#","motion":"plasma""#, 2), still);
+ // Immobile : clé absente, "none" et une valeur inconnue rendent la même image, à tout
+ // instant.
+ let still = shoot("absent", "", 0);
+ for clip in 0..3 {
+ let none = shoot("none", r#","motion":"none""#, clip);
+ assert_eq!(none, still, "{kind} : none au clip {clip}");
+ }
+ assert_eq!(shoot("unknown", r#","motion":"plasma""#, 2), still, "{kind} : inconnu");
- for name in ["drift", "aurora", "waves"] {
- let motion = format!(r#","motion":"{name}""#);
- let hashes: Vec<u64> = (0..3).map(|clip| shoot(name, &motion, clip)).collect();
- for (k, h) in hashes.iter().enumerate() {
- assert_ne!(*h, still, "{name} a t={} rend le degrade immobile", PROGRAMME_TIMES[k]);
+ for name in ["drift", "aurora", "waves"] {
+ let motion = format!(r#","motion":"{name}""#);
+ let hashes: Vec<u64> = (0..3).map(|clip| shoot(name, &motion, clip)).collect();
+ for (k, h) in hashes.iter().enumerate() {
+ let t = PROGRAMME_TIMES[k];
+ assert_ne!(*h, still, "{kind} {name} a t={t} rend le fond immobile");
+ }
+ assert!(
+ hashes[0] != hashes[1] && hashes[1] != hashes[2] && hashes[0] != hashes[2],
+ "{kind} {name} : deux instants rendent la meme image ({hashes:x?})"
+ );
+ // Fonction pure : le même instant recomposé par un autre compositeur donne le même
+ // octet.
+ let again = shoot(name, &motion, 1);
+ assert_eq!(again, hashes[1], "{kind} {name} n'est pas reproductible");
}
- assert!(
- hashes[0] != hashes[1] && hashes[1] != hashes[2] && hashes[0] != hashes[2],
- "{name} : deux instants rendent la meme image ({hashes:x?})"
- );
- // Fonction pure : le même instant recomposé par un autre compositeur donne le même octet.
- assert_eq!(shoot(name, &motion, 1), hashes[1], "{name} n'est pas reproductible");
}
}
diff --git a/src/components/ai-edition/RightPanes.backgroundMotion.test.tsx b/src/components/ai-edition/RightPanes.backgroundMotion.test.tsx
index 536e66a78..a23601aaa 100644
--- a/src/components/ai-edition/RightPanes.backgroundMotion.test.tsx
+++ b/src/components/ai-edition/RightPanes.backgroundMotion.test.tsx
@@ -1,7 +1,7 @@
// @vitest-environment jsdom
-// The background animation control moves only what the compositor draws as a gradient. On any
-// other wallpaper it is not shown at all, rather than holding a choice that changes nothing on
-// screen, and the stored choice waits for the next gradient.
+// The background animation control moves a gradient or an image wallpaper. On a solid colour it
+// is not shown at all, rather than holding a choice that changes nothing on screen, and the stored
+// choice waits for the next wallpaper that moves.
import "@testing-library/jest-dom";
import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
@@ -53,8 +53,16 @@ describe("background animation control", () => {
});
});
- it("is not shown on an image, and keeps the stored choice for the next gradient", () => {
- renderWith({ wallpaper: "/wallpapers/wallpaper1.jpg", wallpaperMotion: "waves" });
+ it("animates an image wallpaper", () => {
+ renderWith({ wallpaper: "/wallpapers/wallpaper1.jpg" });
+ fireEvent.click(choice("Drift"));
+ expect(useProjectStore.getState().document?.legacyEditor).toMatchObject({
+ wallpaperMotion: "drift",
+ });
+ });
+
+ it("is not shown on a solid colour, and keeps the stored choice for the next one", () => {
+ renderWith({ wallpaper: "#123456", wallpaperMotion: "waves" });
expect(screen.queryByRole("group", { name: "Animation" })).not.toBeInTheDocument();
expect(useProjectStore.getState().document?.legacyEditor).toMatchObject({
wallpaperMotion: "waves",
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index 0fafc82f5..75c9050e7 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -401,8 +401,9 @@ function BackgroundSection() {
onPickFile={handlePickFile}
/>
{fileInput}
- {/* Only a gradient can move, so the row comes with one instead of sitting greyed out
- under a photo. The stored choice is kept and comes back with the next gradient. */}
+ {/* Only a gradient or an image can move, so the row comes with one instead of sitting
+ greyed out under a solid colour. The stored choice is kept and comes back with the
+ next wallpaper that moves. */}
{wallpaperAcceptsMotion(settings.wallpaper) ? (
<div className={`${styles.field} ${styles.fieldStack}`}>
<span className={styles.fieldLabel}>{ts("background.motion")}</span>
diff --git a/src/components/video-editor/types.ts b/src/components/video-editor/types.ts
index ec98991a3..312c9a70d 100644
--- a/src/components/video-editor/types.ts
+++ b/src/components/video-editor/types.ts
@@ -38,8 +38,8 @@ export function isWebcamBackgroundMode(value: unknown): value is WebcamBackgroun
export const DEFAULT_WEBCAM_BACKGROUND_MODE: WebcamBackgroundMode = "none";
-/** Slow motion of a gradient wallpaper, rendered by the native compositor from programme
- * time. Only a `linear-gradient(...)` wallpaper moves; any other keeps its value and ignores it. */
+/** Motion of a gradient or image wallpaper, rendered by the native compositor from programme
+ * time. A solid colour keeps the value and ignores it: nothing on it could move. */
export const WALLPAPER_MOTIONS = ["none", "drift", "aurora", "waves"] as const;
export type WallpaperMotion = (typeof WALLPAPER_MOTIONS)[number];
diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.ts
index b15d23cd1..346dd56f2 100644
--- a/src/native/sceneDescription.test.ts
+++ b/src/native/sceneDescription.test.ts
@@ -229,7 +229,7 @@ describe("buildSceneDescription.background motion", () => {
}
});
- it("never moves a colour, an image or the webcam's own gradient", () => {
+ it("attaches the chosen motion to an image, and never to the webcam's own background", () => {
const doc = makeDoc({
legacyEditor: {
wallpaper: "/wallpapers/wallpaper1.jpg",
@@ -239,17 +239,28 @@ describe("buildSceneDescription.background motion", () => {
},
});
const scene = buildSceneDescription(doc);
- expect(scene.background).toEqual({ kind: "image", path: "/wallpapers/wallpaper1.jpg" });
+ expect(scene.background).toEqual({
+ kind: "image",
+ path: "/wallpapers/wallpaper1.jpg",
+ motion: "waves",
+ });
expect(scene.webcamEffect?.background).not.toHaveProperty("motion");
+ });
+
+ it("never moves a colour, or a string the compositor cannot load as an image", () => {
const colour = makeDoc({ legacyEditor: { wallpaper: "#123456", wallpaperMotion: "drift" } });
expect(buildSceneDescription(colour).background).toEqual({ kind: "color", color: "#123456" });
+ const radial = "radial-gradient(#fff, #000)";
+ const doc = makeDoc({ legacyEditor: { wallpaper: radial, wallpaperMotion: "drift" } });
+ expect(buildSceneDescription(doc).background).toEqual({ kind: "image", path: radial });
});
it("enables the control exactly for the wallpapers the compositor animates", () => {
expect(wallpaperAcceptsMotion(gradient)).toBe(true);
+ expect(wallpaperAcceptsMotion("/wallpapers/wallpaper1.jpg")).toBe(true);
+ expect(wallpaperAcceptsMotion("data:image/png;base64,AAAA")).toBe(true);
expect(wallpaperAcceptsMotion("#123456")).toBe(false);
- expect(wallpaperAcceptsMotion("/wallpapers/wallpaper1.jpg")).toBe(false);
- // Drawn by the web preview only; the compositor paints it as an image path.
+ // Drawn by the web preview only; the compositor gets it as an image path it cannot load.
expect(wallpaperAcceptsMotion("radial-gradient(#fff, #000)")).toBe(false);
});
});
diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.ts
index 309a93332..21584e602 100644
--- a/src/native/sceneDescription.ts
+++ b/src/native/sceneDescription.ts
@@ -63,6 +63,7 @@ import type { CursorKind } from "@/lib/cursor/cursorThemes";
import { parseCssGradient, resolveLinearGradientAngle } from "@/lib/exporter/gradientParser";
import type { FrameTheme, RecordingFrame, WebcamAnchor } from "@/lib/projectDefaults";
import { resolveTextFontFamily } from "@/lib/textFonts";
+import { classifyWallpaper } from "@/lib/wallpaper";
import type { CompositorClipInput } from "./contracts";
import { ROUNDNESS_REFERENCE_PX } from "./paramUnits";
@@ -80,7 +81,8 @@ export type SceneBackground =
offsets: number[];
motion?: Exclude<WallpaperMotion, "none">;
}
- | { kind: "image"; path: string }; // "/wallpapers/…" or a data: URL
+ // "/wallpapers/…" or a data: URL. `motion` as for the gradient: omitted when still.
+ | { kind: "image"; path: string; motion?: Exclude<WallpaperMotion, "none"> };
/** A timeline zoom region (from `document.zoomRanges`). Times in seconds. */
export interface SceneZoomRegion {
@@ -586,20 +588,25 @@ function parseWallpaper(wallpaper: string) {
}
/**
- * True when `settings.wallpaperMotion` has something to move: the compositor animates only
- * the gradient it draws itself. The motion control asks this, not its own guess at what a
- * gradient is, so it is enabled exactly when the export would show the motion.
+ * True when `settings.wallpaperMotion` has something to move: a linear gradient the compositor
+ * draws itself, or an image it loads. A colour has nothing to move, and any other string (a
+ * radial gradient, a colour function) reaches the compositor as an image path that does not
+ * load. The motion control asks this, not its own guess, so it is shown exactly when the export
+ * would move.
*/
export function wallpaperAcceptsMotion(wallpaper: string): boolean {
- return parseWallpaper(wallpaper).kind === "gradient";
+ return (
+ parseWallpaper(wallpaper).kind === "gradient" || classifyWallpaper(wallpaper).kind === "image"
+ );
}
/** The screen background with the chosen motion attached, when there is one to attach. */
function sceneBackground(wallpaper: string, motion: WallpaperMotion): SceneBackground {
const background = parseWallpaper(wallpaper);
- return background.kind === "gradient" && motion !== "none"
- ? { ...background, motion }
- : background;
+ if (motion === "none" || background.kind === "color" || !wallpaperAcceptsMotion(wallpaper)) {
+ return background;
+ }
+ return { ...background, motion };
}
/**