diff --git a/examples/headless/src/main.rs b/examples/headless/src/main.rs index 5664b32..f14bbb3 100644 --- a/examples/headless/src/main.rs +++ b/examples/headless/src/main.rs @@ -96,6 +96,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> { time: args.time.unwrap_or(0.), text: &mut text, resolution: None, + base_color: None, }; (example_scene.function)(&mut builder, &mut scene_params); builder.finish(); @@ -130,6 +131,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> { base_color: args .args .get_base_color()? + .or(scene_params.base_color) .unwrap_or(vello::peniko::Color::BLACK), width, height, diff --git a/examples/scenes/src/lib.rs b/examples/scenes/src/lib.rs index 2aed412..c806894 100644 --- a/examples/scenes/src/lib.rs +++ b/examples/scenes/src/lib.rs @@ -19,6 +19,7 @@ pub struct SceneParams<'a> { pub time: f64, pub text: &'a mut SimpleText, pub resolution: Option, + pub base_color: Option, } pub struct SceneConfig { diff --git a/examples/scenes/src/test_scenes.rs b/examples/scenes/src/test_scenes.rs index f268076..46ede47 100644 --- a/examples/scenes/src/test_scenes.rs +++ b/examples/scenes/src/test_scenes.rs @@ -32,6 +32,7 @@ pub fn test_scenes() -> SceneSet { scene!(blend_grid), scene!(conflation_artifacts), scene!(labyrinth), + scene!(base_color_test: animated), ]; #[cfg(target_arch = "wasm32")] scenes.push(ExampleScene { @@ -582,6 +583,21 @@ fn labyrinth(sb: &mut SceneBuilder, _: &mut SceneParams) { ) } +fn base_color_test(sb: &mut SceneBuilder, params: &mut SceneParams) { + // Cycle through the hue value every 5 seconds (t % 5) * 360/5 + let color = Color::hlc((params.time % 5.0) * 72.0, 80.0, 80.0); + params.base_color = Some(color); + + // Blend a white square over it. + sb.fill( + Fill::NonZero, + Affine::IDENTITY, + Color::rgba8(255, 255, 255, 128), + None, + &Rect::new(50.0, 50.0, 500.0, 500.0), + ); +} + fn around_center(xform: Affine, center: Point) -> Affine { Affine::translate(center.to_vec2()) * xform * Affine::translate(-center.to_vec2()) } diff --git a/examples/with_winit/src/main.rs b/examples/with_winit/src/main.rs index 8aee854..91a6e55 100644 --- a/examples/with_winit/src/main.rs +++ b/examples/with_winit/src/main.rs @@ -59,7 +59,7 @@ async fn run( event_loop: EventLoop, window: Window, args: Args, - base_color: Color, + base_color_arg: Option, mut scenes: SceneSet, ) { use winit::{event::*, event_loop::ControlFlow}; @@ -163,12 +163,6 @@ async fn run( let height = surface.config.height; let device_handle = &render_cx.devices[surface.dev_id]; - let render_params = vello::RenderParams { - base_color, - width, - height, - }; - // Allow looping forever scene_ix = scene_ix.rem_euclid(scenes.scenes.len() as i32); let example_scene = &mut scenes.scenes[scene_ix as usize]; @@ -182,9 +176,20 @@ async fn run( time: start.elapsed().as_secs_f64(), text: &mut simple_text, resolution: None, + base_color: None, }; (example_scene.function)(&mut builder, &mut scene_params); builder.finish(); + + // If the user specifies a base color in the CLI we use that. Otherwise we use any + // color specified by the scene. The default is black. + let render_params = vello::RenderParams { + base_color: base_color_arg + .or(scene_params.base_color) + .unwrap_or(Color::BLACK), + width, + height, + }; let mut builder = SceneBuilder::for_scene(&mut scene); let mut transform = transform; if let Some(resolution) = scene_params.resolution { @@ -257,7 +262,7 @@ fn main() -> Result<()> { env_logger::init(); let args = Args::parse(); let scenes = args.args.select_scene_set(|| Args::command())?; - let base_color = args.args.get_base_color()?.unwrap_or(Color::BLACK); + let base_color = args.args.get_base_color()?; if let Some(scenes) = scenes { #[cfg(not(target_arch = "wasm32"))] {