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

(WIP) Update to bevy 0.11 #21

Closed
wants to merge 4 commits into from
Closed
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
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@ keywords = ["gamedev", "bevy", "outline"]
categories = ["game-engines", "rendering"]

[dependencies]
bevy = { version = "0.10", default-features = false, features = [
bevy = { version = "0.11", default-features = false, features = [
"bevy_asset",
"bevy_render",
"bevy_pbr",
"ktx2",
"tonemapping_luts",
"zstd",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"bevy_core_pipeline",
] }
bitfield = "0.14"
interpolation = "0.2"
thiserror = "1.0"
wgpu-types = "0.15"
wgpu-types = "0.16.1"

[dev-dependencies]
bevy = { version = "0.10", default-features = false, features = [
bevy = { version = "0.11", default-features = false, features = [
"animation",
"bevy_gltf",
"bevy_pbr",
"bevy_scene",
"bevy_winit",
"png",
"x11",
] }
bevy_mod_gltf_patched = "0.2"
bevy_mod_gltf_patched = { git = "https://github.com/zainthemaynnn/bevy_mod_gltf_patched/", branch = "bevy-0.11" }

[features]
default = ["bevy_ui"]
Expand Down
9 changes: 3 additions & 6 deletions examples/animated_fox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ struct Fox(Handle<AnimationClip>);

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(OutlinePlugin)
.add_plugin(AutoGenerateOutlineNormalsPlugin)
.add_plugins((DefaultPlugins, OutlinePlugin, AutoGenerateOutlineNormalsPlugin))
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
})
.add_startup_system(setup)
.add_system(setup_scene_once_loaded)
.add_system(close_on_esc)
.add_systems(Startup, setup)
.add_systems(Update, (setup_scene_once_loaded, close_on_esc))
.run();
}

Expand Down
11 changes: 4 additions & 7 deletions examples/hollow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ fn main() {
// Disable built-in glTF plugin
.add_plugins(DefaultPlugins.build().disable::<bevy::gltf::GltfPlugin>())
// Register outline normal vertex attribute with bevy_mod_gltf_patched
.add_plugin(
.add_plugins(
GltfPlugin::default()
.add_custom_vertex_attribute("_OUTLINE_NORMAL", ATTRIBUTE_OUTLINE_NORMAL),
)
.add_plugin(OutlinePlugin)
.add_plugins(OutlinePlugin)
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
})
.add_startup_system(setup)
.add_system(setup_scene_once_loaded)
.add_system(rotates)
.add_system(rotates_hue)
.add_system(close_on_esc)
.add_systems(Startup, setup)
.add_systems(Update, (setup_scene_once_loaded, rotates, rotates_hue, close_on_esc))
.run();
}

Expand Down
8 changes: 3 additions & 5 deletions examples/pieces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.insert_resource(ClearColor(Color::BLACK))
.add_plugins(DefaultPlugins)
.add_plugin(OutlinePlugin)
.add_startup_system(setup)
.add_system(close_on_esc)
.add_system(rotates)
.add_plugins((DefaultPlugins, OutlinePlugin))
.add_systems(Startup, setup)
.add_systems(Update, (close_on_esc, rotates))
.run();
}

Expand Down
8 changes: 3 additions & 5 deletions examples/render_layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.insert_resource(ClearColor(Color::BLACK))
.add_plugins(DefaultPlugins)
.add_plugin(OutlinePlugin)
.add_startup_system(setup)
.add_system(close_on_esc)
.add_system(set_camera_viewports)
.add_plugins((DefaultPlugins, OutlinePlugin))
.add_systems(Startup, setup)
.add_systems(Update, (close_on_esc, set_camera_viewports))
.run();
}

Expand Down
9 changes: 3 additions & 6 deletions examples/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.insert_resource(ClearColor(Color::BLACK))
.add_plugins(DefaultPlugins)
.add_plugin(OutlinePlugin)
.add_startup_system(setup)
.add_system(close_on_esc)
.add_system(wobble)
.add_system(orbit)
.add_plugins((DefaultPlugins, OutlinePlugin))
.add_systems(Startup, setup)
.add_systems(Update, (close_on_esc, wobble, orbit))
.run();
}

