Howto generate GLSL?

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

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.

1 Like