Skip to content

Commit

Permalink
Update to 0.15 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
d28n authored Dec 16, 2024
1 parent 4834006 commit 1b27619
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 73 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ keywords = ["bevy"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.14.0", default-features = false, features = [
bevy = { version = "0.15.0", default-features = false, features = [
"bevy_render",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_asset",
] }

[dev-dependencies]
bevy = { version = "0.14.0", default-features = false, features = [
bevy = { version = "0.15.0", default-features = false, features = [
"bevy_winit",
"bevy_window",
"x11",
"tonemapping_luts",
"ktx2",
Expand Down
47 changes: 22 additions & 25 deletions examples/render_layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,36 @@ fn setup_system(
commands.spawn((InfiniteGridBundle::default(), RenderLayers::layer(1)));

commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 4.37, 14.77),
Camera3d::default(),
Camera {
hdr: true,
..default()
},
Transform::from_xyz(0.0, 4.37, 14.77),
RenderLayers::layer(1),
));

commands.spawn(DirectionalLightBundle {
transform: Transform::from_translation(Vec3::X * 15. + Vec3::Y * 20.)
.looking_at(Vec3::ZERO, Vec3::Y),
..default()
});

let mat = standard_materials.add(StandardMaterial::default());
commands.spawn((
DirectionalLight {
..default()
},
Transform::from_translation(Vec3::X * 15. + Vec3::Y * 20.).looking_at(Vec3::ZERO, Vec3::Y),
));

// cube
commands.spawn(PbrBundle {
material: mat.clone(),
mesh: meshes.add(Cuboid::from_size(Vec3::ONE).mesh()),
transform: Transform {
translation: Vec3::new(3., 4., 0.),
rotation: Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()),
scale: Vec3::splat(1.5),
},
..default()
});
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(standard_materials.add(StandardMaterial::default())),
Transform::from_xyz(3.0, 4.0, 0.0)
.with_rotation(Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()))
.with_scale(Vec3::splat(1.5)),
));

commands.spawn(PbrBundle {
material: mat.clone(),
mesh: meshes.add(Cuboid::from_size(Vec3::ONE).mesh()),
transform: Transform::from_xyz(0.0, 2.0, 0.0),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(standard_materials.add(StandardMaterial::default())),
Transform::from_xyz(0.0, 2.0, 0.0),
));
}

fn toggle_layers(mut q: Query<&mut RenderLayers, With<Camera>>, input: Res<ButtonInput<KeyCode>>) {
Expand Down
56 changes: 25 additions & 31 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,37 @@ fn setup_system(
commands.spawn(InfiniteGridBundle::default());

commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 4.37, 14.77),
camera: Camera {
hdr: true,
..default()
},
Camera3d::default(),
Camera {
hdr: true,
..default()
},
Transform::from_xyz(0.0, 4.37, 14.77),
CameraController::default(),
));

commands.spawn((
DirectionalLight {
..default()
},
Transform::from_translation(Vec3::X * 15. + Vec3::Y * 20.).looking_at(Vec3::ZERO, Vec3::Y),
));

commands.spawn(DirectionalLightBundle {
transform: Transform::from_translation(Vec3::X * 15. + Vec3::Y * 20.)
.looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
// cube
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(standard_materials.add(StandardMaterial::default())),
Transform::from_xyz(3.0, 4.0, 0.0)
.with_rotation(Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()))
.with_scale(Vec3::splat(1.5)),
));

let mat = standard_materials.add(StandardMaterial::default());
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(standard_materials.add(StandardMaterial::default())),
Transform::from_xyz(0.0, 2.0, 0.0),
));

// cube
commands.spawn(PbrBundle {
material: mat.clone(),
mesh: meshes.add(Cuboid::from_size(Vec3::ONE).mesh()),
transform: Transform {
translation: Vec3::new(3., 4., 0.),
rotation: Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()),
scale: Vec3::splat(1.5),
},
..default()
});

commands.spawn(PbrBundle {
material: mat.clone(),
mesh: meshes.add(Cuboid::from_size(Vec3::ONE).mesh()),
transform: Transform::from_xyz(0.0, 2.0, 0.0),
..default()
});
}

