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:
Material matSphere = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
InjectorScript script = _injector.createScript(matSphere, “Modifyed “+matSphere.getName()+” with Rim Shader injected.”);
script.setParam(“RimLighting”, VarType.Vector4, null, FixedFuncBinding.Color);
StringBuffer code = new StringBuffer();
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”);
script.inject(“uniform vec4 m_RimLighting;n”, 14, 0);
script.inject(code, 277, 0);
(); // switches back to the prev editor.
matSphere = script.compile();
System.out.println("Compiled material: "+matSphere);
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.
And yeah… thats it for now