Kind of late, had some issues, But better late then never right?
Here’s the injector at work, the cube uses a normal lighting shader while the sphere uses a modified instance of it.
Achieving this was not a big task(6h in total), atm I’m kind of “hacking” the material meaning there’s no core modification what so ever. I don’t really like how i made it this far, but well see where it go’s when ill release it.
Heres how i’m making the script:
[java]
Material matSphere = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
InjectorScript script = _injector.createScript(matSphere, “Modifyed “+matSphere.getName()+” with Rim Shader injected.”);
script.setEditingTechnique(“Default”);
script.addDefine(“RimLighting”, “RIM_LIGHTING”);
script.setParam(“RimLighting”, VarType.Vector4, null, FixedFuncBinding.Color);
script.setShaderEditor(ShaderType.Fragment, “
#define ATTENUATION”);
StringBuffer code = new StringBuffer();
code.append("
#ifdef RIM_LIGHTINGn");
code.append(" vec4 rim = pow( 1.0 - dot( normal, vViewDir.xyz ), 1.5 ) * m_RimLighting * m_RimLighting.w;n");
code.append(" rim.a = 0.0;n");
code.append(“gl_FragColor += rim*diffuseColor;n”);
code.append("
#endifn");
script.inject(“uniform vec4 m_RimLighting;n”, 14, 0);
script.inject(code, 277, 0);
//script.forward();
//script.back(); // switches back to the prev editor.
//script.detach();
script.attach();
matSphere = script.compile();
System.out.println("Compiled material: "+matSphere);
matSphere.setTexture(“DiffuseMap”, assetManager.loadTexture(“Interface/Logo/Monkey.jpg”));
matSphere.setColor(“RimLighting”, ColorRGBA.Orange.mult(1.3f));
[/java]
This code is placed in simpleInit() and when i invoke a InjectorScript method, an action is made that action gets to compose an sql string and when the shader files are getting loaded by the asset manager(they go through that AssetManagerHook class you see in my workspace) the sql gets to do it’s business and parse the shader source.
Ugly as fuck, but i’m hoping to make a script file later on, or something; I’m open for ideas.
Right now this injector is cool of a private project, but not something to be added in the core. But if i get clearance from the core devs i can make a new injector inside the core and code it how it should be, right now the injector script creates new matdef and techniquedef classes and thats not how it should act. I chose this since editing the lwjglrenderer is not how a contribution should look like and i can’t really detach/attach shader code with out editing the renderer.
@kwando And yeah… thats it for now