Expand Down
6 changes: 4 additions & 2 deletions src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ pub(crate) fn queue_outline_stencil_mesh(
let key = base_key
.with_primitive_topology(mesh.primitive_topology)
.with_depth_mode(stencil_flags.depth_mode)
.with_offset_zero(stencil_uniform.offset == 0.0);
.with_offset_zero(stencil_uniform.offset == 0.0)
.with_morph_targets(mesh.morph_targets.is_some());
let pipeline = pipelines
.specialize(&pipeline_cache, &stencil_pipeline, key, &mesh.layout)
.unwrap();
Expand Down Expand Up @@ -161,7 +162,8 @@ pub(crate) fn queue_outline_volume_mesh(
})
.with_depth_mode(volume_flags.depth_mode)
.with_offset_zero(volume_uniform.offset == 0.0)
.with_hdr_format(view.hdr);
.with_hdr_format(view.hdr)
.with_morph_targets(mesh.morph_targets.is_some());
let pipeline = pipelines
.specialize(&pipeline_cache, &outline_pipeline, key, &mesh.layout)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,6 @@ pub struct AutoGenerateOutlineNormalsPlugin;

impl Plugin for AutoGenerateOutlineNormalsPlugin {
fn build(&self, app: &mut App) {
app.add_system(auto_generate_outline_normals);
app.add_systems(Update, auto_generate_outline_normals);
}
}
95 changes: 56 additions & 39 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use bevy::render::render_graph::RenderGraph;
use bevy::render::render_phase::{sort_phase_system, AddRenderCommand, DrawFunctions};
use bevy::render::render_resource::{SpecializedMeshPipelines, VertexFormat};
use bevy::render::view::RenderLayers;
use bevy::render::{RenderApp, RenderSet};
use bevy::render::{Render, RenderApp, RenderSet};
use bevy::transform::TransformSystem;
use interpolation::Lerp;

Expand Down Expand Up @@ -207,37 +207,55 @@ impl Plugin for OutlinePlugin {
Shader::from_wgsl
);

app.add_plugin(ExtractComponentPlugin::<OutlineStencil>::extract_visible())
.add_plugin(ExtractComponentPlugin::<OutlineRenderLayers>::default())
.add_plugin(UniformComponentPlugin::<OutlineStencilUniform>::default())
.add_plugin(UniformComponentPlugin::<OutlineVolumeUniform>::default())
.add_plugin(UniformComponentPlugin::<OutlineFragmentUniform>::default())
.add_plugin(UniformComponentPlugin::<OutlineViewUniform>::default())
.add_system(
compute_outline_depth
.in_base_set(CoreSet::PostUpdate)
.after(TransformSystem::TransformPropagate),
)
.sub_app_mut(RenderApp)
.init_resource::<DrawFunctions<StencilOutline>>()
.init_resource::<DrawFunctions<OpaqueOutline>>()
.init_resource::<DrawFunctions<TransparentOutline>>()
.init_resource::<OutlinePipeline>()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everything here (and similar add_systems/add_plugins changes) was following the migration guide, including this line but I wanted to point out this one

https://bevyengine.org/learn/migration-guides/0.10-0.11/#webgpu-support

this line actually got removed here and is now done in the finish function on line 282

