Hello Guest

How would I compile shaders to spv without the glslangValidator file but in code

  • 2 Replies
Hi I recently started porting my game from opengl to Vulkan.
Now I got stuck on shaders. I have this system where I generate many shaders from "modules" depending on what a model needs. (if some face need to be glowing then add glowing module to shader source)
Now this was no issue in opengl as I could simply give the generated source to opengl and it would compile it. So I can't just include some compiled shaders in the game as I allow for user created content. (mods and similar)

  • Compile source to spv from glsl directly in game
  • Force user to have vulkan sdk installed and use command line to call glslangValidator.exe
  • Drop the whole system and lose on performance

Sooo.... first option is by far the best one. I know you can do it in c++ but I am really not sure how I would go about this in LWJGL3.
« Last Edit: October 05, 2017, 19:41:02 by LapisSea »


Offline KaiHH

  • **
  • 55
There are no bindings to GLSL/SPIR-V compilers currently in LWJGL3 to support option 1.
It'd sure be a nice opportunity to add one, though.
See: https://github.com/LWJGL/lwjgl3/issues/77#issuecomment-137675918
Google's shaderc/libshaderc, integrating glslang and SPIR-V Tools, has a particularly simple C API, which I wrote a custom JNI binding to a while ago.
So, it should be very easy to port this to LWJGL3's binding approach with a Kotlin template.

Thanks for the info!  :)
This is means green light for option 2. (however i'd not recommend this as a final solution to anyone with similar problem...)
Hoping that it becomes a reality in next year or so.