Merging Material System possible?

Hello monkey, i lately started programing simple shaders.

For example i have a working snow Shader which adds snow based on the normal of an object.



The problem here is that for correct usage i have to add the new technique to each of the materials, which require changing each material definition and all the materials.



Would it not be possible create a material system which allows to merge two materials together at runtime?



From my point of view this would allow to create materials which include only the functions needed. It would also allow to update/fix some technique once instead of fixing it in each used shader. The main advantage would be that it would allow to reuse already programmed techniques very easily.



I have no idea if such a thing is even possible from the tecnical side. Take this just a brainstorm input.

Yeah, just make your own copy of the Lighting material (e.g. MyLighting) and then use that as you would use the Lighting material.

I know about that. I was thinking of an addition to the jme material pipeline which would lead the current pipeline intact but add’s the option to merge materials at runtime.



From the technical side, would it be possible to add following functions to the Material.java

[java]

private void mergeTechnique(HashMap<String, MatParam> paramValues, HashMap<String, Technique> techniques){

Set list=paramValues.keySet();

for (Iterator it = list.iterator(); it.hasNext():wink: {

String tmp=(String)it.next();

this.paramValues.put(tmp, paramValues.get(tmp));

}

list=techniques.keySet();

for (Iterator it = list.iterator(); it.hasNext():wink: {

String tmp=(String)it.next();

this.techniques.put(tmp, techniques.get(tmp));

}

}

public HashMap<String, MatParam> getParamValues(){

return this.paramValues;

}

public HashMap<String, MatParam> getTechniques(){

return this.techniques;

}

[/java]



And then in the Game a simple call to

[java]

Material mat_norm = new Material( assetManager, “Common/MatDefs/Misc/ShowNormals.j3md”);

Material mat_tex = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

Texture tex = assetManager.loadTexture(“Interface/Logo/Monkey.jpg”);

mat_tex.setTexture(“ColorMap”, tex);



Material tex_norm = mat_tex.clone();

tex_norm.mergeTechnique(mat_norm.getParamValues(),mat_norm.getTechniques());



[/java]



Would create a textured material which shows the normals. (I know in this example the ShowNormals technique would overwrite all work done by the TexturedMaterial, but this is just an example)

That is what shader injection would be.

Ah, one of the most hated words on this forum :wink: