-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Objective - Rendering before MainPass should be possible, so clearing needs to happen in an earlier pass. - Fixes #3190. ## Solution - I added a "Clear" SubGraph, a "ClearPassNode" Node, that clears the color and depth attachments of all views and a "ClearNodeDriver" Node, that schedules the "ClearPassNode" before MainPass. - Make sure that the 2d and 3d draw passes do not clear their attachments anymore. ### Notes - It works in the way, that with the current pipeline examples nothing should have changed in their behaviour - I would like to add an example that adds a pass inbetween ClearPass and MainPass, but I do not understand enough about the new render architecture to do that yet - Clears all attachment for all views: I do not know enough about rendering in general to say, whether there is a use case for not clearing - Does not solve #3043 as we still need Cameras/ViewTargets to clear.
- Loading branch information
1 parent
4c91613
commit 82c04f9
Showing
5 changed files
with
114 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::ClearColor; | ||
use bevy_ecs::prelude::*; | ||
use bevy_render2::{ | ||
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo}, | ||
render_resource::{LoadOp, Operations, RenderPassDepthStencilAttachment, RenderPassDescriptor}, | ||
renderer::RenderContext, | ||
view::{ExtractedView, ViewDepthTexture, ViewTarget}, | ||
}; | ||
|
||
pub struct ClearPassNode { | ||
query: QueryState<(&'static ViewTarget, &'static ViewDepthTexture), With<ExtractedView>>, | ||
} | ||
|
||
impl ClearPassNode { | ||
pub fn new(world: &mut World) -> Self { | ||
Self { | ||
query: QueryState::new(world), | ||
} | ||
} | ||
} | ||
|
||
impl Node for ClearPassNode { | ||
fn input(&self) -> Vec<SlotInfo> { | ||
vec![] | ||
} | ||
|
||
fn update(&mut self, world: &mut World) { | ||
self.query.update_archetypes(world); | ||
} | ||
|
||
fn run( | ||
&self, | ||
_graph: &mut RenderGraphContext, | ||
render_context: &mut RenderContext, | ||
world: &World, | ||
) -> Result<(), NodeRunError> { | ||
/* This gets all ViewTargets and ViewDepthTextures and clears its attachments */ | ||
for (target, depth) in self.query.iter_manual(world) { | ||
let clear_color = world.get_resource::<ClearColor>().unwrap(); | ||
let pass_descriptor = RenderPassDescriptor { | ||
label: Some("clear_pass"), | ||
color_attachments: &[target.get_color_attachment(Operations { | ||
load: LoadOp::Clear(clear_color.0.into()), | ||
store: true, | ||
})], | ||
depth_stencil_attachment: Some(RenderPassDepthStencilAttachment { | ||
view: &depth.view, | ||
depth_ops: Some(Operations { | ||
load: LoadOp::Clear(0.0), | ||
store: true, | ||
}), | ||
stencil_ops: None, | ||
}), | ||
}; | ||
|
||
render_context | ||
.command_encoder | ||
.begin_render_pass(&pass_descriptor); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use bevy_ecs::world::World; | ||
use bevy_render2::{ | ||
render_graph::{Node, NodeRunError, RenderGraphContext}, | ||
renderer::RenderContext, | ||
}; | ||
|
||
pub struct ClearPassDriverNode; | ||
|
||
impl Node for ClearPassDriverNode { | ||
fn run( | ||
&self, | ||
graph: &mut RenderGraphContext, | ||
_render_context: &mut RenderContext, | ||
_world: &World, | ||
) -> Result<(), NodeRunError> { | ||
graph.run_sub_graph(crate::clear_graph::NAME, vec![])?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters