Is it possible to code material shaders using nothing but Rust proper? #10384
-
As it stands, all the material shader example code I've looked at uses If it's not, I'm also very curious as to why. A lot of shader code seems to be distributed as if it's a script, despite being a compiled C-like language. The Rust compiler is bigger and more complicated, but it still seems like it should be possible to embed the binary code as an asset instead of compiling on the fly. It also seems a shame, as rust-analyzer can't analyze |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
WGSL is a programming language for shaders. It was designed for WebGPU under the umbrella of the W3C, by engineers from Google, Mozilla and Apple. The best place to learn about WGSL right now is the standard draft: https://gpuweb.github.io/gpuweb/wgsl/#intro Code running on GPU (graphic processing unit) has different constraints than code running on CPU (Central processing unit). Code running on GPU is called "shader", it has a different binary representation than code running on CPU, due to the drastic difference in architecture. You can't1 just compile rust code and run it on GPU. The WebGPU standard, and by extension, the graphics library bevy uses, named But IIRC the same standard specifies that WebGPU should support SpirV3. The WGSL syntax is pretty bad, but definitively better than its predecessors. The WGSL analyzerThere is a VSCode plugin that adds a language server for WGSL files that use the Hot reloadingWGSL code is different from rust code, in that bevy consider WGSL shaders as "assets". Which means, you can launch your game, run it, see the result of your shader, modify the file, save it, and bevy will reload the shader and you'll immediately see the changed shader. This is very different from rust code, where you have to close the game, recompile it, and re-open it. Hot reloading enables you to see the result of your shader changes in a fraction of the time it would make to just type-check your game. Rust-GPUThere is a project spear-headed by Embark that aims to bring Rust to the GPU. It is rust-gpu Some serious people are working on it, but it's still pretty much a prototype. You could theoretically use rust for your shaders, but rust-gpu has serious limitations such as very slow compile times. Footnotes
|
Beta Was this translation helpful? Give feedback.
WGSL is a programming language for shaders. It was designed for WebGPU under the umbrella of the W3C, by engineers from Google, Mozilla and Apple.
The best place to learn about WGSL right now is the standard draft: https://gpuweb.github.io/gpuweb/wgsl/#intro
Code running on GPU (graphic processing unit) has different constraints than code running on CPU (Central processing unit). Code running on GPU is called "shader", it has a different binary representation than code running on CPU, due to the drastic difference in architecture. You can't1 just compile rust code and run it on GPU. The WebGPU standard, and by extension, the graphics library bevy uses, named
wgpu
2, specify WGSL as a manda…