Skip to content

Commit f51a835

Browse files
committed
add some comments
1 parent 23dddcd commit f51a835

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

crates/bevy_pbr/src/fullscreen_material.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! This is mostly a pluginify version of the custom_post_processing example
2+
13
use std::marker::PhantomData;
24

35
use bevy_app::{App, Plugin};
@@ -93,11 +95,9 @@ fn init_pipeline<T: FullscreenMaterial>(
9395
fullscreen_shader: Res<FullscreenShader>,
9496
pipeline_cache: Res<PipelineCache>,
9597
) {
96-
// We need to define the bind group layout used for our pipeline
9798
let layout = render_device.create_bind_group_layout(
9899
"post_process_bind_group_layout",
99100
&BindGroupLayoutEntries::sequential(
100-
// The layout entries will only be visible in the fragment stage
101101
ShaderStages::FRAGMENT,
102102
(
103103
// The screen texture
@@ -109,16 +109,17 @@ fn init_pipeline<T: FullscreenMaterial>(
109109
),
110110
),
111111
);
112-
// We can create the sampler here since it won't change at runtime and doesn't depend on the view
113112
let sampler = render_device.create_sampler(&SamplerDescriptor::default());
114113
let shader = match T::fragment_shader() {
115114
ShaderRef::Default => {
115+
// TODO not sure what an actual fallback should be. An empty shader or output a solid
116+
// color to indicate a missing shader?
116117
unimplemented!("No default fallback for FullscreenMaterial shader")
117118
}
118119
ShaderRef::Handle(handle) => handle,
119120
ShaderRef::Path(path) => asset_server.load(path),
120121
};
121-
// This will setup a fullscreen triangle for the vertex state.
122+
// Setup a fullscreen triangle for the vertex state.
122123
let vertex_state = fullscreen_shader.to_vertex_state();
123124
let pipeline_id = pipeline_cache.queue_render_pipeline(RenderPipelineDescriptor {
124125
label: Some("post_process_pipeline".into()),
@@ -149,16 +150,9 @@ struct FullscreenMaterialNode<T: FullscreenMaterial> {
149150
}
150151

151152
impl<T: FullscreenMaterial> ViewNode for FullscreenMaterialNode<T> {
152-
// The node needs a query to gather data from the ECS in order to do its rendering,
153-
// but it's not a normal system so we need to define it manually.
154-
//
155-
// This query will only run on the view entity
156153
type ViewQuery = (
157154
&'static ViewTarget,
158-
// This makes sure the node only runs on cameras with the PostProcessSettings component
159155
&'static T,
160-
// As there could be multiple post processing components sent to the GPU (one per camera),
161-
// we need to get the index of the one that is associated with the current view.
162156
&'static DynamicUniformIndex<T>,
163157
);
164158

@@ -188,7 +182,6 @@ impl<T: FullscreenMaterial> ViewNode for FullscreenMaterialNode<T> {
188182
let bind_group = render_context.render_device().create_bind_group(
189183
"post_process_bind_group",
190184
&post_process_pipeline.layout,
191-
// It's important for this to match the BindGroupLayout defined in the PostProcessPipeline
192185
&BindGroupEntries::sequential((
193186
// Make sure to use the source view
194187
post_process.source,
@@ -199,12 +192,9 @@ impl<T: FullscreenMaterial> ViewNode for FullscreenMaterialNode<T> {
199192
)),
200193
);
201194

202-
// Begin the render pass
203195
let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
204196
label: Some("post_process_pass"),
205197
color_attachments: &[Some(RenderPassColorAttachment {
206-
// We need to specify the post process destination view here
207-
// to make sure we write to the appropriate texture.
208198
view: post_process.destination,
209199
depth_slice: None,
210200
resolve_target: None,
@@ -215,12 +205,7 @@ impl<T: FullscreenMaterial> ViewNode for FullscreenMaterialNode<T> {
215205
occlusion_query_set: None,
216206
});
217207

218-
// This is mostly just wgpu boilerplate for drawing a fullscreen triangle,
219-
// using the pipeline/bind_group created above
220208
render_pass.set_render_pipeline(pipeline);
221-
// By passing in the index of the post process settings on this view, we ensure
222-
// that in the event that multiple settings were sent to the GPU (as would be the
223-
// case with multiple cameras), we use the correct one.
224209
render_pass.set_bind_group(0, &bind_group, &[settings_index.index()]);
225210
render_pass.draw(0..3, 0..1);
226211

0 commit comments

Comments
 (0)