| Crates.io | shadermagic |
| lib.rs | shadermagic |
| version | 0.1.2 |
| created_at | 2023-09-19 18:17:54.374632+00 |
| updated_at | 2024-06-21 23:13:33.036744+00 |
| description | Pseudo-glsl to msl and glsl transpiler. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 977100 |
| size | 23,765 |
shadermagic is a crate I wish existed. Think Therkla's hlslparser, but rust native.
shadermagic pretend to be a compiler from pseudo-glsl to different glsl variants and Metal's MSL.
If you want something that actually works, check naga, spirvcross, sokol-shdc, glslang, glslcc, hlsl parser, hlslparser fork or even nanoshredder.
Another relevant case study is this emscripten hack. shadermagic is a slightly more advanced version of the same idea.
shadermagic takes some undocumented almost #version 130 shader and apply a ton of String::replace to make plain version 100, version 100 with webgl1 extensions, 130, 330, 300 es and metal's MSL.
Metal is a bit of a special case, with a bit of extra code on top of String::replace. But it is still very sipmple string manipulations. shadermagic knows nothing about AST and shaders semantics.
shadermagic will never work well on arbitary glsl input. No amount of string::replace could replace a compiler. However, it might be possible to design shaders specifically for shadermagic, and it might take less work than hand-writing for each target. Or not! I really hope I put enough warnings here.
Enough with warnings, tips to keep this bunch of hacks afloat:
main() function, pass them as arguments.