Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to bevy 0.14 #61

Merged
merged 10 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -8,7 +8,7 @@ default = ["egui"]
egui = ["dep:bevy-inspector-egui"]

[dependencies]
bevy = { version = "0.13", default-features = false, features = [
bevy = { version = "0.14.1", default-features = false, features = [
"bevy_render",
"bevy_core_pipeline",
"bevy_winit",
Expand All @@ -17,12 +17,12 @@ bevy = { version = "0.13", default-features = false, features = [
"bevy_pbr",
"embedded_watcher",
] }
bevy-inspector-egui = { version = "0.23.0", optional = true }
bevy-inspector-egui = { version = "0.25.2", optional = true }
log = "0.4.20"
rand = "0.8.5"

[dev-dependencies]
bevy = "0.13"
bevy = "0.14.1"

[profile.release]
codegen-units = 1
Expand Down
198 changes: 97 additions & 101 deletions examples/krypta.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main()
{
// Basic setup.
App::new()
.insert_resource(ClearColor(Color::rgb_u8(255, 255, 255)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rgb_u8 is deprecated in bevy 0.14 now

.insert_resource(ClearColor(Color::srgba_u8(255, 255, 255, 0)))
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
Expand Down Expand Up @@ -74,7 +74,7 @@ fn setup(mut commands: Commands, camera_targets: Res<CameraTargets>)
"left",
OmniLightSource2D {
intensity: 1.0,
color: Color::rgb_u8(255, 0, 0),
color: Color::srgb_u8(255, 0, 0),
falloff: Vec3::new(1.5, 10.0, 0.005),
..default()
},
Expand All @@ -86,7 +86,7 @@ fn setup(mut commands: Commands, camera_targets: Res<CameraTargets>)
"right",
OmniLightSource2D {
intensity: 1.0,
color: Color::rgb_u8(0, 0, 255),
color: Color::srgb_u8(0, 0, 255),
falloff: Vec3::new(1.5, 10.0, 0.005),
..default()
},
Expand All @@ -98,7 +98,7 @@ fn setup(mut commands: Commands, camera_targets: Res<CameraTargets>)
"rop",
OmniLightSource2D {
intensity: 1.0,
color: Color::rgb_u8(0, 255, 0),
color: Color::srgb_u8(0, 255, 0),
falloff: Vec3::new(1.5, 10.0, 0.005),
..default()
},
Expand Down
6 changes: 3 additions & 3 deletions examples/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main()
{
// Basic setup.
App::new()
.insert_resource(ClearColor(Color::rgb_u8(255, 255, 255)))
.insert_resource(ClearColor(Color::srgba_u8(255, 255, 255, 0)))
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
Expand Down Expand Up @@ -92,7 +92,7 @@ fn setup(mut commands: Commands, camera_targets: Res<CameraTargets>)
"left",
OmniLightSource2D {
intensity: 10.0,
color: Color::rgb_u8(255, 255, 0),
color: Color::srgb_u8(255, 255, 0),
falloff: Vec3::new(1.5, 10.0, 0.01),
..default()
},
Expand All @@ -104,7 +104,7 @@ fn setup(mut commands: Commands, camera_targets: Res<CameraTargets>)
"right",
OmniLightSource2D {
intensity: 10.0,
color: Color::rgb_u8(0, 255, 255),
color: Color::srgb_u8(0, 255, 255),
falloff: Vec3::new(1.5, 10.0, 0.01),
..default()
},
Expand Down
19 changes: 10 additions & 9 deletions src/gi/compositing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::core_pipeline::bloom::BloomSettings;
use bevy::pbr::{MAX_CASCADES_PER_LIGHT, MAX_DIRECTIONAL_LIGHTS};
use bevy::prelude::*;
use bevy::reflect::TypePath;
use bevy::render::mesh::MeshVertexBufferLayout;
use bevy::render::mesh::MeshVertexBufferLayoutRef;
use bevy::render::render_resource::{
AsBindGroup,
Extent3d,
Expand All @@ -21,6 +21,7 @@ use bevy::sprite::{Material2d, Material2dKey, MaterialMesh2dBundle};

use crate::gi::constants::{POST_PROCESSING_MATERIAL, POST_PROCESSING_RECT};
use crate::gi::pipeline::GiTargetsWrapper;
use crate::gi::render_layer;
use crate::gi::resource::ComputedTargetSizes;

#[derive(Component)]
Expand Down Expand Up @@ -138,9 +139,9 @@ impl CameraTargets
let walls_image_handle: Handle<Image> = Handle::weak_from_u128(7264512947825624361);
let objects_image_handle: Handle<Image> = Handle::weak_from_u128(2987462343287146234);

images.insert(floor_image_handle.clone(), floor_image);
images.insert(walls_image_handle.clone(), walls_image);
images.insert(objects_image_handle.clone(), objects_image);
images.insert(floor_image_handle.id(), floor_image);
images.insert(walls_image_handle.id(), walls_image);
images.insert(objects_image_handle.id(), objects_image);

Self {
floor_target: floor_image_handle,
Expand All @@ -157,7 +158,7 @@ impl Material2d for PostProcessingMaterial {

fn specialize(
descriptor: &mut RenderPipelineDescriptor,
_layout: &MeshVertexBufferLayout,
_layout: &MeshVertexBufferLayoutRef,
_key: Material2dKey<Self>,
) -> Result<(), SpecializedMeshPipelineError>
{
Expand Down Expand Up @@ -195,16 +196,16 @@ pub fn setup_post_processing_camera(
target_sizes.primary_target_size.y,
));

meshes.insert(POST_PROCESSING_RECT.clone(), quad);
meshes.insert(POST_PROCESSING_RECT.id(), quad);

*camera_targets = CameraTargets::create(&mut images, &target_sizes);

let material = PostProcessingMaterial::create(&camera_targets, &gi_targets_wrapper);
materials.insert(POST_PROCESSING_MATERIAL.clone(), material);
materials.insert(POST_PROCESSING_MATERIAL.id(), material);

// This specifies the layer used for the post processing camera, which
// will be attached to the post processing camera and 2d quad.
let layer = RenderLayers::layer((RenderLayers::TOTAL_LAYERS - 1) as u8);
let layer = RenderLayers::from_layers(render_layer::CAMERA_LAYER_POST_PROCESSING);

commands.spawn((
PostProcessingQuad,
Expand All @@ -217,7 +218,7 @@ pub fn setup_post_processing_camera(
},
..default()
},
layer,
layer.clone(),
));

commands.spawn((
Expand Down
6 changes: 3 additions & 3 deletions src/gi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Plugin for BevyMagicLight2DPlugin
),
);

let mut render_graph = render_app.world.resource_mut::<RenderGraph>();
let mut render_graph = render_app.world_mut().resource_mut::<RenderGraph>();
render_graph.add_node(LightPass2DRenderLabel, LightPass2DNode::default());
render_graph.add_node_edge(
LightPass2DRenderLabel,
Expand Down Expand Up @@ -138,15 +138,15 @@ pub fn handle_window_resize(
ComputedTargetSizes::from_window(window, &res_plugin_config.target_scaling_params);

assets_mesh.insert(
POST_PROCESSING_RECT.clone(),
POST_PROCESSING_RECT.id(),
Mesh::from(bevy::math::primitives::Rectangle::new(
res_target_sizes.primary_target_size.x,
res_target_sizes.primary_target_size.y,
)),
);

assets_material.insert(
POST_PROCESSING_MATERIAL.clone(),
POST_PROCESSING_MATERIAL.id(),
PostProcessingMaterial::create(&res_camera_targets, &res_gi_targets_wrapper),
);

Expand Down
21 changes: 8 additions & 13 deletions src/gi/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ use bevy::render::extract_resource::ExtractResource;
use bevy::render::render_asset::{RenderAssetUsages, RenderAssets};
use bevy::render::render_resource::*;
use bevy::render::renderer::RenderDevice;
use bevy::render::texture::{
ImageAddressMode,
ImageFilterMode,
ImageSampler,
ImageSamplerDescriptor,
};
use bevy::render::texture::{GpuImage, ImageAddressMode, ImageFilterMode, ImageSampler, ImageSamplerDescriptor};

use crate::gi::pipeline_assets::{LightPassPipelineAssets, load_embedded_shader};
use crate::gi::resource::ComputedTargetSizes;
Expand Down Expand Up @@ -94,12 +89,12 @@ impl GiTargets
let ss_filter_target: Handle<Image> = Handle::weak_from_u128(8761232615172413412);
let ss_pose_target: Handle<Image> = Handle::weak_from_u128(4728165084756128470);

images.insert(sdf_target.clone(), sdf_tex);
images.insert(ss_probe_target.clone(), ss_probe_tex);
images.insert(ss_bounce_target.clone(), ss_bounce_tex);
images.insert(ss_blend_target.clone(), ss_blend_tex);
images.insert(ss_filter_target.clone(), ss_filter_tex);
images.insert(ss_pose_target.clone(), ss_pose_tex);
images.insert(sdf_target.id(), sdf_tex);
images.insert(ss_probe_target.id(), ss_probe_tex);
images.insert(ss_bounce_target.id(), ss_bounce_tex);
images.insert(ss_blend_target.id(), ss_blend_tex);
images.insert(ss_filter_target.id(), ss_filter_tex);
images.insert(ss_pose_target.id(), ss_pose_tex);

Self {
sdf_target,
Expand Down Expand Up @@ -184,7 +179,7 @@ pub struct LightPassPipeline
pub fn system_queue_bind_groups(
mut commands: Commands,
pipeline: Res<LightPassPipeline>,
gpu_images: Res<RenderAssets<Image>>,
gpu_images: Res<RenderAssets<GpuImage>>,
targets_wrapper: Res<GiTargetsWrapper>,
gi_compute_assets: Res<LightPassPipelineAssets>,
render_device: Res<RenderDevice>,
Expand Down
15 changes: 8 additions & 7 deletions src/gi/pipeline_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn system_extract_pipeline_assets(
res_light_settings: Extract<Res<BevyMagicLight2DSettings>>,
res_target_sizes: Extract<Res<ComputedTargetSizes>>,

query_lights: Extract<Query<(&GlobalTransform, &OmniLightSource2D, &InheritedVisibility, &ViewVisibility)>>,
query_lights: Extract<Query<(&GlobalTransform, &OmniLightSource2D, &InheritedVisibility)>>,
query_occluders: Extract<Query<(&LightOccluder2D, &GlobalTransform, &Transform, &InheritedVisibility, &ViewVisibility)>>,
query_camera: Extract<Query<(&Camera, &GlobalTransform), With<FloorCamera>>>,
query_masks: Extract<Query<(&GlobalTransform, &SkylightMask2D)>>,
Expand All @@ -108,8 +108,8 @@ pub fn system_extract_pipeline_assets(
let mut rng = thread_rng();
light_sources.count = 0;
light_sources.data.clear();
for (transform, light_source, hviz, vviz) in query_lights.iter() {
if hviz.get() && vviz.get() {
for (transform, light_source, hviz) in query_lights.iter() {
if hviz.get() {
light_sources.count += 1;
light_sources.data.push(GpuOmniLightSource::new(
OmniLightSource2D {
Expand Down Expand Up @@ -160,7 +160,7 @@ pub fn system_extract_pipeline_assets(
{
if let Ok((camera, camera_global_transform)) = query_camera.get_single() {
let camera_params = gpu_pipeline_assets.camera_params.get_mut();
let projection = camera.projection_matrix();
let projection = camera.clip_from_view();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same method, different name

let inverse_projection = projection.inverse();
let view = camera_global_transform.compute_matrix();
let inverse_view = view.inverse();
Expand Down Expand Up @@ -209,9 +209,10 @@ pub fn system_extract_pipeline_assets(
let light_pass_params = gpu_pipeline_assets.light_pass_params.get_mut();
light_pass_params.skylight_color = Vec3::splat(0.0);
for new_gi_state in query_skylight_light.iter() {
light_pass_params.skylight_color.x += new_gi_state.color.r() * new_gi_state.intensity;
light_pass_params.skylight_color.y += new_gi_state.color.g() * new_gi_state.intensity;
light_pass_params.skylight_color.z += new_gi_state.color.b() * new_gi_state.intensity;
let srgba = new_gi_state.color.to_srgba();
light_pass_params.skylight_color.x += srgba.red * new_gi_state.intensity;
light_pass_params.skylight_color.y += srgba.green * new_gi_state.intensity;
light_pass_params.skylight_color.z += srgba.blue * new_gi_state.intensity;
}
}

Expand Down
21 changes: 18 additions & 3 deletions src/gi/render_layer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
pub const CAMERA_LAYER_FLOOR: &[u8] = &[1];
pub const CAMERA_LAYER_WALLS: &[u8] = &[2];
pub const CAMERA_LAYER_OBJECTS: &[u8] = &[3];
use bevy::render::view::Layer;

pub const LAYER_FLOOR_ID: Layer = 1;
pub const LAYER_WALLS_ID: Layer = 2;
pub const LAYER_OBJECTS_ID: Layer = 3;

pub const CAMERA_LAYER_FLOOR: &[Layer] = &[LAYER_FLOOR_ID];
pub const CAMERA_LAYER_WALLS: &[Layer] = &[LAYER_WALLS_ID];
pub const CAMERA_LAYER_OBJECTS: &[Layer] = &[LAYER_OBJECTS_ID];

pub const ALL_LAYERS: &[Layer] = &[
LAYER_FLOOR_ID,
LAYER_WALLS_ID,
LAYER_OBJECTS_ID,
];

pub const LAYER_POST_PROCESSING_ID: Layer = 42;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of layers is unlimited now. I chose '42' just as some arbitrary large number

pub const CAMERA_LAYER_POST_PROCESSING: &[Layer] = &[LAYER_POST_PROCESSING_ID];
6 changes: 3 additions & 3 deletions src/gi/types_gpu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::{Mat4, Vec2, Vec3, Vec4};
use bevy::prelude::*;
use bevy::render::render_resource::ShaderType;

use crate::gi::constants::GI_SCREEN_PROBE_SIZE;
Expand All @@ -17,11 +17,11 @@ impl GpuOmniLightSource
{
pub fn new(light: OmniLightSource2D, center: Vec2) -> Self
{
let color = light.color.as_rgba_f32();
let color: Srgba = light.color.into();
Self {
center,
intensity: light.intensity,
color: Vec3::new(color[0], color[1], color[2]),
color: color.to_vec3(),
falloff: light.falloff,
}
}
Expand Down