Skip to content

Commit

Permalink
fix: image opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau committed Jul 5, 2024
1 parent c1ef104 commit 9067f20
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe

### Fixed

- Opacity now correctly applies to SVG assets.
- Opacity now applies correctly to the lottie image group, rather than each element and path within it, causing overdraw.
- `VelloScene` components on `bevy::ui::Node` entities now account for Bevy's UI layout systems and render at the expected viewport coordinates

### Removed
Expand Down
7 changes: 2 additions & 5 deletions src/render/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ pub struct ExtractedRenderAsset {
pub z_function: ZFunction,
pub render_mode: CoordinateSpace,
pub ui_node: Option<Node>,
pub alpha: f32,
#[cfg(feature = "lottie")]
pub theme: Option<crate::Theme>,
#[cfg(feature = "lottie")]
pub playhead: f64,
#[cfg(feature = "lottie")]
pub alpha: f32,
}

#[cfg(feature = "svg")]
Expand Down Expand Up @@ -56,7 +55,6 @@ pub fn extract_svg_instances(
if let Some(
asset @ VelloAsset {
file: _file @ crate::VectorFile::Svg(_),
#[cfg(feature = "lottie")]
alpha,
..
},
Expand All @@ -70,12 +68,11 @@ pub fn extract_svg_instances(
z_function: *z_function,
render_mode: *coord_space,
ui_node: ui_node.cloned(),
alpha: *alpha,
#[cfg(feature = "lottie")]
theme: None,
#[cfg(feature = "lottie")]
playhead: 0.0,
#[cfg(feature = "lottie")]
alpha: *alpha,
});
}
}
Expand Down
33 changes: 29 additions & 4 deletions src/render/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ use bevy::{
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
window::{WindowResized, WindowResolution},
};
use vello::{kurbo::Affine, AaSupport, RenderParams, Renderer, RendererOptions, Scene};
use vello::{
kurbo::{Affine, Rect},
peniko::Mix,
AaSupport, RenderParams, Renderer, RendererOptions, Scene,
};

pub fn setup_image(images: &mut Assets<Image>, window: &WindowResolution) -> Handle<Image> {
let size = Extent3d {
Expand Down Expand Up @@ -133,7 +137,6 @@ pub fn render_scene(
match render_item {
RenderItem::Asset(ExtractedRenderAsset {
asset,
#[cfg(feature = "lottie")]
alpha,
#[cfg(feature = "lottie")]
theme,
Expand All @@ -143,11 +146,29 @@ pub fn render_scene(
}) => match &asset.file {
#[cfg(feature = "svg")]
crate::VectorFile::Svg(scene) => {
// TODO: Apply alpha
if *alpha < 1.0 {
scene_buffer.push_layer(
Mix::Normal,
*alpha,
*affine,
&Rect::new(0.0, 0.0, asset.width as f64, asset.height as f64),
);
}
scene_buffer.append(scene, Some(*affine));
if *alpha < 1.0 {
scene_buffer.pop_layer();
}
}
#[cfg(feature = "lottie")]
crate::VectorFile::Lottie(composition) => {
if *alpha < 1.0 {
scene_buffer.push_layer(
Mix::Normal,
*alpha,
*affine,
&Rect::new(0.0, 0.0, asset.width as f64, asset.height as f64),
);
}
velato_renderer.append(
{
theme
Expand All @@ -158,9 +179,13 @@ pub fn render_scene(
},
*playhead as f64,
*affine,
*alpha as f64,
// TODO: Alpha should probably be removed from the renderer. The current way it works isn't correct.
1.0,
&mut scene_buffer,
);
if *alpha < 1.0 {
scene_buffer.pop_layer();
}
}
#[cfg(not(any(feature = "svg", feature = "lottie")))]
_ => unimplemented!(),
Expand Down

0 comments on commit 9067f20

Please sign in to comment.