@@ -17,6 +17,7 @@ use bevy_utils::tracing::info_span;
1717
1818use super :: { AlphaMask3d , Camera3dDepthLoadOp } ;
1919
20+ /// A [`Node`] that runs the [`Opaque3d`] and [`AlphaMask3d`] [`RenderPhase`].
2021pub struct MainOpaquePass3dNode {
2122 query : QueryState <
2223 (
@@ -76,81 +77,50 @@ impl Node for MainOpaquePass3dNode {
7677 return Ok ( ( ) ) ;
7778 } ;
7879
79- // Always run opaque pass to ensure screen is cleared
80- {
81- // Run the opaque pass, sorted front-to-back
82- // NOTE: Scoped to drop the mutable borrow of render_context
83- #[ cfg( feature = "trace" ) ]
84- let _main_opaque_pass_3d_span = info_span ! ( "main_opaque_pass_3d" ) . entered ( ) ;
85-
86- let mut render_pass = render_context. begin_tracked_render_pass ( RenderPassDescriptor {
87- label : Some ( "main_opaque_pass_3d" ) ,
88- // NOTE: The opaque pass loads the color
89- // buffer as well as writing to it.
90- color_attachments : & [ Some ( target. get_color_attachment ( Operations {
91- load : match camera_3d. clear_color {
92- ClearColorConfig :: Default => {
93- LoadOp :: Clear ( world. resource :: < ClearColor > ( ) . 0 . into ( ) )
94- }
95- ClearColorConfig :: Custom ( color) => LoadOp :: Clear ( color. into ( ) ) ,
96- ClearColorConfig :: None => LoadOp :: Load ,
97- } ,
80+ // Run the opaque pass, sorted front-to-back
81+ #[ cfg( feature = "trace" ) ]
82+ let _main_opaque_pass_3d_span = info_span ! ( "main_opaque_pass_3d" ) . entered ( ) ;
83+
84+ let mut render_pass = render_context. begin_tracked_render_pass ( RenderPassDescriptor {
85+ label : Some ( "main_opaque_pass_3d" ) ,
86+ // NOTE: The opaque pass loads the color
87+ // buffer as well as writing to it.
88+ color_attachments : & [ Some ( target. get_color_attachment ( Operations {
89+ load : match camera_3d. clear_color {
90+ ClearColorConfig :: Default => {
91+ LoadOp :: Clear ( world. resource :: < ClearColor > ( ) . 0 . into ( ) )
92+ }
93+ ClearColorConfig :: Custom ( color) => LoadOp :: Clear ( color. into ( ) ) ,
94+ ClearColorConfig :: None => LoadOp :: Load ,
95+ } ,
96+ store : true ,
97+ } ) ) ] ,
98+ depth_stencil_attachment : Some ( RenderPassDepthStencilAttachment {
99+ view : & depth. view ,
100+ // NOTE: The opaque main pass loads the depth buffer and possibly overwrites it
101+ depth_ops : Some ( Operations {
102+ load : if depth_prepass. is_some ( ) || normal_prepass. is_some ( ) {
103+ // if any prepass runs, it will generate a depth buffer so we should use it,
104+ // even if only the normal_prepass is used.
105+ Camera3dDepthLoadOp :: Load
106+ } else {
107+ // NOTE: 0.0 is the far plane due to bevy's use of reverse-z projections.
108+ camera_3d. depth_load_op . clone ( )
109+ }
110+ . into ( ) ,
98111 store : true ,
99- } ) ) ] ,
100- depth_stencil_attachment : Some ( RenderPassDepthStencilAttachment {
101- view : & depth. view ,
102- // NOTE: The opaque main pass loads the depth buffer and possibly overwrites it
103- depth_ops : Some ( Operations {
104- load : if depth_prepass. is_some ( ) || normal_prepass. is_some ( ) {
105- // if any prepass runs, it will generate a depth buffer so we should use it,
106- // even if only the normal_prepass is used.
107- Camera3dDepthLoadOp :: Load
108- } else {
109- // NOTE: 0.0 is the far plane due to bevy's use of reverse-z projections.
110- camera_3d. depth_load_op . clone ( )
111- }
112- . into ( ) ,
113- store : true ,
114- } ) ,
115- stencil_ops : None ,
116112 } ) ,
117- } ) ;
118-
119- if let Some ( viewport) = camera. viewport . as_ref ( ) {
120- render_pass. set_camera_viewport ( viewport) ;
121- }
113+ stencil_ops : None ,
114+ } ) ,
115+ } ) ;
122116
123- opaque_phase. render ( & mut render_pass, world, view_entity) ;
117+ if let Some ( viewport) = camera. viewport . as_ref ( ) {
118+ render_pass. set_camera_viewport ( viewport) ;
124119 }
125120
126- if !alpha_mask_phase. items . is_empty ( ) {
127- // Run the alpha mask pass, sorted front-to-back
128- // NOTE: Scoped to drop the mutable borrow of render_context
129- #[ cfg( feature = "trace" ) ]
130- let _main_alpha_mask_pass_3d_span = info_span ! ( "main_alpha_mask_pass_3d" ) . entered ( ) ;
131-
132- let mut render_pass = render_context. begin_tracked_render_pass ( RenderPassDescriptor {
133- label : Some ( "main_alpha_mask_pass_3d" ) ,
134- // NOTE: The alpha_mask pass loads the color buffer as well as overwriting it where appropriate.
135- color_attachments : & [ Some ( target. get_color_attachment ( Operations {
136- load : LoadOp :: Load ,
137- store : true ,
138- } ) ) ] ,
139- depth_stencil_attachment : Some ( RenderPassDepthStencilAttachment {
140- view : & depth. view ,
141- // NOTE: The alpha mask pass loads the depth buffer and possibly overwrites it
142- depth_ops : Some ( Operations {
143- load : LoadOp :: Load ,
144- store : true ,
145- } ) ,
146- stencil_ops : None ,
147- } ) ,
148- } ) ;
149-
150- if let Some ( viewport) = camera. viewport . as_ref ( ) {
151- render_pass. set_camera_viewport ( viewport) ;
152- }
121+ opaque_phase. render ( & mut render_pass, world, view_entity) ;
153122
123+ if !alpha_mask_phase. items . is_empty ( ) {
154124 alpha_mask_phase. render ( & mut render_pass, world, view_entity) ;
155125 }
156126
0 commit comments