Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Add y_sort_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
darthdeus committed Jan 1, 2024
1 parent 11219ae commit 797d3f5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions comfy-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ pub struct Mesh {
pub indices: SmallVec<[u32; 6]>,
pub z_index: i32,
pub texture: Option<TextureHandle>,
pub y_sort_offset: f32,
}

#[repr(C)]
Expand Down
5 changes: 5 additions & 0 deletions comfy-core/src/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ pub struct DrawTextureProParams {
pub blend_mode: BlendMode,
/// Rotation around the x axis for creating a 3d effect.
pub rotation_x: f32,
/// Offset for y-sorting in world-space. This is useful for when sprites have different
/// sizes and pivots, for example when a tree should be "behind" something based on its bottom-most
/// pixel, and not based on its size.
pub y_sort_offset: f32,
}

impl Default for DrawTextureProParams {
Expand All @@ -199,6 +203,7 @@ impl Default for DrawTextureProParams {
flip_y: false,
blend_mode: Default::default(),
rotation_x: 0.0,
y_sort_offset: 0.0,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion comfy-wgpu/src/batching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ pub fn run_batched_render_passes(

// TODO: add this back later
if get_y_sort(key.z_index) {
meshes.sort_by_key(|mesh| OrderedFloat::<f32>(-mesh.origin.y));
meshes.sort_by_key(|mesh| {
OrderedFloat::<f32>(-(mesh.origin.y + mesh.y_sort_offset))
});
}

render_meshes(
Expand Down

0 comments on commit 797d3f5

Please sign in to comment.