I want to generate some shader code (a lib) at runtime, how should I go about this? The generated shader code will not change once it is generated.
@kwando said:
I want to generate some shader code (a lib) at runtime, how should I go about this? The generated shader code will not change once it is generated.
AFAIK it should be possible to simply get the Source from a specific technique and then modify it. You probably have to add some code to the core:
[java]
//Adding this to Technique.java
public void Shader getShader(){
return this.shader;
}
[/java]
Might already be enough. It gives you access to the shader, which gives you access to the sources-.-
But i don't know what happens when you change the code...
I could just spit out a mylib.glsllib file a temporary folder at startup and register a AssetLocator for that folder and then let jME handle everything for me⦠but I donāt like to do it like so⦠There have to be some other neat way of doing it.
Depends what you are trying to reach, the easies thing would be to add a techniqueā¦
If you simply want to āinjectā the deferred technique in the default lighting material something like this would work:
[java]
Material deferredMaterial=new Material();
Material lightingMaterial=new Material();
lightingMaterial.getMaterialDef().addTechniqueDef(deferredMaterial.getMaterialDef().getTechniqueDef(āDeferredā));
[/java]
or similar, donāt know what happens with the uniformsā¦
Hmm, interesting approach. But itās not what Iām trying to accomplish here. I would like to specify the GBuffer layout in java code and then generate the encoding/decoding scheme (essentially the GBuffer.glsllib file) on the fly
Hmmm, well then using this allows you to put your generated code into a Technique
[java]
TechniqueDef technique=new TechniqueDef();
technique.setShaderFile(String vertexShader, String fragmentShader, String vertLanguage, String fragLanguage);
mat.getMaterialDef().addTechniqueDef(technique);
[/java]
Might be a start, but again, donāt know about uniform bindingsā¦
As the shader files are loaded from the assetmanager you can simply provide a loader that generates the files when they are loaded.