Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support shader includes #185

Closed
StarArawn opened this issue Aug 14, 2020 · 10 comments
Closed

Support shader includes #185

StarArawn opened this issue Aug 14, 2020 · 10 comments
Labels
A-Rendering Drawing game state to the screen

Comments

@StarArawn
Copy link
Contributor

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.

@karroffel karroffel added the A-Rendering Drawing game state to the screen label Aug 14, 2020
@StarArawn
Copy link
Contributor Author

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.

@cart
Copy link
Member

cart commented Aug 14, 2020

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.

@StarArawn
Copy link
Contributor Author

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

@fu5ha
Copy link
Contributor

fu5ha commented Aug 15, 2020

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

@StarArawn
Copy link
Contributor Author

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 :)

@fu5ha
Copy link
Contributor

fu5ha commented Aug 15, 2020

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)

@cart
Copy link
Member

cart commented Aug 15, 2020

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?

@fu5ha
Copy link
Contributor

fu5ha commented Aug 15, 2020

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.

@lachlansneff
Copy link
Contributor

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.

@james7132
Copy link
Member

This seems to be resolved as of #3137 and subsequent PRs. It should (?) work for GLSL shaders too, not just WGSL ones. Closing t his issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen
Projects
None yet
Development

No branches or pull requests

6 participants