Skip to content

Commit

Permalink
Prepare for crate release 0.10 (#64)
Browse files Browse the repository at this point in the history
* Minor clean ups

* clean up queue_material

* bump version

* update README
  • Loading branch information
IceSentry authored Jul 9, 2024
1 parent 236257b commit d811580
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "bevy_polyline"
version = "0.9.0"
version = "0.10.0"
description = "Polyline Rendering for Bevy"
license = "MIT OR Apache-2.0"
repository = "https://github.com/ForesightMiningSoftwareCorporation/bevy_polyline"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ We intend to track the `main` branch of Bevy. PRs supporting this are welcome!

| bevy | bevy_polyline |
| ---- | ------------- |
| 0.14 | 0.10 |
| 0.13 | 0.9 |
| 0.12 | 0.8 |
| 0.11 | 0.7 |
Expand Down
3 changes: 2 additions & 1 deletion examples/depth_bias.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::f32::consts::TAU;
use std::f64::consts::TAU as TAU64;

use bevy::color::palettes::css::RED;
use bevy::prelude::*;
use bevy_polyline::prelude::*;

Expand Down Expand Up @@ -80,7 +81,7 @@ fn setup(
}),
material: materials.add(PolylineMaterial {
width: 5.0,
color: bevy::color::palettes::css::RED.into(),
color: RED.into(),
depth_bias: -1.0,
perspective: false,
}),
Expand Down
4 changes: 2 additions & 2 deletions examples/linestrip.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{pbr::PointLightBundle, prelude::*};
use bevy::{color::palettes::css::RED, pbr::PointLightBundle, prelude::*};
use bevy_polyline::prelude::*;

