File tree Expand file tree Collapse file tree 5 files changed +35
-24
lines changed
bevy_core_pipeline/src/prepass Expand file tree Collapse file tree 5 files changed +35
-24
lines changed Original file line number Diff line number Diff line change 1
1
#import bevy_pbr ::mesh_types
2
2
#import bevy_pbr ::mesh_view_bindings
3
- #import bevy_pbr ::utils
3
+ #import bevy_pbr ::prepass_utils
4
4
5
5
@group (1 ) @binding (0 )
6
6
var <uniform > show_depth : f32 ;
Original file line number Diff line number Diff line change 16
16
//! it will always create a depth buffer that will be used by the main pass.
17
17
//!
18
18
//! When using the default mesh view bindings you should be able to use `prepass_depth()`
19
- //! and `prepass_normal()` to load the related textures. These functions are defined in `bevy_pbr::utils `.
19
+ //! and `prepass_normal()` to load the related textures. These functions are defined in `bevy_pbr::prepass_utils `.
20
20
//! See the `shader_prepass` example that shows how to use it.
21
21
//!
22
22
//! The prepass runs for each `Material`. You can control if the prepass should run per-material by setting the `prepass_enabled`
Original file line number Diff line number Diff line change @@ -57,6 +57,9 @@ pub const PREPASS_SHADER_HANDLE: HandleUntyped =
57
57
pub const PREPASS_BINDINGS_SHADER_HANDLE : HandleUntyped =
58
58
HandleUntyped :: weak_from_u64 ( Shader :: TYPE_UUID , 5533152893177403494 ) ;
59
59
60
+ pub const PREPASS_UTILS_SHADER_HANDLE : HandleUntyped =
61
+ HandleUntyped :: weak_from_u64 ( Shader :: TYPE_UUID , 4603948296044544 ) ;
62
+
60
63
pub struct PrepassPlugin < M : Material > ( PhantomData < M > ) ;
61
64
62
65
impl < M : Material > Default for PrepassPlugin < M > {
84
87
Shader :: from_wgsl
85
88
) ;
86
89
90
+ load_internal_asset ! (
91
+ app,
92
+ PREPASS_UTILS_SHADER_HANDLE ,
93
+ "prepass_utils.wgsl" ,
94
+ Shader :: from_wgsl
95
+ ) ;
96
+
87
97
let Ok ( render_app) = app. get_sub_app_mut ( RenderApp ) else {
88
98
return ;
89
99
} ;
Original file line number Diff line number Diff line change
1
+ #define_import_path bevy_pbr ::prepass_utils
2
+
3
+ #ifndef NORMAL_PREPASS
4
+ fn prepass_normal (frag_coord : vec4 <f32 >, sample_index : u32 ) -> vec3 <f32 > {
5
+ #ifdef MULTISAMPLED
6
+ let normal_sample = textureLoad (normal_prepass_texture , vec2 <i32 >(frag_coord . xy), i32 (sample_index ));
7
+ #else
8
+ let normal_sample = textureLoad (normal_prepass_texture , vec2 <i32 >(frag_coord . xy), 0 );
9
+ #endif
10
+ return normal_sample . xyz * 2.0 - vec3 (1.0 );
11
+ }
12
+ #endif // NORMAL_PREPASS
13
+
14
+ #ifndef DEPTH_PREPASS
15
+ fn prepass_depth (frag_coord : vec4 <f32 >, sample_index : u32 ) -> f32 {
16
+ #ifdef MULTISAMPLED
17
+ let depth_sample = textureLoad (depth_prepass_texture , vec2 <i32 >(frag_coord . xy), i32 (sample_index ));
18
+ #else
19
+ let depth_sample = textureLoad (depth_prepass_texture , vec2 <i32 >(frag_coord . xy), 0 );
20
+ #endif
21
+ return depth_sample ;
22
+ }
23
+ #endif // DEPTH_PREPASS
Original file line number Diff line number Diff line change @@ -25,25 +25,3 @@ fn random1D(s: f32) -> f32 {
25
25
fn coords_to_viewport_uv (position : vec2 <f32 >, viewport : vec4 <f32 >) -> vec2 <f32 > {
26
26
return (position - viewport . xy) / viewport . zw;
27
27
}
28
-
29
- #ifndef NORMAL_PREPASS
30
- fn prepass_normal (frag_coord : vec4 <f32 >, sample_index : u32 ) -> vec3 <f32 > {
31
- #ifdef MULTISAMPLED
32
- let normal_sample = textureLoad (normal_prepass_texture , vec2 <i32 >(frag_coord . xy), i32 (sample_index ));
33
- #else
34
- let normal_sample = textureLoad (normal_prepass_texture , vec2 <i32 >(frag_coord . xy), 0 );
35
- #endif
36
- return normal_sample . xyz * 2.0 - vec3 (1.0 );
37
- }
38
- #endif // NORMAL_PREPASS
39
-
40
- #ifndef DEPTH_PREPASS
41
- fn prepass_depth (frag_coord : vec4 <f32 >, sample_index : u32 ) -> f32 {
42
- #ifdef MULTISAMPLED
43
- let depth_sample = textureLoad (depth_prepass_texture , vec2 <i32 >(frag_coord . xy), i32 (sample_index ));
44
- #else
45
- let depth_sample = textureLoad (depth_prepass_texture , vec2 <i32 >(frag_coord . xy), 0 );
46
- #endif
47
- return depth_sample ;
48
- }
49
- #endif // DEPTH_PREPASS
You can’t perform that action at this time.
0 commit comments