Skip to content

Commit

Permalink
Merge pull request #49 from ForesightMiningSoftwareCorporation/v0.7-r…
Browse files Browse the repository at this point in the history
…elease

v0.7
  • Loading branch information
aevyrie authored Jul 11, 2023
2 parents 7d12a7c + 9f8c72a commit 67fdd2d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 69 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "bevy_polyline"
version = "0.6.0"
version = "0.7.0"
description = "Polyline Rendering for Bevy"
license = "MIT OR Apache-2.0"
repository = "https://github.com/ForesightMiningSoftwareCorporation/bevy_polyline"
Expand All @@ -17,24 +17,24 @@ authors = [
]

[dependencies]
bitflags = "1.3"
bitflags = "2.3"
bevy = { version = "0.11.0", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_pbr",
"bevy_asset",
] }

[dependencies.naga]
features = ["glsl-in", "spv-out", "wgsl-out"]
version = "0.11"
version = "0.12"

[dev-dependencies]
lazy_static = "1.4.0"
rand = "0.8.4"
ringbuffer = "0.12"
ringbuffer = "0.14"
bevy = { version = "0.11.0", default-features = false, features = [
"bevy_winit",
"bevy_pbr",
"x11",
"tonemapping_luts",
"ktx2",
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.11 | 0.7 |
| 0.10 | 0.5, 0.6 |
| 0.9 | 0.4 |
| 0.8 | 0.3 |
Expand Down
48 changes: 48 additions & 0 deletions src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,51 @@ pub fn queue_material_polylines(
}
}
}

/// Sets how a material's base color alpha channel is used for transparency.
#[derive(Debug, Default, Reflect, Copy, Clone, PartialEq)]
#[reflect(Default, Debug)]
pub enum AlphaMode {
/// Base color alpha values are overridden to be fully opaque (1.0).
#[default]
Opaque,
/// Reduce transparency to fully opaque or fully transparent
/// based on a threshold.
///
/// Compares the base color alpha value to the specified threshold.
/// If the value is below the threshold,
/// considers the color to be fully transparent (alpha is set to 0.0).
/// If it is equal to or above the threshold,
/// considers the color to be fully opaque (alpha is set to 1.0).
Mask(f32),
/// The base color alpha value defines the opacity of the color.
/// Standard alpha-blending is used to blend the fragment's color
/// with the color behind it.
Blend,
/// Similar to [`AlphaMode::Blend`], however assumes RGB channel values are
/// [premultiplied](https://en.wikipedia.org/wiki/Alpha_compositing#Straight_versus_premultiplied).
///
/// For otherwise constant RGB values, behaves more like [`AlphaMode::Blend`] for
/// alpha values closer to 1.0, and more like [`AlphaMode::Add`] for
/// alpha values closer to 0.0.
///
/// Can be used to avoid “border” or “outline” artifacts that can occur
/// when using plain alpha-blended textures.
Premultiplied,
/// Combines the color of the fragments with the colors behind them in an
/// additive process, (i.e. like light) producing lighter results.
///
/// Black produces no effect. Alpha values can be used to modulate the result.
///
/// Useful for effects like holograms, ghosts, lasers and other energy beams.
Add,
/// Combines the color of the fragments with the colors behind them in a
/// multiplicative process, (i.e. like pigments) producing darker results.
///
/// White produces no effect. Alpha values can be used to modulate the result.
///
/// Useful for effects like stained glass, window tint film and some colored liquids.
Multiply,
}

impl Eq for AlphaMode {}
74 changes: 10 additions & 64 deletions src/polyline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use bevy::{
SystemParamItem,
},
},
pbr::{GlobalLightMeta, LightMeta, ViewClusterBindings, ViewShadowBindings},
prelude::*,
reflect::{TypePath, TypeUuid},
render::{
Expand Down Expand Up @@ -300,6 +299,7 @@ impl SpecializedRenderPipeline for PolylinePipeline {

bitflags::bitflags! {
#[repr(transparent)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
// NOTE: Apparently quadro drivers support up to 64x MSAA.
// MSAA uses the highest 3 bits for the MSAA log2(sample count) to support up to 128x MSAA.
pub struct PolylinePipelineKey: u32 {
Expand All @@ -318,11 +318,11 @@ impl PolylinePipelineKey {
pub fn from_msaa_samples(msaa_samples: u32) -> Self {
let msaa_bits =
(msaa_samples.trailing_zeros() & Self::MSAA_MASK_BITS) << Self::MSAA_SHIFT_BITS;
Self::from_bits(msaa_bits).unwrap()
Self::from_bits_retain(msaa_bits)
}

pub fn msaa_samples(&self) -> u32 {
1 << ((self.bits >> Self::MSAA_SHIFT_BITS) & Self::MSAA_MASK_BITS)
1 << ((self.bits() >> Self::MSAA_SHIFT_BITS) & Self::MSAA_MASK_BITS)
}

pub fn from_hdr(hdr: bool) -> Self {
Expand Down Expand Up @@ -369,70 +369,16 @@ pub fn queue_polyline_view_bind_groups(
mut commands: Commands,
render_device: Res<RenderDevice>,
polyline_pipeline: Res<PolylinePipeline>,
light_meta: Res<LightMeta>,
global_light_meta: Res<GlobalLightMeta>,
view_uniforms: Res<ViewUniforms>,
views: Query<(Entity, &ViewShadowBindings, &ViewClusterBindings)>,
views: Query<Entity, With<bevy::render::view::ExtractedView>>,
) {
if let (Some(view_binding), Some(_light_binding), Some(_point_light_binding)) = (
view_uniforms.uniforms.binding(),
light_meta.view_gpu_lights.binding(),
global_light_meta.gpu_point_lights.binding(),
) {
for (entity, _view_shadow_bindings, _view_cluster_bindings) in views.iter() {
if let Some(view_binding) = view_uniforms.uniforms.binding() {
for entity in views.iter() {
let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor {
entries: &[
BindGroupEntry {
binding: 0,
resource: view_binding.clone(),
},
/* Can add these bindings in the future if needed
BindGroupEntry {
binding: 1,
resource: light_binding.clone(),
},
BindGroupEntry {
binding: 2,
resource: BindingResource::TextureView(
&view_shadow_bindings.point_light_depth_texture_view,
),
},
BindGroupEntry {
binding: 3,
resource: BindingResource::Sampler(&shadow_pipeline.point_light_sampler),
},
BindGroupEntry {
binding: 4,
resource: BindingResource::TextureView(
&view_shadow_bindings.directional_light_depth_texture_view,
),
},
BindGroupEntry {
binding: 5,
resource: BindingResource::Sampler(
&shadow_pipeline.directional_light_sampler,
),
},
BindGroupEntry {
binding: 6,
resource: point_light_binding.clone(),
},
BindGroupEntry {
binding: 7,
resource: view_cluster_bindings
.cluster_light_index_lists
.binding()
.unwrap(),
},
BindGroupEntry {
binding: 8,
resource: view_cluster_bindings
.cluster_offsets_and_counts
.binding()
.unwrap(),
},
*/
],
entries: &[BindGroupEntry {
binding: 0,
resource: view_binding.clone(),
}],
label: Some("polyline_view_bind_group"),
layout: &polyline_pipeline.view_layout,
});
Expand Down

0 comments on commit 67fdd2d

Please sign in to comment.