diff --git a/crates/bevy_render/src/experimental/occlusion_culling/mod.rs b/crates/bevy_render/src/experimental/occlusion_culling/mod.rs index a3b067e19f..77fcb4b5b2 100644 --- a/crates/bevy_render/src/experimental/occlusion_culling/mod.rs +++ b/crates/bevy_render/src/experimental/occlusion_culling/mod.rs @@ -4,19 +4,13 @@ //! Bevy. use bevy_app::{App, Plugin}; -use bevy_asset::{load_internal_asset, weak_handle, Handle}; use bevy_ecs::{component::Component, entity::Entity, prelude::ReflectComponent}; use bevy_reflect::{prelude::ReflectDefault, Reflect}; use crate::{ - extract_component::ExtractComponent, - render_resource::{Shader, TextureView}, + extract_component::ExtractComponent, load_shader_library, render_resource::TextureView, }; -/// The handle to the `mesh_preprocess_types.wgsl` compute shader. -pub const MESH_PREPROCESS_TYPES_SHADER_HANDLE: Handle = - weak_handle!("7bf7bdb1-ec53-4417-987f-9ec36533287c"); - /// Enables GPU occlusion culling. /// /// See [`OcclusionCulling`] for a detailed description of occlusion culling in @@ -25,12 +19,7 @@ pub struct OcclusionCullingPlugin; impl Plugin for OcclusionCullingPlugin { fn build(&self, app: &mut App) { - load_internal_asset!( - app, - MESH_PREPROCESS_TYPES_SHADER_HANDLE, - "mesh_preprocess_types.wgsl", - Shader::from_wgsl - ); + load_shader_library!(app, "mesh_preprocess_types.wgsl"); } } diff --git a/crates/bevy_render/src/globals.rs b/crates/bevy_render/src/globals.rs index 49755f4098..04e4109f09 100644 --- a/crates/bevy_render/src/globals.rs +++ b/crates/bevy_render/src/globals.rs @@ -1,25 +1,21 @@ use crate::{ extract_resource::ExtractResource, - prelude::Shader, + load_shader_library, render_resource::{ShaderType, UniformBuffer}, renderer::{RenderDevice, RenderQueue}, Extract, ExtractSchedule, Render, RenderApp, RenderSystems, }; use bevy_app::{App, Plugin}; -use bevy_asset::{load_internal_asset, weak_handle, Handle}; use bevy_diagnostic::FrameCount; use bevy_ecs::prelude::*; use bevy_reflect::prelude::*; use bevy_time::Time; -pub const GLOBALS_TYPE_HANDLE: Handle = - weak_handle!("9e22a765-30ca-4070-9a4c-34ac08f1c0e7"); - pub struct GlobalsPlugin; impl Plugin for GlobalsPlugin { fn build(&self, app: &mut App) { - load_internal_asset!(app, GLOBALS_TYPE_HANDLE, "globals.wgsl", Shader::from_wgsl); + load_shader_library!(app, "globals.wgsl"); app.register_type::(); if let Some(render_app) = app.get_sub_app_mut(RenderApp) { diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index 9f7ae3e637..a2eb1e9cc7 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -1,7 +1,6 @@ pub mod visibility; pub mod window; -use bevy_asset::{load_internal_asset, weak_handle, Handle}; use bevy_diagnostic::FrameCount; pub use visibility::*; pub use window::*; @@ -13,7 +12,7 @@ use crate::{ }, experimental::occlusion_culling::OcclusionCulling, extract_component::ExtractComponentPlugin, - prelude::Shader, + load_shader_library, primitives::Frustum, render_asset::RenderAssets, render_phase::ViewRangefinder3d, @@ -46,8 +45,6 @@ use wgpu::{ TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, }; -pub const VIEW_TYPE_HANDLE: Handle = weak_handle!("7234423c-38bb-411c-acec-f67730f6db5b"); - /// The matrix that converts from the RGB to the LMS color space. /// /// To derive this, first we convert from RGB to [CIE 1931 XYZ]: @@ -101,7 +98,7 @@ pub struct ViewPlugin; impl Plugin for ViewPlugin { fn build(&self, app: &mut App) { - load_internal_asset!(app, VIEW_TYPE_HANDLE, "view.wgsl", Shader::from_wgsl); + load_shader_library!(app, "view.wgsl"); app.register_type::() .register_type::() diff --git a/crates/bevy_render/src/view/window/screenshot.rs b/crates/bevy_render/src/view/window/screenshot.rs index 0dbce3f48d..56d591a365 100644 --- a/crates/bevy_render/src/view/window/screenshot.rs +++ b/crates/bevy_render/src/view/window/screenshot.rs @@ -17,7 +17,7 @@ use crate::{ }; use alloc::{borrow::Cow, sync::Arc}; use bevy_app::{First, Plugin, Update}; -use bevy_asset::{load_internal_asset, weak_handle, Handle}; +use bevy_asset::{embedded_asset, load_embedded_asset, Handle}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ entity::EntityHashMap, event::event_update_system, prelude::*, system::SystemState, @@ -392,9 +392,6 @@ fn prepare_screenshot_state( pub struct ScreenshotPlugin; -const SCREENSHOT_SHADER_HANDLE: Handle = - weak_handle!("c31753d6-326a-47cb-a359-65c97a471fda"); - impl Plugin for ScreenshotPlugin { fn build(&self, app: &mut bevy_app::App) { app.add_systems( @@ -406,12 +403,7 @@ impl Plugin for ScreenshotPlugin { .register_type::() .register_type::(); - load_internal_asset!( - app, - SCREENSHOT_SHADER_HANDLE, - "screenshot.wgsl", - Shader::from_wgsl - ); + embedded_asset!(app, "screenshot.wgsl"); } fn finish(&self, app: &mut bevy_app::App) { @@ -441,6 +433,7 @@ impl Plugin for ScreenshotPlugin { #[derive(Resource)] pub struct ScreenshotToScreenPipeline { pub bind_group_layout: BindGroupLayout, + pub shader: Handle, } impl FromWorld for ScreenshotToScreenPipeline { @@ -455,7 +448,12 @@ impl FromWorld for ScreenshotToScreenPipeline { ), ); - Self { bind_group_layout } + let shader = load_embedded_asset!(render_world, "screenshot.wgsl"); + + Self { + bind_group_layout, + shader, + } } } @@ -470,7 +468,7 @@ impl SpecializedRenderPipeline for ScreenshotToScreenPipeline { buffers: vec![], shader_defs: vec![], entry_point: Cow::Borrowed("vs_main"), - shader: SCREENSHOT_SHADER_HANDLE, + shader: self.shader.clone(), }, primitive: wgpu::PrimitiveState { cull_mode: Some(wgpu::Face::Back), @@ -479,7 +477,7 @@ impl SpecializedRenderPipeline for ScreenshotToScreenPipeline { depth_stencil: None, multisample: Default::default(), fragment: Some(FragmentState { - shader: SCREENSHOT_SHADER_HANDLE, + shader: self.shader.clone(), entry_point: Cow::Borrowed("fs_main"), shader_defs: vec![], targets: vec![Some(wgpu::ColorTargetState {