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

Update to Bevy v0.10.1 #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
[package]
name = "bevy_jfa"
authors = ["dataphract"]
categories = ["game-development", "graphics"]
description = "The jump flooding algorithm (JFA) for Bevy"
documentation = "https://docs.rs/bevy_jfa"
keywords = ["bevy", "jfa", "outline", "graphics"]
categories = ["game-development", "graphics"]
authors = ["dataphract"]
license = "MIT OR Apache-2.0"
documentation = "https://docs.rs/bevy_jfa"
repository = "https://github.com/dataphract/bevy_jfa"
name = "bevy_jfa"
readme = "README.md"
repository = "https://github.com/dataphract/bevy_jfa"

version = "0.1.0"
edition = "2021"
resolver = "2"
version = "0.1.0"

[features]
default = ["wgpu-profiler"]

[dependencies]
bitflags = "1"
wgpu-profiler = { version = "0.9", optional = true }
bitflags = "2.3.1"
wgpu-profiler = {version = "0.12.1", optional = true}

[dependencies.bevy]
version = "0.8.0"
default-features = false
features = [
"bevy_asset",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_render",
"bevy_winit",
"bevy_asset",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_render",
"bevy_winit",
]
version = "0.10.1"

[profile.dev]
opt-level = 3
7 changes: 0 additions & 7 deletions examples/Cargo.toml

This file was deleted.

11 changes: 6 additions & 5 deletions examples/cube/src/main.rs → examples/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn setup(
});