.init_resource::<SpecializedMeshPipelines<OutlinePipeline>>()
.add_render_command::<StencilOutline, DrawStencil>()
.add_render_command::<OpaqueOutline, DrawOutline>()
.add_render_command::<TransparentOutline, DrawOutline>()
.add_system(extract_outline_view_uniforms.in_schedule(ExtractSchedule))
.add_system(extract_outline_stencil_uniforms.in_schedule(ExtractSchedule))
.add_system(extract_outline_volume_uniforms.in_schedule(ExtractSchedule))
.add_system(sort_phase_system::<StencilOutline>.in_set(RenderSet::PhaseSort))
.add_system(sort_phase_system::<OpaqueOutline>.in_set(RenderSet::PhaseSort))
.add_system(sort_phase_system::<TransparentOutline>.in_set(RenderSet::PhaseSort))
.add_system(queue_outline_view_bind_group.in_set(RenderSet::Queue))
.add_system(queue_outline_stencil_bind_group.in_set(RenderSet::Queue))
.add_system(queue_outline_volume_bind_group.in_set(RenderSet::Queue))
.add_system(queue_outline_stencil_mesh.in_set(RenderSet::Queue))
.add_system(queue_outline_volume_mesh.in_set(RenderSet::Queue));
app.add_plugins((
ExtractComponentPlugin::<OutlineStencil>::extract_visible(),
ExtractComponentPlugin::<OutlineRenderLayers>::default(),
UniformComponentPlugin::<OutlineStencilUniform>::default(),
UniformComponentPlugin::<OutlineVolumeUniform>::default(),
UniformComponentPlugin::<OutlineFragmentUniform>::default(),
UniformComponentPlugin::<OutlineViewUniform>::default(),
))
.add_systems(
PostUpdate,
compute_outline_depth.after(TransformSystem::TransformPropagate),
)
.sub_app_mut(RenderApp)
.init_resource::<DrawFunctions<StencilOutline>>()
.init_resource::<DrawFunctions<OpaqueOutline>>()
.init_resource::<DrawFunctions<TransparentOutline>>()
.init_resource::<SpecializedMeshPipelines<OutlinePipeline>>()
.add_render_command::<StencilOutline, DrawStencil>()
.add_render_command::<OpaqueOutline, DrawOutline>()
.add_render_command::<TransparentOutline, DrawOutline>()
.add_systems(ExtractSchedule, extract_outline_view_uniforms)
.add_systems(ExtractSchedule, extract_outline_stencil_uniforms)
.add_systems(ExtractSchedule, extract_outline_volume_uniforms)
.add_systems(
Render,
sort_phase_system::<StencilOutline>.in_set(RenderSet::PhaseSort),
)
.add_systems(
Render,
sort_phase_system::<OpaqueOutline>.in_set(RenderSet::PhaseSort),
)
.add_systems(
Render,
sort_phase_system::<TransparentOutline>.in_set(RenderSet::PhaseSort),
)
.add_systems(
Render,
queue_outline_view_bind_group.in_set(RenderSet::Queue),
)
.add_systems(
Render,
queue_outline_stencil_bind_group.in_set(RenderSet::Queue),
)
.add_systems(
Render,
queue_outline_volume_bind_group.in_set(RenderSet::Queue),
)
.add_systems(Render, queue_outline_stencil_mesh.in_set(RenderSet::Queue))
.add_systems(Render, queue_outline_volume_mesh.in_set(RenderSet::Queue));

let world = &mut app.sub_app_mut(RenderApp).world;
let node = OutlineNode::new(world);
Expand All @@ -248,16 +266,10 @@ impl Plugin for OutlinePlugin {
.get_sub_graph_mut(bevy::core_pipeline::core_3d::graph::NAME)
.unwrap();
draw_3d_graph.add_node(OUTLINE_PASS_NODE_NAME, node);
draw_3d_graph.add_slot_edge(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

draw_3d_graph.input_node().id,
bevy::core_pipeline::core_3d::graph::input::VIEW_ENTITY,
OUTLINE_PASS_NODE_NAME,
OutlineNode::IN_VIEW,
);

// Run after main 3D pass, but before UI psss
draw_3d_graph.add_node_edge(
bevy::core_pipeline::core_3d::graph::node::MAIN_PASS,
bevy::core_pipeline::core_3d::graph::node::END_MAIN_PASS,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is due to this

bevyengine/bevy#8090

it's listed under the 0.11 update https://bevyengine.org/news/bevy-0-11/#rendering but not in the migration guide.

As I mentioned in the PR description, when I had this set to START_MAIN_PASS, sometimes while running the examples I didn't get outlines at all. END_MAIN_PASS works better but I did notice a bit more transparency than usual in the shapes example.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am pretty sure using END_MAIN_PASS is identical to the old MAIN_PASS in terms of render graph, so this might be a different problem. I'm not sure what that is though.

OUTLINE_PASS_NODE_NAME,
);
#[cfg(feature = "bevy_ui")]
Expand All @@ -266,4 +278,9 @@ impl Plugin for OutlinePlugin {
bevy::ui::draw_ui_graph::node::UI_PASS,
);
}

