Hi everybody, I am trying to work a modding system into Armory and I'm in need of a way to load shaders dynamically from mods.
The way Kha games normally load shaders, as far as I understand, is:
- The Shaders in the project are located by Khamake.
- Khamake writes out a
files.json
file with references to all of the compiled shaders, which are stored in a<target>-resources
directory. - The
kha.internal.ShadersBuilder.build()
macro is used to build thekha.Shaders
class and provide a field in that class for every shader found by Khamake.
This workflow hardcodes the shaders available to the game at build-time, which is fine for most circumstances, but not if I need to dynamically load mods.
I found this function in the FragmentShader
class and I was wondering if this would let me load a shader at runtime, but it has a warning about the function not being portable.
My Questions:
- Does anybody know what "not portable" means exactly?
- Would it work if I loaded the Shader data blob at runtime from a file and created a
FragmentShader
instance with thefromSource
function? - Are there any better ways to do this that I am not aware of?
Kha/Graphics4/FragmentShader.hx:
/**
Beware: This function is not portable.
**/
public static function fromSource(source: String): FragmentShader;