commands
.spawn_bundle(PbrBundle {
.spawn(PbrBundle {
mesh: mesh.clone(),
material: material.clone(),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
Expand All @@ -32,7 +32,7 @@ fn setup(
.insert(Outline { enabled: true });

commands
.spawn_bundle(PbrBundle {
.spawn(PbrBundle {
mesh: mesh.clone(),
material: material.clone(),
transform: Transform::from_xyz(-2.0, 0.0, 0.0),
Expand All @@ -42,7 +42,7 @@ fn setup(
.insert(Outline { enabled: true });

commands
.spawn_bundle(PbrBundle {
.spawn(PbrBundle {
mesh,
material,
transform: Transform::from_xyz(0.0, 0.0, -2.0),
Expand All @@ -52,7 +52,7 @@ fn setup(
.insert(Outline { enabled: true });

commands
.spawn_bundle(Camera3dBundle {
.spawn(Camera3dBundle {
transform: Transform::from_xyz(3.0, 2.0, 3.0)
.looking_at([-1.0, -0.5, -1.0].into(), Vec3::Y),
..Camera3dBundle::default()
Expand All @@ -65,7 +65,7 @@ fn setup(
}),
});

commands.spawn_bundle(PointLightBundle {
commands.spawn(PointLightBundle {
point_light: PointLight {
color: Color::WHITE,
intensity: 800.0,
Expand Down Expand Up @@ -99,6 +99,7 @@ fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(OutlinePlugin)
// .insert_resource(Msaa::Off)
.add_startup_system(setup)
.add_system(rotate_cube)
.add_system(handle_keys)
Expand Down
9 changes: 0 additions & 9 deletions examples/cube/Cargo.toml

This file was deleted.

12 changes: 6 additions & 6 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,47 +90,47 @@ pub fn outline(render_app: &mut App) -> Result<RenderGraph, RenderGraphError> {
outline::input::VIEW_ENTITY,
outline::node::MASK_PASS,
MeshMaskNode::IN_VIEW,
)?;
);

// Mask -> JFA Init
graph.add_slot_edge(
outline::node::MASK_PASS,
MeshMaskNode::OUT_MASK,
outline::node::JFA_INIT_PASS,
JfaInitNode::IN_MASK,
)?;
);

// Input -> JFA
graph.add_slot_edge(
input_node_id,
outline::input::VIEW_ENTITY,
outline::node::JFA_PASS,
JfaNode::IN_VIEW,
)?;
);

// JFA Init -> JFA
graph.add_slot_edge(
outline::node::JFA_INIT_PASS,
JfaInitNode::OUT_JFA_INIT,
outline::node::JFA_PASS,
JfaNode::IN_BASE,
)?;
);

// Input -> Outline
graph.add_slot_edge(
input_node_id,
outline::input::VIEW_ENTITY,
outline::node::OUTLINE_PASS,
OutlineNode::IN_VIEW,
)?;
);

// JFA -> Outline
graph.add_slot_edge(
outline::node::JFA_PASS,
JfaNode::OUT_JUMP,
outline::node::OUTLINE_PASS,
OutlineNode::IN_JFA,
)?;
);

Ok(graph)
}
21 changes: 9 additions & 12 deletions src/jfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use bevy::{
render::{
render_asset::RenderAssets,
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
render_phase::TrackedRenderPass,
render_resource::{
BindGroup, CachedRenderPipelineId, ColorTargetState, ColorWrites, FragmentState,
LoadOp, MultisampleState, Operations, PipelineCache, RenderPassColorAttachment,
Expand Down Expand Up @@ -42,6 +41,7 @@ impl Dimensions {
}
}

#[derive(Resource)]
pub struct JfaPipeline {
cached: CachedRenderPipelineId,
}
Expand All @@ -51,10 +51,10 @@ impl FromWorld for JfaPipeline {
let res = world.get_resource::<OutlineResources>().unwrap();
let dimensions_bind_group_layout = res.dimensions_bind_group_layout.clone();
let jfa_bind_group_layout = res.jfa_bind_group_layout.clone();
let mut pipeline_cache = world.get_resource_mut::<PipelineCache>().unwrap();
let pipeline_cache = world.get_resource_mut::<PipelineCache>().unwrap();
let cached = pipeline_cache.queue_render_pipeline(RenderPipelineDescriptor {
label: Some("outline_jfa_pipeline".into()),
layout: Some(vec![dimensions_bind_group_layout, jfa_bind_group_layout]),
layout: vec![dimensions_bind_group_layout, jfa_bind_group_layout],
vertex: VertexState {
shader: JFA_SHADER_HANDLE.typed::<Shader>(),
shader_defs: vec![],
Expand All @@ -74,6 +74,7 @@ impl FromWorld for JfaPipeline {
primitive: FULLSCREEN_PRIMITIVE_STATE,
depth_stencil: None,
multisample: MultisampleState::default(),
push_constant_ranges: vec![],
});

JfaPipeline { cached }
Expand Down Expand Up @@ -197,15 +198,11 @@ impl Node for JfaNode {
store: true,
},
};
let render_pass =
render_context
.command_encoder
.begin_render_pass(&RenderPassDescriptor {
label: Some("outline_jfa"),
color_attachments: &[Some(attachment)],
depth_stencil_attachment: None,
});
let mut tracked_pass = TrackedRenderPass::new(render_pass);
let mut tracked_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
label: Some("outline_jfa"),
color_attachments: &[Some(attachment)],
depth_stencil_attachment: None,
});
tracked_pass.set_render_pipeline(cached_pipeline);
tracked_pass.set_bind_group(0, &res.dimensions_bind_group, &[]);
tracked_pass.set_bind_group(1, src, &[res.jfa_distance_offsets[exp]]);
Expand Down
50 changes: 24 additions & 26 deletions src/jfa_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use bevy::{
prelude::*,
render::{
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
render_phase::TrackedRenderPass,
render_resource::{
CachedRenderPipelineId, ColorTargetState, ColorWrites, Face, FragmentState, FrontFace,
LoadOp, MultisampleState, Operations, PipelineCache, PolygonMode, PrimitiveState,
Expand All @@ -15,6 +14,7 @@ use bevy::{

use crate::{resources::OutlineResources, JFA_INIT_SHADER_HANDLE, JFA_TEXTURE_FORMAT};

#[derive(Resource)]
pub struct JfaInitPipeline {
cached: CachedRenderPipelineId,
}
Expand All @@ -25,10 +25,10 @@ impl FromWorld for JfaInitPipeline {
let dims_layout = res.dimensions_bind_group_layout.clone();
let init_layout = res.jfa_init_bind_group_layout.clone();

let mut pipeline_cache = world.get_resource_mut::<PipelineCache>().unwrap();
let pipeline_cache = world.get_resource_mut::<PipelineCache>().unwrap();
let cached = pipeline_cache.queue_render_pipeline(RenderPipelineDescriptor {
label: Some("outline_jfa_init_pipeline".into()),
layout: Some(vec![dims_layout, init_layout]),
layout: vec![dims_layout, init_layout],
vertex: VertexState {
shader: JFA_INIT_SHADER_HANDLE.typed::<Shader>(),
shader_defs: vec![],
Expand Down Expand Up @@ -56,6 +56,7 @@ impl FromWorld for JfaInitPipeline {
write_mask: ColorWrites::ALL,
})],
}),
push_constant_ranges: vec![],
});

JfaInitPipeline { cached }
Expand Down Expand Up @@ -115,29 +116,26 @@ impl Node for JfaInitNode {
}
};

let render_pass = render_context
.command_encoder
.begin_render_pass(&RenderPassDescriptor {
label: Some("outline_jfa_init"),
color_attachments: &[Some(RenderPassColorAttachment {
view: &res.jfa_primary_output.default_view,
resolve_target: None,
ops: Operations {
load: LoadOp::Clear(
Color::RgbaLinear {
red: -1.0,
green: -1.0,
blue: 0.0,
alpha: 0.0,
}
.into(),
),
store: true,
},
})],
depth_stencil_attachment: None,
});
let mut tracked_pass = TrackedRenderPass::new(render_pass);
let mut tracked_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
label: Some("outline_jfa_init"),
color_attachments: &[Some(RenderPassColorAttachment {
view: &res.jfa_primary_output.default_view,
resolve_target: None,
ops: Operations {
load: LoadOp::Clear(
Color::RgbaLinear {
red: -1.0,
green: -1.0,
blue: 0.0,
alpha: 0.0,
}
.into(),
),
store: true,
},
})],
depth_stencil_attachment: None,
});
tracked_pass.set_render_pipeline(cached_pipeline);
tracked_pass.set_bind_group(0, &res.dimensions_bind_group, &[]);
tracked_pass.set_bind_group(1, &res.jfa_init_bind_group, &[]);
Expand Down
38 changes: 16 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ use bevy::{
render_graph::RenderGraph,
render_phase::{
AddRenderCommand, CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions,
EntityPhaseItem, PhaseItem, RenderPhase, SetItemPipeline,
PhaseItem, RenderPhase, SetItemPipeline,
},
render_resource::*,
renderer::{RenderDevice, RenderQueue},
view::{ExtractedView, VisibleEntities},
Extract, RenderApp, RenderStage,
Extract, RenderApp, RenderSet,
},
utils::FloatOrd,
};
Expand Down Expand Up @@ -74,7 +74,7 @@ const FULLSCREEN_PRIMITIVE_STATE: PrimitiveState = PrimitiveState {
pub struct OutlinePlugin;

/// Performance and visual quality settings for JFA-based outlines.
#[derive(Clone, ExtractResource)]
#[derive(Clone, ExtractResource, Resource)]
pub struct OutlineSettings {
pub(crate) half_resolution: bool,
}
Expand Down Expand Up @@ -154,31 +154,27 @@ impl Plugin for OutlinePlugin {
.init_resource::<jfa::JfaPipeline>()
.init_resource::<outline::OutlinePipeline>()
.init_resource::<SpecializedRenderPipelines<outline::OutlinePipeline>>()
.add_system_to_stage(RenderStage::Extract, extract_outline_settings)
.add_system_to_stage(RenderStage::Extract, extract_camera_outlines)
.add_system_to_stage(RenderStage::Extract, extract_mask_camera_phase)
.add_system_to_stage(RenderStage::Prepare, resources::recreate_outline_resources)
.add_system_to_stage(RenderStage::Queue, queue_mesh_masks);
.add_system(extract_outline_settings.in_schedule(ExtractSchedule))
.add_system(extract_camera_outlines.in_schedule(ExtractSchedule))
.add_system(extract_mask_camera_phase.in_schedule(ExtractSchedule))
.add_system(resources::recreate_outline_resources.in_set(RenderSet::Queue))
.add_system(queue_mesh_masks.in_set(RenderSet::Queue));

let outline_graph = graph::outline(render_app).unwrap();

let mut root_graph = render_app.world.resource_mut::<RenderGraph>();
let draw_3d_graph = root_graph.get_sub_graph_mut(core_3d::graph::NAME).unwrap();
let draw_3d_input = draw_3d_graph.input_node().unwrap().id;
let draw_3d_input = draw_3d_graph.input_node().id;

draw_3d_graph.add_sub_graph(outline_graph::NAME, outline_graph);
let outline_driver = draw_3d_graph.add_node(OutlineDriverNode::NAME, OutlineDriverNode);
draw_3d_graph
.add_slot_edge(
draw_3d_input,
core_3d::graph::input::VIEW_ENTITY,
outline_driver,
OutlineDriverNode::INPUT_VIEW,
)
.unwrap();
draw_3d_graph
.add_node_edge(core_3d::graph::node::MAIN_PASS, outline_driver)
.unwrap();
draw_3d_graph.add_slot_edge(
draw_3d_input,
core_3d::graph::input::VIEW_ENTITY,
outline_driver,
OutlineDriverNode::INPUT_VIEW,
);
draw_3d_graph.add_node_edge(core_3d::graph::node::MAIN_PASS, outline_driver);
}
}

Expand All @@ -199,9 +195,7 @@ impl PhaseItem for MeshMask {
fn draw_function(&self) -> DrawFunctionId {
self.draw_function
}
}

impl EntityPhaseItem for MeshMask {
fn entity(&self) -> Entity {
self.entity
}
Expand Down
Loading