bevyengine/bevy
bevy_shader
Shader assets. Defines the Shader type and asset loaders for WGSL, SPIR-V, GLSL (when enabled), and Bevy's own .wgsl import syntax.
Purpose
Shaders are first-class assets in Bevy. The renderer doesn't bake shader bytes into the binary — it loads Shader assets through AssetServer, processes Bevy-flavored imports (#import bevy_pbr::pbr_functions), and feeds the result to wgpu. Hot reloading works on shader assets too.
Directory layout
crates/bevy_shader/src/
├── lib.rs # ShaderPlugin, Shader asset
├── loader.rs # Asset loader for .wgsl / .spv / .vert / .frag
└── compose.rs # Imports / shader def processing (via naga_oil)Key abstractions
| Type | File | Description |
|---|---|---|
Shader |
crates/bevy_shader/src/lib.rs |
Asset; the un-processed source code. |
ShaderImport |
crates/bevy_shader/src/lib.rs |
Names that other shaders can #import. |
ShaderDefVal |
crates/bevy_shader/src/lib.rs |
Compile-time constant or boolean used for shader specialization. |
ShaderPlugin |
crates/bevy_shader/src/lib.rs |
Registers the asset and loader. |
How it works
Shaders are stored as Shader assets. When a pipeline asks for a fragment-shader handle plus a list of shader defs, the renderer (via naga_oil) composes the imports, applies defs, and produces a complete naga::Module that goes to wgpu. The composer caches by (handle, defs) so identical specializations don't recompile.
Integration points
- Depends on:
bevy_app,bevy_asset,bevy_reflect,naga_oil. - Depended on by:
bevy_render,bevy_pbr, every renderer crate.
Entry points for modification
- New shader format: add an
AssetLoaderinloader.rs. Already supported:.wgsl,.spv,.glsl(gated). - Custom import resolver:
compose.rs.
See also
bevy_render— pipeline cache.bevy_pbr— the canonical consumer.- naga_oil documentation for the import syntax.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.