// This is a simplified version of the camera controller used in bevy examples
Expand Down Expand Up @@ -96,7 +90,7 @@ mod camera_controller {
key_input: Res<ButtonInput<KeyCode>>,
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
) {
let dt = time.delta_seconds();
let dt = time.delta_secs();

if let Ok((mut transform, mut state)) = query.get_single_mut() {
// Handle key input
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
profile = "default"
channel = "1.79"
channel = "1.82"
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
mod render;

use bevy::prelude::*;
use bevy::render::view::{check_visibility, NoFrustumCulling, VisibleEntities};
use bevy::{
prelude::*,
render::{
view::{check_visibility, NoFrustumCulling, RenderVisibleEntities},
sync_world::SyncToRenderWorld,
}
};

pub struct InfiniteGridPlugin;

Expand Down Expand Up @@ -52,6 +57,7 @@ pub struct InfiniteGridBundle {
pub visibility: Visibility,
pub view_visibility: ViewVisibility,
pub inherited_visibility: InheritedVisibility,
pub shadow_casters: VisibleEntities,
pub shadow_casters: RenderVisibleEntities,
pub no_frustum_culling: NoFrustumCulling,
}
pub sync_to_render_world: SyncToRenderWorld
}
21 changes: 11 additions & 10 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ use bevy::{
StencilFaceState, StencilState, TextureFormat, VertexState,
},
renderer::{RenderDevice, RenderQueue},
texture::BevyDefault,
view::{ExtractedView, ViewTarget, VisibleEntities},
view::{ExtractedView, ViewTarget, RenderVisibleEntities},
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
sync_world::RenderEntity,
},
image::BevyDefault,
};

use crate::InfiniteGridSettings;
Expand Down Expand Up @@ -196,7 +197,7 @@ impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetInfiniteGridBindGroup
) -> RenderCommandResult {
let Some(base_offsets) = base_offsets else {
warn!("PerCameraSettingsUniformOffset missing");
return RenderCommandResult::Failure;
return RenderCommandResult::Skip;
};
pass.set_bind_group(
I,
Expand Down Expand Up @@ -285,10 +286,10 @@ fn extract_infinite_grids(
mut commands: Commands,
grids: Extract<
Query<(
Entity,
RenderEntity,
&InfiniteGridSettings,
&GlobalTransform,
&VisibleEntities,
&RenderVisibleEntities,
)>,
>,
) {
Expand All @@ -312,7 +313,7 @@ fn extract_infinite_grids(

fn extract_per_camera_settings(
mut commands: Commands,
cameras: Extract<Query<(Entity, &InfiniteGridSettings), With<Camera>>>,
cameras: Extract<Query<(RenderEntity, &InfiniteGridSettings), With<Camera>>>,
) {
let extracted: Vec<_> = cameras
.iter()
Expand Down Expand Up @@ -400,15 +401,14 @@ fn queue_infinite_grids(
mut pipelines: ResMut<SpecializedRenderPipelines<InfiniteGridPipeline>>,
infinite_grids: Query<&ExtractedInfiniteGrid>,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent3d>>,
mut views: Query<(Entity, &VisibleEntities, &ExtractedView)>,
msaa: Res<Msaa>,
mut views: Query<(Entity, &RenderVisibleEntities, &ExtractedView, &Msaa), With<ExtractedView>>,
) {
let draw_function_id = transparent_draw_functions
.read()
.get_id::<DrawInfiniteGrid>()
.unwrap();

for (view_entity, entities, view) in views.iter_mut() {
for (view_entity, entities, view, msaa) in views.iter_mut() {
let Some(phase) = transparent_render_phases.get_mut(&view_entity) else {
continue;
};
Expand All @@ -424,7 +424,7 @@ fn queue_infinite_grids(
);
for &entity in entities.iter::<With<InfiniteGridSettings>>() {
if !infinite_grids
.get(entity)
.get(entity.0)
.map(|grid| plane_check(&grid.transform, view.world_from_view.translation()))
.unwrap_or(false)
{
Expand Down Expand Up @@ -553,6 +553,7 @@ impl SpecializedRenderPipeline for InfiniteGridPipeline {
write_mask: ColorWrites::ALL,
})],
}),
zero_initialize_workgroup_memory: false,
}
}
}

0 comments on commit 1b27619

Please sign in to comment.