don't include file not available on docs.rs (#18551)

# Objective

- Fixes #18539 
- Doc failed to build as an example `include_str!` an asset, but assets
are not available in the packaged crate

## Solution

- Don't `include_str!` the shader but read it at runtime
This commit is contained in:
François Mockers 2025-03-26 07:07:39 +01:00 committed by François Mockers
parent 765e5842cd
commit 1c747bd78c

View File

@ -1,7 +1,6 @@
//! A shader that uses the WESL shading language. //! A shader that uses the WESL shading language.
use bevy::{ use bevy::{
asset::{load_internal_asset, weak_handle},
pbr::{MaterialPipeline, MaterialPipelineKey}, pbr::{MaterialPipeline, MaterialPipelineKey},
prelude::*, prelude::*,
reflect::TypePath, reflect::TypePath,
@ -16,8 +15,6 @@ use bevy::{
/// This example uses shader source files from the assets subdirectory /// This example uses shader source files from the assets subdirectory
const FRAGMENT_SHADER_ASSET_PATH: &str = "shaders/custom_material.wesl"; const FRAGMENT_SHADER_ASSET_PATH: &str = "shaders/custom_material.wesl";
/// An example utility shader that is used by the custom material
pub const UTIL_SHADER_HANDLE: Handle<Shader> = weak_handle!("748706a1-969e-43d4-be36-74559bd31d23");
fn main() { fn main() {
App::new() App::new()
@ -34,14 +31,21 @@ fn main() {
/// A plugin that loads the custom material shader /// A plugin that loads the custom material shader
pub struct CustomMaterialPlugin; pub struct CustomMaterialPlugin;
/// An example utility shader that is used by the custom material
#[expect(
dead_code,
reason = "used to kept a strong handle, shader is referenced by the material"
)]
#[derive(Resource)]
struct UtilityShader(Handle<Shader>);
impl Plugin for CustomMaterialPlugin { impl Plugin for CustomMaterialPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
load_internal_asset!( let handle = app
app, .world_mut()
UTIL_SHADER_HANDLE, .resource_mut::<AssetServer>()
"../../assets/shaders/util.wesl", .load::<Shader>("shaders/util.wesl");
Shader::from_wesl app.insert_resource(UtilityShader(handle));
);
} }
} }