Skip to content

Commit 257b2e5

Browse files
IceSentryJMS55
andauthored
0.11 Section: Simpler RenderGraph construction (#667)
Co-authored-by: JMS55 <[email protected]>
1 parent b5af745 commit 257b2e5

File tree

1 file changed

+51
-0
lines changed
  • content/news/2023-07-07-bevy-0.11

1 file changed

+51
-0
lines changed

content/news/2023-07-07-bevy-0.11/index.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,57 @@ app.add_systems(Update,
472472

473473
This will run `a` in parallel with `b->c->d`, then after those have finished running it will run `e` and `f` in parallel.
474474

475+
## Simpler RenderGraph Construction
476+
477+
<div class="release-feature-authors">authors: @IceSentry, @cart</div>
478+
479+
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 APIs have been removed, these are only helpers made to simplify working with the `RenderGraph`.
480+
481+
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.
482+
483+
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-class 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`.
484+
485+
All these new APIs assume that your Node implements `FromWorld` or `Default`.
486+
487+
Here's what it looks like in practice for the `BloomNode`:
488+
489+
```rust
490+
// Adding the node to the 3d graph
491+
render_app
492+
// To run a ViewNode you need to create a ViewNodeRunner
493+
.add_render_graph_node::<ViewNodeRunner<BloomNode>>(
494+
CORE_3D,
495+
core_3d::graph::node::BLOOM,
496+
);
497+
498+
// Defining the node
499+
#[derive(Default)]
500+
struct BloomNode;
501+
// This can replace your `impl Node` block of any existing `Node` that operated on a view
502+
impl ViewNode for BloomNode {
503+
// You need to define your view query as an associated type
504+
type ViewQuery = (
505+
&'static ExtractedCamera,
506+
&'static ViewTarget,
507+
&'static BloomSettings,
508+
);
509+
// 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.
510+
fn run(
511+
&self,
512+
graph: &mut RenderGraphContext,
513+
render_context: &mut RenderContext,
514+
// This is the result of your query. If it is empty the run function will not be called
515+
(camera, view_target, bloom_settings): QueryItem<Self::ViewQuery>,
516+
world: &World,
517+
) -> Result<(), NodeRunError> {
518+
// When using the ViewNode you probably won't need the view entity but here's how to get it if you do
519+
let view_entity = graph.view_entity();
520+
521+
// Run the node
522+
}
523+
}
524+
```
525+
475526
## <a name="what-s-next"></a>What's Next?
476527

477528
* **X**: Y

0 commit comments

Comments
 (0)