Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ smallvec = "1.11.0"
bitflags = "2.3"

[dependencies.bevy]
version = "0.13"
default_features = false
version = "0.14"
default-features = false
features = [
"bevy_core_pipeline",
"bevy_render",
Expand All @@ -34,4 +34,4 @@ features = [
]

[dev-dependencies]
bevy = "0.13"
bevy = "0.14"
3 changes: 2 additions & 1 deletion examples/depth.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes;
use bevy::prelude::*;
use bevy_mod_billboard::prelude::*;
use bevy_mod_billboard::BillboardDepth;
Expand Down Expand Up @@ -68,7 +69,7 @@ fn setup_scene(

commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::BEIGE),
material: materials.add(Color::Srgba(palettes::css::BEIGE)),
transform: Transform::from_translation(Vec3::new(1., 0., 0.)),
..default()
});
Expand Down
5 changes: 3 additions & 2 deletions examples/lock_rotation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes;
use bevy::prelude::*;
use bevy_mod_billboard::prelude::*;
use bevy_mod_billboard::BillboardLockAxis;
Expand All @@ -23,7 +24,7 @@ fn setup_billboard(mut commands: Commands, asset_server: Res<AssetServer>) {
style: TextStyle {
font_size: 60.0,
font: fira_sans_regular_handle.clone(),
color: Color::ORANGE,
color: Color::Srgba(palettes::css::ORANGE),
},
},
TextSection {
Expand Down Expand Up @@ -67,7 +68,7 @@ fn setup_scene(

commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::GRAY),
material: materials.add(Color::Srgba(palettes::css::GRAY)),
transform: Transform::from_translation(Vec3::NEG_Y),
..default()
});
Expand Down
5 changes: 3 additions & 2 deletions examples/lock_y.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes;
use bevy::prelude::*;
use bevy_mod_billboard::prelude::*;
use bevy_mod_billboard::{BillboardLockAxis, BillboardLockAxisBundle};
Expand Down Expand Up @@ -49,8 +50,8 @@ fn setup_scene(
) {
commands.spawn(PbrBundle {
transform: Transform::from_scale(Vec3::splat(3.0)),
mesh: meshes.add(Plane3d::new(Vec3::Y)),
material: materials.add(Color::SILVER),
mesh: meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.5))),
material: materials.add(Color::Srgba(palettes::css::SILVER)),
..default()
});

Expand Down
3 changes: 2 additions & 1 deletion examples/stress_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//! and recompute them every frame.

use bevy::{
color::palettes,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
};
Expand Down Expand Up @@ -67,7 +68,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut meshes: Res
TextStyle {
font_size: 60.0,
font: fira_sans_regular_handle.clone(),
color: Color::ORANGE,
color: Color::Srgba(palettes::css::ORANGE),
},
),
..default()
Expand Down
5 changes: 3 additions & 2 deletions examples/text.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes;
use bevy::prelude::*;
use bevy_mod_billboard::prelude::*;

Expand All @@ -20,7 +21,7 @@ fn setup_billboard(mut commands: Commands, asset_server: Res<AssetServer>) {
style: TextStyle {
font_size: 60.0,
font: fira_sans_regular_handle.clone(),
color: Color::ORANGE,
color: Color::Srgba(palettes::css::ORANGE),
},
},
TextSection {
Expand Down Expand Up @@ -59,7 +60,7 @@ fn setup_scene(

commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::GRAY),
material: materials.add(Color::Srgba(palettes::css::GRAY)),
transform: Transform::from_translation(Vec3::NEG_Y),
..default()
});
Expand Down
3 changes: 2 additions & 1 deletion examples/texture.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes;
use bevy::prelude::*;
use bevy_mod_billboard::prelude::*;

Expand Down Expand Up @@ -45,7 +46,7 @@ fn setup_scene(

commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::GRAY),
material: materials.add(Color::Srgba(palettes::css::GRAY)),
transform: Transform::from_translation(Vec3::NEG_Y * 2.),
..default()
});
Expand Down
3 changes: 2 additions & 1 deletion examples/transform_propagation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes;
use bevy::prelude::*;
use bevy_mod_billboard::prelude::*;

Expand Down Expand Up @@ -25,7 +26,7 @@ fn setup_billboard(
.spawn((
PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::GRAY),
material: materials.add(Color::Srgba(palettes::css::GRAY)),
transform: Transform::from_translation(Vec3::new(0.0, -2.0, 1.0)),
..default()
},
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ impl Default for BillboardDepth {
}
}

#[derive(Default, Clone, Copy, Component, Debug, Reflect)]
pub struct Billboard;

