diff --git a/assets/shaders/show_prepass.wgsl b/assets/shaders/show_prepass.wgsl index 592143aa6e..87c48993aa 100644 --- a/assets/shaders/show_prepass.wgsl +++ b/assets/shaders/show_prepass.wgsl @@ -1,6 +1,6 @@ #import bevy_pbr::mesh_types #import bevy_pbr::mesh_view_bindings -#import bevy_pbr::utils +#import bevy_pbr::prepass_utils @group(1) @binding(0) var show_depth: f32; diff --git a/crates/bevy_core_pipeline/src/prepass/mod.rs b/crates/bevy_core_pipeline/src/prepass/mod.rs index a3d05259d5..10440a0c6f 100644 --- a/crates/bevy_core_pipeline/src/prepass/mod.rs +++ b/crates/bevy_core_pipeline/src/prepass/mod.rs @@ -16,7 +16,7 @@ //! it will always create a depth buffer that will be used by the main pass. //! //! When using the default mesh view bindings you should be able to use `prepass_depth()` -//! and `prepass_normal()` to load the related textures. These functions are defined in `bevy_pbr::utils`. +//! and `prepass_normal()` to load the related textures. These functions are defined in `bevy_pbr::prepass_utils`. //! See the `shader_prepass` example that shows how to use it. //! //! The prepass runs for each `Material`. You can control if the prepass should run per-material by setting the `prepass_enabled` diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 8202409d4a..f2492ed94c 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -57,6 +57,9 @@ pub const PREPASS_SHADER_HANDLE: HandleUntyped = pub const PREPASS_BINDINGS_SHADER_HANDLE: HandleUntyped = HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 5533152893177403494); +pub const PREPASS_UTILS_SHADER_HANDLE: HandleUntyped = + HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 4603948296044544); + pub struct PrepassPlugin(PhantomData); impl Default for PrepassPlugin { @@ -84,6 +87,13 @@ where Shader::from_wgsl ); + load_internal_asset!( + app, + PREPASS_UTILS_SHADER_HANDLE, + "prepass_utils.wgsl", + Shader::from_wgsl + ); + let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; diff --git a/crates/bevy_pbr/src/prepass/prepass_utils.wgsl b/crates/bevy_pbr/src/prepass/prepass_utils.wgsl new file mode 100644 index 0000000000..1fd1365a65 --- /dev/null +++ b/crates/bevy_pbr/src/prepass/prepass_utils.wgsl @@ -0,0 +1,23 @@ +#define_import_path bevy_pbr::prepass_utils + +#ifndef NORMAL_PREPASS +fn prepass_normal(frag_coord: vec4, sample_index: u32) -> vec3 { +#ifdef MULTISAMPLED + let normal_sample = textureLoad(normal_prepass_texture, vec2(frag_coord.xy), i32(sample_index)); +#else + let normal_sample = textureLoad(normal_prepass_texture, vec2(frag_coord.xy), 0); +#endif + return normal_sample.xyz * 2.0 - vec3(1.0); +} +#endif // NORMAL_PREPASS + +#ifndef DEPTH_PREPASS +fn prepass_depth(frag_coord: vec4, sample_index: u32) -> f32 { +#ifdef MULTISAMPLED + let depth_sample = textureLoad(depth_prepass_texture, vec2(frag_coord.xy), i32(sample_index)); +#else + let depth_sample = textureLoad(depth_prepass_texture, vec2(frag_coord.xy), 0); +#endif + return depth_sample; +} +#endif // DEPTH_PREPASS diff --git a/crates/bevy_pbr/src/render/utils.wgsl b/crates/bevy_pbr/src/render/utils.wgsl index 641010868f..d1da8611f1 100644 --- a/crates/bevy_pbr/src/render/utils.wgsl +++ b/crates/bevy_pbr/src/render/utils.wgsl @@ -25,25 +25,3 @@ fn random1D(s: f32) -> f32 { fn coords_to_viewport_uv(position: vec2, viewport: vec4) -> vec2 { return (position - viewport.xy) / viewport.zw; } - -#ifndef NORMAL_PREPASS -fn prepass_normal(frag_coord: vec4, sample_index: u32) -> vec3 { -#ifdef MULTISAMPLED - let normal_sample = textureLoad(normal_prepass_texture, vec2(frag_coord.xy), i32(sample_index)); -#else - let normal_sample = textureLoad(normal_prepass_texture, vec2(frag_coord.xy), 0); -#endif - return normal_sample.xyz * 2.0 - vec3(1.0); -} -#endif // NORMAL_PREPASS - -#ifndef DEPTH_PREPASS -fn prepass_depth(frag_coord: vec4, sample_index: u32) -> f32 { -#ifdef MULTISAMPLED - let depth_sample = textureLoad(depth_prepass_texture, vec2(frag_coord.xy), i32(sample_index)); -#else - let depth_sample = textureLoad(depth_prepass_texture, vec2(frag_coord.xy), 0); -#endif - return depth_sample; -} -#endif // DEPTH_PREPASS \ No newline at end of file