Skip to content

Commit 1c747bd

Browse files
committed
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
1 parent 765e584 commit 1c747bd

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

examples/shader/shader_material_wesl.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! A shader that uses the WESL shading language.
22
33
use bevy::{
4-
asset::{load_internal_asset, weak_handle},
54
pbr::{MaterialPipeline, MaterialPipelineKey},
65
prelude::*,
76
reflect::TypePath,
@@ -16,8 +15,6 @@ use bevy::{
1615

1716
/// This example uses shader source files from the assets subdirectory
1817
const FRAGMENT_SHADER_ASSET_PATH: &str = "shaders/custom_material.wesl";
19-
/// An example utility shader that is used by the custom material
20-
pub const UTIL_SHADER_HANDLE: Handle<Shader> = weak_handle!("748706a1-969e-43d4-be36-74559bd31d23");
2118

2219
fn main() {
2320
App::new()
@@ -34,14 +31,21 @@ fn main() {
3431
/// A plugin that loads the custom material shader
3532
pub struct CustomMaterialPlugin;
3633

34+
/// An example utility shader that is used by the custom material
35+
#[expect(
36+
dead_code,
37+
reason = "used to kept a strong handle, shader is referenced by the material"
38+
)]
39+
#[derive(Resource)]
40+
struct UtilityShader(Handle<Shader>);
41+
3742
impl Plugin for CustomMaterialPlugin {
3843
fn build(&self, app: &mut App) {
39-
load_internal_asset!(
40-
app,
41-
UTIL_SHADER_HANDLE,
42-
"../../assets/shaders/util.wesl",
43-
Shader::from_wesl
44-
);
44+
let handle = app
45+
.world_mut()
46+
.resource_mut::<AssetServer>()
47+
.load::<Shader>("shaders/util.wesl");
48+
app.insert_resource(UtilityShader(handle));
4549
}
4650
}
4751

0 commit comments

Comments
 (0)