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