fn main() {
Expand Down Expand Up @@ -33,7 +33,7 @@ fn setup(
}),
material: polyline_materials.add(PolylineMaterial {
width: 2.0,
color: bevy::color::palettes::css::RED.into(),
color: RED.into(),
perspective: false,
// Bias the line toward the camera so the line at the cube-plane intersection is visible
depth_bias: -0.0002,
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{color::palettes::css::RED, prelude::*};
use bevy_polyline::prelude::*;

fn main() {
Expand All @@ -20,7 +20,7 @@ fn setup(
}),
material: polyline_materials.add(PolylineMaterial {
width: 10.0,
color: bevy::color::palettes::css::RED.into(),
color: RED.into(),
perspective: false,
..default()
}),
Expand Down
4 changes: 2 additions & 2 deletions examples/perspective.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{color::palettes::css::RED, prelude::*};
use bevy_polyline::prelude::*;

fn main() {
Expand All @@ -21,7 +21,7 @@ fn setup(
}),
material: polyline_materials.add(PolylineMaterial {
width: 10.0,
color: bevy::color::palettes::css::RED.into(),
color: RED.into(),
perspective: true,
..default()
}),
Expand Down
97 changes: 44 additions & 53 deletions src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,13 @@ pub fn queue_material_polylines(
mut alpha_mask_phases: ResMut<ViewBinnedRenderPhases<AlphaMask3d>>,
mut transparent_phases: ResMut<ViewSortedRenderPhases<Transparent3d>>,
) {
let draw_opaque = opaque_draw_functions
.read()
.get_id::<DrawPolylineMaterial>()
.unwrap();
let draw_opaque = opaque_draw_functions.read().id::<DrawPolylineMaterial>();
let draw_alpha_mask = alpha_mask_draw_functions
.read()
.get_id::<DrawPolylineMaterial>()
.unwrap();
.id::<DrawPolylineMaterial>();
let draw_transparent = transparent_draw_functions
.read()
.get_id::<DrawPolylineMaterial>()
.unwrap();
.id::<DrawPolylineMaterial>();

for (view_entity, view, visible_entities) in &views {
let inverse_view_matrix = view.world_from_view.compute_matrix().inverse();
Expand All @@ -329,64 +324,60 @@ pub fn queue_material_polylines(
let pipeline_id =
pipelines.specialize(&pipeline_cache, &material_pipeline, polyline_key);

let (mut opaque_phase, mut alpha_mask_phase, mut transparent_phase) = (
let (Some(opaque_phase), Some(alpha_mask_phase), Some(transparent_phase)) = (
opaque_phases.get_mut(&view_entity),
alpha_mask_phases.get_mut(&view_entity),
transparent_phases.get_mut(&view_entity),
);
) else {
continue;
};

// NOTE: row 2 of the inverse view matrix dotted with column 3 of the model matrix
// gives the z component of translation of the mesh in view space
let polyline_z = inverse_view_row_2.dot(polyline_uniform.transform.col(3));
match material.alpha_mode {
AlphaMode::Opaque => {
if let Some(opaque_phase) = opaque_phase.as_mut() {
opaque_phase.add(
Opaque3dBinKey {
pipeline: pipeline_id,
draw_function: draw_opaque,
// The draw command doesn't use a mesh handle so we don't need an `asset_id`
asset_id: AssetId::<Mesh>::invalid().untyped(),
material_bind_group_id: Some(material.bind_group.id()),
lightmap_image: None,
},
*visible_entity,
BinnedRenderPhaseType::NonMesh,
);
}
opaque_phase.add(
Opaque3dBinKey {
pipeline: pipeline_id,
draw_function: draw_opaque,
// The draw command doesn't use a mesh handle so we don't need an `asset_id`
asset_id: AssetId::<Mesh>::invalid().untyped(),
material_bind_group_id: Some(material.bind_group.id()),
lightmap_image: None,
},
*visible_entity,
BinnedRenderPhaseType::NonMesh,
);
}
AlphaMode::Mask(_) => {
if let Some(alpha_mask_phase) = alpha_mask_phase.as_mut() {
alpha_mask_phase.add(
OpaqueNoLightmap3dBinKey {
draw_function: draw_alpha_mask,
pipeline: pipeline_id,
asset_id: AssetId::<Mesh>::invalid().untyped(),
material_bind_group_id: Some(material.bind_group.id()),
},
*visible_entity,
BinnedRenderPhaseType::NonMesh,
);
}
alpha_mask_phase.add(
OpaqueNoLightmap3dBinKey {
draw_function: draw_alpha_mask,
pipeline: pipeline_id,
asset_id: AssetId::<Mesh>::invalid().untyped(),
material_bind_group_id: Some(material.bind_group.id()),
},
*visible_entity,
BinnedRenderPhaseType::NonMesh,
);
}
AlphaMode::Blend
| AlphaMode::Premultiplied
| AlphaMode::Add
| AlphaMode::Multiply => {
if let Some(transparent_phase) = transparent_phase.as_mut() {
transparent_phase.add(Transparent3d {
entity: *visible_entity,
draw_function: draw_transparent,
pipeline: pipeline_id,
// NOTE: Back-to-front ordering for transparent with ascending sort means far should have the
// lowest sort key and getting closer should increase. As we have
// -z in front of the camera, the largest distance is -far with values increasing toward the
// camera. As such we can just use mesh_z as the distance
distance: polyline_z,
batch_range: 0..1,
extra_index: PhaseItemExtraIndex::NONE,
});
}
// NOTE: row 2 of the inverse view matrix dotted with column 3 of the model matrix
// gives the z component of translation of the mesh in view space
let polyline_z = inverse_view_row_2.dot(polyline_uniform.transform.col(3));
transparent_phase.add(Transparent3d {
entity: *visible_entity,
draw_function: draw_transparent,
pipeline: pipeline_id,
// NOTE: Back-to-front ordering for transparent with ascending sort means far should have the
// lowest sort key and getting closer should increase. As we have
// -z in front of the camera, the largest distance is -far with values increasing toward the
// camera. As such we can just use mesh_z as the distance
distance: polyline_z,
batch_range: 0..1,
extra_index: PhaseItemExtraIndex::NONE,
});
}
}
}
Expand Down

0 comments on commit d811580

Please sign in to comment.