Skip to content

Conversation

beicause
Copy link
Contributor

@beicause beicause commented Oct 7, 2025

Objective

Fixes #20285

Solution

If wesl shaders import a dependency from a named asset source (e.g. embeded), we register the dependency into the bevy_asset module so it can be imported as import bevy_asset::{asset_source}::{asset_path} (my current proposal, open for discussion). super also works.

Testing

Modified the shader_material_wesl example to import embeded wesl for testing.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 7, 2025
@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds D-Shaders This code uses GPU shader languages labels Oct 7, 2025
@beicause beicause force-pushed the fix-wesl-embeded-path branch from 2f56f3e to f7ca21e Compare October 8, 2025 04:48
@beicause beicause force-pushed the fix-wesl-embeded-path branch from f7ca21e to cc49321 Compare October 8, 2025 05:05
Comment on lines +62 to +71
let asset_server = app.world_mut().resource_mut::<AssetServer>();
let utils_handle =
asset_server.load::<Shader>("embedded://shader_material_wesl/files/util.wesl");
let vertex_attr_handle =
asset_server.load::<Shader>("embedded://shader_material_wesl/files/vertex_attr.wesl");
let custom_material_import_handle =
asset_server.load::<Shader>("shaders/custom_material_import.wesl");
app.insert_resource(UtilityShader(utils_handle))
.insert_resource(VertexAttrShader(vertex_attr_handle))
.insert_resource(CustomMaterialImportShader(custom_material_import_handle));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's bad to manually import every dependency. But Shader::from_wesl requires parsing dependencies in advance when loading (such as naga_oil::compose::get_preprocessor_data), which wesl-rs currently doesn't provide.

@tychedelia
Copy link
Member

Hey @beicause, I'm currently working on porting all our shaders to WESL and will need to account for some of this. I'm not sure we can merge this as-is or if that work will conflict there, but I may cherry-pick some of this there. We definitely need to have a bigger conversation about import paths as part of this. I'm not sure I love the bevy_asset::embedded pattern, however, because embedded assets aren't really "in" bevy_asset.

@beicause
Copy link
Contributor Author

beicause commented Oct 9, 2025

In my opinion, it is necessary to register the asset source in a specific package (not necessarily using the approach from this PR).

If it is registered at the root module, such as import package::{asset_source}, it may occupy a actual folder.

For example https://docs.rs/wesl/latest/wesl/struct.StandardResolver.html#method.add_constant also registers constants in a non-existent "constants" package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Assets Load files from disk to use for things like images, models, and sounds A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible D-Shaders This code uses GPU shader languages S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Illegal path when importing embedded wesl shaders

3 participants