-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
WESL: Suport importing shader from asset source #21440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
2f56f3e
to
f7ca21e
Compare
f7ca21e
to
cc49321
Compare
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)); |
There was a problem hiding this comment.
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.
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 |
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 For example https://docs.rs/wesl/latest/wesl/struct.StandardResolver.html#method.add_constant also registers constants in a non-existent "constants" package. |
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 asimport 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.