Returning shader's source instead of path in custom Material #5654
-
I'm trying to create a custom Material but I can't figure out how to create a shader given its source code (included at compile-time via the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Internally, Bevy and other plugins do something like this. const SHADER_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, /* insert a large random number here */);
// You can use this helper macro as suggested by komadori below :)
load_internal_asset!(
app,
SHADER_HANDLE,
"shader/path.wgsl",
Shader::from_wgsl
);
// Which expands to the following code.
let mut shaders = app.world.resource_mut::<Assets<Shader>>();
shaders.set_untracked(SHADER_HANDLE, Shader::from_wgsl(include_str!("shader/path.wgsl"))); And then return this handle from |
Beta Was this translation helpful? Give feedback.
Internally, Bevy and other plugins do something like this.
And then return this handle from
fragment_shader()
.