@@ -4,10 +4,14 @@ use crate::{
4
4
} ;
5
5
use bevy_app:: { App , Plugin } ;
6
6
use bevy_asset:: Handle ;
7
- use bevy_core_pipeline:: core_3d:: { Transparent3d , CORE_3D_DEPTH_FORMAT } ;
7
+ use bevy_core_pipeline:: {
8
+ core_3d:: { Transparent3d , CORE_3D_DEPTH_FORMAT } ,
9
+ prepass:: { DeferredPrepass , DepthPrepass , MotionVectorPrepass , NormalPrepass } ,
10
+ } ;
8
11
9
12
use bevy_ecs:: {
10
13
prelude:: Entity ,
14
+ query:: Has ,
11
15
schedule:: IntoSystemConfigs ,
12
16
system:: { Query , Res , ResMut , Resource } ,
13
17
world:: { FromWorld , World } ,
@@ -69,7 +73,7 @@ impl FromWorld for LineGizmoPipeline {
69
73
70
74
#[ derive( PartialEq , Eq , Hash , Clone ) ]
71
75
struct LineGizmoPipelineKey {
72
- mesh_key : MeshPipelineKey ,
76
+ view_key : MeshPipelineKey ,
73
77
strip : bool ,
74
78
perspective : bool ,
75
79
}
@@ -87,15 +91,15 @@ impl SpecializedRenderPipeline for LineGizmoPipeline {
87
91
shader_defs. push ( "PERSPECTIVE" . into ( ) ) ;
88
92
}
89
93
90
- let format = if key. mesh_key . contains ( MeshPipelineKey :: HDR ) {
94
+ let format = if key. view_key . contains ( MeshPipelineKey :: HDR ) {
91
95
ViewTarget :: TEXTURE_FORMAT_HDR
92
96
} else {
93
97
TextureFormat :: bevy_default ( )
94
98
} ;
95
99
96
100
let view_layout = self
97
101
. mesh_pipeline
98
- . get_view_layout ( key. mesh_key . into ( ) )
102
+ . get_view_layout ( key. view_key . into ( ) )
99
103
. clone ( ) ;
100
104
101
105
let layout = vec ! [ view_layout, self . uniform_layout. clone( ) ] ;
@@ -127,7 +131,7 @@ impl SpecializedRenderPipeline for LineGizmoPipeline {
127
131
bias : DepthBiasState :: default ( ) ,
128
132
} ) ,
129
133
multisample : MultisampleState {
130
- count : key. mesh_key . msaa_samples ( ) ,
134
+ count : key. view_key . msaa_samples ( ) ,
131
135
mask : !0 ,
132
136
alpha_to_coverage_enabled : false ,
133
137
} ,
@@ -158,19 +162,47 @@ fn queue_line_gizmos_3d(
158
162
& ExtractedView ,
159
163
& mut RenderPhase < Transparent3d > ,
160
164
Option < & RenderLayers > ,
165
+ (
166
+ Has < NormalPrepass > ,
167
+ Has < DepthPrepass > ,
168
+ Has < MotionVectorPrepass > ,
169
+ Has < DeferredPrepass > ,
170
+ ) ,
161
171
) > ,
162
172
) {
163
173
let draw_function = draw_functions. read ( ) . get_id :: < DrawLineGizmo3d > ( ) . unwrap ( ) ;
164
174
165
- for ( view, mut transparent_phase, render_layers) in & mut views {
175
+ for (
176
+ view,
177
+ mut transparent_phase,
178
+ render_layers,
179
+ ( normal_prepass, depth_prepass, motion_vector_prepass, deferred_prepass) ,
180
+ ) in & mut views
181
+ {
166
182
let render_layers = render_layers. copied ( ) . unwrap_or_default ( ) ;
167
183
if !config. render_layers . intersects ( & render_layers) {
168
184
continue ;
169
185
}
170
186
171
- let mesh_key = MeshPipelineKey :: from_msaa_samples ( msaa. samples ( ) )
187
+ let mut view_key = MeshPipelineKey :: from_msaa_samples ( msaa. samples ( ) )
172
188
| MeshPipelineKey :: from_hdr ( view. hdr ) ;
173
189
190
+ if normal_prepass {
191
+ view_key |= MeshPipelineKey :: NORMAL_PREPASS ;
192
+ }
193
+
194
+ if depth_prepass {
195
+ view_key |= MeshPipelineKey :: DEPTH_PREPASS ;
196
+ }
197
+
198
+ if motion_vector_prepass {
199
+ view_key |= MeshPipelineKey :: MOTION_VECTOR_PREPASS ;
200
+ }
201
+
202
+ if deferred_prepass {
203
+ view_key |= MeshPipelineKey :: DEFERRED_PREPASS ;
204
+ }
205
+
174
206
for ( entity, handle) in & line_gizmos {
175
207
let Some ( line_gizmo) = line_gizmo_assets. get ( handle) else {
176
208
continue ;
@@ -180,7 +212,7 @@ fn queue_line_gizmos_3d(
180
212
& pipeline_cache,
181
213
& pipeline,
182
214
LineGizmoPipelineKey {
183
- mesh_key ,
215
+ view_key ,
184
216
strip : line_gizmo. strip ,
185
217
perspective : config. line_perspective ,
186
218
} ,
0 commit comments