#[derive(Default, Clone, Copy, Component, Debug, Reflect)]
pub struct BillboardLockAxis {
pub y_axis: bool,
Expand All @@ -42,6 +45,7 @@ pub struct BillboardLockAxisBundle<T: Bundle> {

#[derive(Bundle, Default)]
pub struct BillboardTextureBundle {
pub billboard: Billboard,
pub mesh: BillboardMeshHandle,
pub texture: BillboardTextureHandle,
pub transform: Transform,
Expand All @@ -54,6 +58,7 @@ pub struct BillboardTextureBundle {

#[derive(Bundle, Default)]
pub struct BillboardTextBundle {
pub billboard: Billboard,
pub text: Text,
pub text_bounds: BillboardTextBounds,
pub text_anchor: Anchor,
Expand Down
35 changes: 19 additions & 16 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::text::RenderBillboard;
use crate::BILLBOARD_SHADER_HANDLE;
use crate::{Billboard, BILLBOARD_SHADER_HANDLE};
use bevy::asset::AssetId;
use bevy::core_pipeline::core_3d::Transparent3d;
use bevy::ecs::query::ROQueryItem;
Expand All @@ -12,11 +12,11 @@ use bevy::prelude::{
ResMut, Resource, With, World,
};
use bevy::render::extract_component::{ComponentUniforms, DynamicUniformIndex};
use bevy::render::mesh::{GpuBufferInfo, MeshVertexBufferLayout, PrimitiveTopology};
use bevy::render::mesh::{GpuBufferInfo, GpuMesh, MeshVertexBufferLayoutRef, PrimitiveTopology};
use bevy::render::render_asset::RenderAssets;
use bevy::render::render_phase::{
DrawFunctions, RenderCommand, RenderCommandResult, RenderPhase, SetItemPipeline,
TrackedRenderPass,
DrawFunctions, PhaseItemExtraIndex, RenderCommand, RenderCommandResult, SetItemPipeline,
TrackedRenderPass, ViewSortedRenderPhases,
};
use bevy::render::render_resource::{
BindGroup, BindGroupEntry, BindGroupLayout, BindGroupLayoutEntry, BindingResource, BindingType,
Expand All @@ -27,7 +27,7 @@ use bevy::render::render_resource::{
SpecializedMeshPipelines, TextureFormat, TextureSampleType, TextureViewDimension, VertexState,
};
use bevy::render::renderer::RenderDevice;
use bevy::render::texture::BevyDefault;
use bevy::render::texture::{BevyDefault, GpuImage};
use bevy::render::view::{
ExtractedView, ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms, VisibleEntities,
};
Expand Down Expand Up @@ -144,19 +144,16 @@ pub fn prepare_billboard_bind_group(
}

pub fn queue_billboard_texture(
mut views: Query<(
&ExtractedView,
&VisibleEntities,
&mut RenderPhase<Transparent3d>,
)>,
mut views: Query<(Entity, &ExtractedView, &VisibleEntities)>,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent3d>>,
mut pipeline_cache: ResMut<PipelineCache>,
mut image_bind_groups: ResMut<BillboardImageBindGroups>,
mut billboard_pipelines: ResMut<SpecializedMeshPipelines<BillboardPipeline>>,
render_device: Res<RenderDevice>,
transparent_draw_functions: Res<DrawFunctions<Transparent3d>>,
msaa: Res<Msaa>,
billboard_pipeline: Res<BillboardPipeline>,
(gpu_images, gpu_meshes): (Res<RenderAssets<Image>>, Res<RenderAssets<Mesh>>),
(gpu_images, gpu_meshes): (Res<RenderAssets<GpuImage>>, Res<RenderAssets<GpuMesh>>),
events: Res<SpriteAssetEvents>,
billboards: Query<(
&BillboardUniform,
Expand All @@ -177,15 +174,19 @@ pub fn queue_billboard_texture(
};
}

for (view, visible_entities, mut transparent_phase) in &mut views {
for (view_entity, view, visible_entities) in &mut views {
let Some(transparent_phase) = transparent_render_phases.get_mut(&view_entity) else {
continue;
};

let draw_transparent_billboard = transparent_draw_functions
.read()
.get_id::<DrawBillboard>()
.unwrap();

let rangefinder = view.rangefinder3d();

for visible_entity in &visible_entities.entities {
for visible_entity in visible_entities.iter::<With<Billboard>>() {
let Ok((uniform, mesh, image, billboard)) = billboards.get(*visible_entity) else {
continue;
};
Expand Down Expand Up @@ -252,7 +253,7 @@ pub fn queue_billboard_texture(
entity: *visible_entity,
draw_function: draw_transparent_billboard,
batch_range: 0..1,
dynamic_offset: None,
extra_index: PhaseItemExtraIndex::NONE,
distance,
});
}
Expand Down Expand Up @@ -336,7 +337,7 @@ impl SpecializedMeshPipeline for BillboardPipeline {
fn specialize(
&self,
key: Self::Key,
layout: &MeshVertexBufferLayout,
layout: &MeshVertexBufferLayoutRef,
) -> Result<RenderPipelineDescriptor, SpecializedMeshPipelineError> {
const DEF_VERTEX_COLOR: &str = "VERTEX_COLOR";
const DEF_LOCK_Y: &str = "LOCK_Y";
Expand All @@ -348,6 +349,8 @@ impl SpecializedMeshPipeline for BillboardPipeline {
attributes.push(Mesh::ATTRIBUTE_POSITION.at_shader_location(0));
attributes.push(Mesh::ATTRIBUTE_UV_0.at_shader_location(1));

let layout = layout.0.as_ref();

if layout.contains(Mesh::ATTRIBUTE_COLOR) {
shader_defs.push(DEF_VERTEX_COLOR.into());
attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(2));
Expand Down Expand Up @@ -504,7 +507,7 @@ impl<const I: usize> RenderCommand<Transparent3d> for SetBillboardTextureBindGro

pub struct DrawBillboardMesh;
impl RenderCommand<Transparent3d> for DrawBillboardMesh {
type Param = SRes<RenderAssets<Mesh>>;
type Param = SRes<RenderAssets<GpuMesh>>;
type ViewQuery = ();
type ItemQuery = Read<RenderBillboardMesh>;

Expand Down
10 changes: 8 additions & 2 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ use crate::pipeline::{
use crate::text::{extract_billboard_text, update_billboard_text_layout};
use crate::texture::extract_billboard_texture;
use crate::{
BillboardMeshHandle, BillboardTextBounds, BillboardTextureHandle, BILLBOARD_SHADER_HANDLE,
Billboard, BillboardMeshHandle, BillboardTextBounds, BillboardTextureHandle,
BILLBOARD_SHADER_HANDLE,
};
use bevy::prelude::*;
use bevy::render::camera::CameraUpdateSystem;
use bevy::render::extract_component::UniformComponentPlugin;
use bevy::render::render_phase::AddRenderCommand;
use bevy::render::render_resource::SpecializedMeshPipelines;
use bevy::render::view::check_visibility;
use bevy::render::view::VisibilitySystems::CheckVisibility;
use bevy::render::{RenderApp, RenderSet};
use bevy::{asset::load_internal_asset, core_pipeline::core_3d::Transparent3d, render::Render};

Expand All @@ -32,7 +35,10 @@ impl Plugin for BillboardPlugin {
.register_type::<BillboardTextBounds>()
.add_systems(
PostUpdate,
update_billboard_text_layout.ambiguous_with(CameraUpdateSystem),
(
update_billboard_text_layout.ambiguous_with(CameraUpdateSystem),
check_visibility::<With<Billboard>>.in_set(CheckVisibility),
),
);
}

Expand Down
13 changes: 8 additions & 5 deletions src/text.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::pipeline::{RenderBillboardImage, RenderBillboardMesh};
use crate::utils::calculate_billboard_uniform;
use crate::{BillboardDepth, BillboardLockAxis};
use bevy::color::palettes;
use bevy::prelude::*;
use bevy::render::mesh::{Indices, PrimitiveTopology};
use bevy::render::render_asset::RenderAssetUsages;
Expand Down Expand Up @@ -169,7 +170,7 @@ pub fn update_billboard_text_layout(
let mut colors = Vec::with_capacity(info.glyphs.len() * 4);
let mut indices = Vec::with_capacity(info.glyphs.len() * 6);

let mut color = Color::WHITE.as_linear_rgba_f32();
let mut color = palettes::css::WHITE.to_f32_array();
let mut current_section = usize::MAX;

for PositionedGlyph {
Expand All @@ -194,9 +195,10 @@ pub fn update_billboard_text_layout(
[bottom_right.x, top_left.y, 0.0],
]);

let Rect { min, max } = atlas.textures[atlas_info.glyph_index];
let min = min / atlas.size;
let max = max / atlas.size;
let URect { min, max } = atlas.textures[atlas_info.glyph_index];
let atlas_size = atlas.size.as_vec2();
let min = min.as_vec2() / atlas_size;
let max = max.as_vec2() / atlas_size;

uvs.extend([
[min.x, max.y],
Expand All @@ -209,7 +211,8 @@ pub fn update_billboard_text_layout(
color = text.sections[section_index]
.style
.color
.as_linear_rgba_f32();
.to_linear()
.to_f32_array();
current_section = section_index;
}

Expand Down