docs/bevy/release-content/migration-guides/shaders_use_wesl.md 1.7 K · 46 lines · raw · history

1 ---
2 title: WESL Shaders
3 pull_requests: []
4 ---
5
6 Bevy's shaders are now written in [WESL](https://wesl-lang.dev) and the
7 naga_oil preprocessor is gone. Custom shaders in the naga_oil dialect need to
8 be translated to WESL and renamed from `.wgsl` to `.wesl`. Plain WGSL files
9 with no preprocessor directives keep working.
10
11 ```wgsl
12 // BEFORE
13 #import bevy_pbr::forward_io::VertexOutput
14 #import "shaders/util.wgsl"::hsv_to_rgb
15
16 #ifdef VERTEX_COLORS
17 var<private> tint: vec4<f32>;
18 #endif
19
20 @group(2) @binding(#{MATERIAL_BINDING}) var<uniform> color: vec4<f32>;
21
22 // AFTER
23 import bevy_pbr::render::forward_io::VertexOutput;
24 import super::util::hsv_to_rgb;
25
26 @if(VERTEX_COLORS)
27 var<private> tint: vec4<f32>;
28
29 @group(2) @binding(constants::MATERIAL_BINDING) var<uniform> color: vec4<f32>;
30 ```
31
32 - Imports end with a semicolon and come first in the file, before any
33 declaration or `enable` directive.
34 - Module names now match the shader's path in its crate:
35 `bevy_pbr::mesh_view_bindings` is `bevy_pbr::render::mesh_view_bindings`,
36 `bevy_pbr::prepass_utils` is `bevy_pbr::prepass::utils`, and so on.
37 - `@if`/`@elif`/`@else` attach to whole declarations, struct members, function
38 parameters, imports and statements. Boolean shader defs become conditional
39 compilation flags, and `Int`/`UInt` defs are readable as `constants::NAME`
40 and enable a flag of the same name.
41 - `#define_import_path` is gone. Shaders loaded from `embedded://` are
42 importable at their crate and file path (`embedded://bevy_foo/bar.wesl` is
43 `bevy_foo::bar`), anything else at its asset path.
44
45 The `shader_format_wesl` cargo feature is gone, WESL support is always
46 enabled. GLSL support has also been removed. SPIR-V passthrough is unchanged.