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

0.11 Section: Simpler RenderGraph construction #667

Merged
Merged
Changes from 2 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
51 changes: 51 additions & 0 deletions content/news/2023-07-07-bevy-0.11/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,57 @@ Since our last release a few months ago we've added a _ton_ of new features, bug

Description

## Simpler RenderGraph Construction

<div class="release-feature-authors">authors: @IceSentry, @cart</div>

Adding `Node`s to the `RenderGraph` requires a lot of boilerplate. In this release, we tried to reduce this for most common operations. No existing API have been removed, these are only helpers made to simplify working with the `RenderGraph`.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

We added the `RenderGraphApp` trait to the `App`. This trait contains various helper functions to reduce the boilerplate with adding nodes and edges to a graph.

Another pain point of `RenderGraph` `Node`s is passing the view entity through each node and manually updating the query on that view. To fix this we added a `ViewNode` trait and `ViewNodeRunner` that will automatically take care of running the `Query` on the view entity. We also made the view entity a first party concept of the `RenderGraph`. So you can now access the view entity the graph is currently running on from anywhere in the graph without passing it around between each `Node`.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

All these new apis assume that your Node implements `FromWorld` or `Default`.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

Here's what it looks like in practice for the `BloomNode`:

```rust
// Adding the node to the 3d graph
render_app
// To run a ViewNode you need to create a ViewNodeRunner
.add_render_graph_node::<ViewNodeRunner<BloomNode>>(
CORE_3D,
core_3d::graph::node::BLOOM,
);

// Defining the node
#[derive(Default)]
struct BloomNode;
// This can replace your `impl Node` block of any existing `Node` that operated on a view
impl ViewNode for BloomNode {
// You need to define your view query as an associated type
type ViewQuery = (
&'static ExtractedCamera,
&'static ViewTarget,
&'static BloomSettings,
);
// You don't need Node::input() or Node::update() anymore. If you still need these they are still available but they have an empty default implementation.
fn run(
&self,
graph: &mut RenderGraphContext,
render_context: &mut RenderContext,
// This is the result of your query. If it is empty the run function will not be called
(camera, view_target, bloom_settings): QueryItem<Self::ViewQuery>,
world: &World,
) -> Result<(), NodeRunError> {
// When using the ViewNode you probably won't need the view entity but here's how to get it
IceSentry marked this conversation as resolved.
Show resolved Hide resolved
let view_entity = graph.view_entity();

// Run the node
}
}
```

## <a name="what-s-next"></a>What's Next?

* **X**: Y
Expand Down