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 11#import bevy_pbr :: mesh_types
22#import bevy_pbr :: mesh_view_bindings
3- #import bevy_pbr :: utils
3+ #import bevy_pbr :: prepass_utils
44
55@group (1 ) @binding (0 )
66var <uniform > show_depth : f32 ;
Original file line number Diff line number Diff line change 1616//! it will always create a depth buffer that will be used by the main pass.
1717//!
1818//! 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 `.
2020//! See the `shader_prepass` example that shows how to use it.
2121//!
2222//! 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 =
5757pub const PREPASS_BINDINGS_SHADER_HANDLE : HandleUntyped =
5858 HandleUntyped :: weak_from_u64 ( Shader :: TYPE_UUID , 5533152893177403494 ) ;
5959
60+ pub const PREPASS_UTILS_SHADER_HANDLE : HandleUntyped =
61+ HandleUntyped :: weak_from_u64 ( Shader :: TYPE_UUID , 4603948296044544 ) ;
62+
6063pub struct PrepassPlugin < M : Material > ( PhantomData < M > ) ;
6164
6265impl < M : Material > Default for PrepassPlugin < M > {
8487 Shader :: from_wgsl
8588 ) ;
8689
90+ load_internal_asset ! (
91+ app,
92+ PREPASS_UTILS_SHADER_HANDLE ,
93+ "prepass_utils.wgsl" ,
94+ Shader :: from_wgsl
95+ ) ;
96+
8797 let Ok ( render_app) = app. get_sub_app_mut ( RenderApp ) else {
8898 return ;
8999 } ;
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 {
2525fn coords_to_viewport_uv (position : vec2 <f32 >, viewport : vec4 <f32 >) -> vec2 <f32 > {
2626 return (position - viewport . xy ) / viewport . zw ;
2727}
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