Bevy: Support shader includes

Created on 14 Aug 2020  路  9Comments  路  Source: bevyengine/bevy

This is pretty common and looks something like this:

#include "./my_include.glsl"

One problem would be that the current shader compiler we use does not support includes. Currently shaderc supports includes, and I believe naga will support them as well.

rendering

Most helpful comment

Thinking about this a bit more. If we add PBR for example it would be handy to have a way for a bevy user to include a general "lighting.glsl" include that comes from bevy. This lets them build out their own shader but still hook into our existing lighting and shadow techniques.

All 9 comments

Thinking about this a bit more. If we add PBR for example it would be handy to have a way for a bevy user to include a general "lighting.glsl" include that comes from bevy. This lets them build out their own shader but still hook into our existing lighting and shadow techniques.

Agreed on all counts. I think this should be a relatively easy win, but if its not id prefer to wait for naga as this won't block progress on the renderer.

Yeah I think waiting for naga is probably best. Shaderc is just too much, and making your own system is probably not worth it.

IMO shaderc isn't that bad. It's a bit annoying but it's just a one time install. Basically just install ninja and you're good to go. Moving in the direction of bundling precompiled spirv so things "just work" out of the box and then using shaderc under a shader-compiler feature flag for those who want to mess with shader development work shouldn't be particularly hard and would unblock this stuff while naga is being waited on.

Another option would be to use a Rust crate like glsl-include in the interim

Basically just install ninja and you're good to go.

It's not that simple. You need python too, and I had a hell of a time getting cmake to find python even though it was installed and in the path. glsl_include looks really cool :)

If building from source is too much of a pain, using precompiled shaderc libs and just pointing the env variable to it is pretty reliable (and the recommended way unless it doesn't work on your platform).

https://github.com/google/shaderc-rs#setup

(note just linking the above for posterity, not trying to be rude or say you didn't see it or anything)

Yeah that seems reasonable. I was worried env variables would make it less of a "works out of the box" experience. Is there a way to set env variables in Cargo.toml?

Don't believe so... not sure that's a great idea even if it was possible.

Instead I'd suggest using the same route Amethyst does:

Check in precompiled .spv files for all default shaders which can be ingested directly so that no shader compiler is needed by a default user just downloading bevy.

Then under a feature flag, add shaderc (and add/point to docs about how to set it up) for those who want to actually mess with shaders.

I'm experimenting with replacing spirv-reflect and glsl-to-spirv with naga. Naga isn't totally there yet, but I think it's close enough to have behind a feature flag until it's a little more mature.

Was this page helpful?
0 / 5 - 0 ratings