fn finish(&self, app: &mut App) {
app.sub_app_mut(RenderApp)
.init_resource::<OutlinePipeline>();
}
}
10 changes: 2 additions & 8 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::Reverse;
use bevy::ecs::system::lifetimeless::Read;
use bevy::prelude::*;
use bevy::render::camera::ExtractedCamera;
use bevy::render::render_graph::{NodeRunError, SlotInfo, SlotType};
use bevy::render::render_graph::NodeRunError;
use bevy::render::render_phase::{
CachedRenderPipelinePhaseItem, DrawFunctionId, PhaseItem, RenderPhase,
};
Expand Down Expand Up @@ -128,8 +128,6 @@ pub(crate) struct OutlineNode {
}

impl OutlineNode {
pub(crate) const IN_VIEW: &'static str = "view";
Copy link
Contributor Author

Choose a reason for hiding this comment

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


pub(crate) fn new(world: &mut World) -> Self {
Self {
query: world.query_filtered(),
Expand All @@ -138,10 +136,6 @@ impl OutlineNode {
}

impl Node for OutlineNode {
fn input(&self) -> Vec<SlotInfo> {
vec![SlotInfo::new(Self::IN_VIEW, SlotType::Entity)]
}

fn update(&mut self, world: &mut World) {
self.query.update_archetypes(world);
}
Expand All @@ -152,7 +146,7 @@ impl Node for OutlineNode {
render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.get_input_entity(Self::IN_VIEW)?;
let view_entity = graph.view_entity();
let (camera, stencil_phase, opaque_phase, transparent_phase, camera_3d, target, depth) =
match self.query.get_manual(world, view_entity) {
Ok(query) => query,
Expand Down
19 changes: 10 additions & 9 deletions src/outline.wgsl
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#import bevy_pbr::mesh_view_bindings
#import bevy_pbr::mesh_types
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these shader changes were due to this

https://bevyengine.org/learn/migration-guides/0.10-0.11/#improve-shader-import-model

I'm not as experienced with these shaders, so I wouldn't be surprised if there are changes here that "work" but may only work in the cases I've been testing.

#import bevy_render::view View
#import bevy_pbr::mesh_types Mesh
#import bevy_pbr::mesh_types SkinnedMesh

struct VertexInput {
@location(0) position: vec3<f32>,
#ifndef OFFSET_ZERO
@location(1) normal: vec3<f32>,
#endif
#ifdef SKINNED
@location(2) joint_indexes: vec4<u32>,
@location(3) joint_weights: vec4<f32>,
@location(5) joint_indices: vec4<u32>,
@location(6) joint_weights: vec4<f32>,
#endif
};

Expand All @@ -30,14 +31,14 @@ struct OutlineVertexUniform {
offset: f32,
};

@group(0) @binding(0)
var<uniform> view: View;

@group(1) @binding(0)
var<uniform> mesh: Mesh;

#ifdef SKINNED
@group(1) @binding(1)
var<uniform> joint_matrices: SkinnedMesh;
#import bevy_pbr::skinning
#endif
#import bevy_pbr::morph

@group(2) @binding(0)
var<uniform> view_uniform: OutlineViewUniform;
Expand All @@ -62,7 +63,7 @@ fn model_origin_z(plane: vec3<f32>, view_proj: mat4x4<f32>) -> f32 {
@vertex
fn vertex(vertex: VertexInput) -> VertexOutput {
#ifdef SKINNED
let model = skin_model(vertex.joint_indexes, vertex.joint_weights);
let model = bevy_pbr::skinning::skin_model(vertex.joint_indices, vertex.joint_weights);
#else
let model = mesh.model;
#endif
Expand Down
Loading
Loading