Skip to content

Commit ad3350f

Browse files
robtfmJMS55cart
authored
0.11 section improve shader imports (#659)
Co-authored-by: JMS55 <[email protected]> Co-authored-by: Carter Anderson <[email protected]>
1 parent f8c56f5 commit ad3350f

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed
22.4 KB
Loading
Loading

content/news/2023-07-07-bevy-0.11/index.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@ Since our last release a few months ago we've added a _ton_ of new features, bug
1717

1818
* **Feature**: description
1919

20+
## Improved Shader Imports
21+
22+
<div class="release-feature-authors">authors: @robtfm</div>
23+
24+
Bevy's rendering engine has a lot of great options and features. For example, the PBR `StandardMaterial` pipeline supports desktop/webgpu and webgl, 6 optional mesh attributes, 4 optional textures, and a plethora of optional features like fog, skinning, and alpha blending modes, with more coming in every release.
25+
26+
Many feature combos need specialized shader variants, and with over 3000 lines of shader code split over 50 files in total, the text-substitution-based shader processor was beginning to creak at the seams.
27+
28+
This release we've switched to using [naga_oil](https://github.com/bevyengine/naga_oil), which gives us a module-based shader framework. It compiles each file individually to naga's IR and then combines them into a final shader on demand. This doesn't have much visible impact yet, but it does give a few immediate benefits:
29+
30+
* The engine's shader code is easier to navigate and less magical. Previously there was only a single global scope, so items could be referenced even if they were only imported indirectly. This sometimes made it hard to locate the actual code behind the reference. Now items must be explicitly imported, so you can always tell where a variable or function originated just by looking at the current file: <br/>
31+
![imported items](imported_items.png)
32+
* Shaders now have codespan reporting, an error will point you to the shader file and line number, preventing a lot of hair pulling in complex shader codebases: <br/>
33+
![codespan](codespan.png)
34+
* naga_oil's preprocessor supports a few more conditional directives, you can use `#else if` and `#else ifndef` as well as `#else ifdef` which was previously supported
35+
* Functions, variables and structs are all properly scoped so a shader file doesn't need to use globally unique names to avoid conflicts
36+
* Shader defs can be added to modules directly. For example, any shader that imports `bevy_pbr::mesh_view_types` now has `MAX_DIRECTIONAL_LIGHTS` automatically defined, there's no longer a need to remember to add it for every new pipeline that uses the module.
37+
38+
The future possibilities are more exciting. Using naga IR opens the door to a bunch of nice features that we hope to bring in future releases:
39+
40+
* Automatic bind slot allocation will let plugins extend the core view bindgroup, which means self-contained plugins for features like lighting and shadow methods, common material properties, etc become viable. This will allow us to modularise the core pipelines to make growing the codebase - while keeping support for multiple targets - more sustainable
41+
* "Virtual" shader functions will allow user modifications to core functions (like lighting), and potentially lead to a template-style material system, where users can provide "hooks" that will be called at the right point in the pipeline
42+
* Language interop: mix and match glsl and wgsl, so bevy's pbr pipeline features could be accessed from your glsl material shader, or utils written for glsl could be used in wgsl code. We're hopeful that this can extend to spirv (and rust-gpu) as well
43+
* More cool stuff we haven't thought of yet. Being able to inspect and modify shaders at runtime is very powerful and makes a lot of things possible!
44+
2045
## Schedule-First ECS APIs
2146

2247
<div class="release-feature-authors">authors: @cart</div>
@@ -47,13 +72,13 @@ app
4772
```
4873

4974
* **There is _exactly_ one way to schedule systems**
50-
* Call `add_systems`, state the schedule name, and specify one or more systems
75+
* Call `add_systems`, state the schedule name, and specify one or more systems
5176
* **Base Sets have been entirely removed in favor of Schedules, which have friendly / short names**
52-
* Ex: The `CoreSet::Update` Base Set has become `Update`
77+
* Ex: The `CoreSet::Update` Base Set has become `Update`
5378
* **There is no implicit or implied configuration**
54-
* Default Schedules and default Base Sets don't exist
79+
* Default Schedules and default Base Sets don't exist
5580
* **The syntax is easy on the eyes and ergonomic**
56-
* Schedules are first so they "line up" when formatted
81+
* Schedules are first so they "line up" when formatted
5782

5883
<details>
5984
<summary>To compare, expand this to see what it used to be!</summary>

0 commit comments

Comments
 (0)