Here is a super simple outline material I made a while back, its not really finished, but it works and is a great starting point for something… what that is yet I don’t know. Being such a simple example this could be a useful learning tool for monkeys.
Material Outliner Ver 0.1 Download
It’s very basic, it renders the geometry a second time, scaled along the normals and inverted (I obviously didn’t invent this, just implemented it in my own way).
The guts of how it works :
I pulled out some of the more important bits of code to go over.
We can start off simple …
public class OutlineMaterial extends Material {
with me so far ? Good !
OutlineMaterial keeps a reference to the original material for the geometry so it cal use it later.
So all that OutlineMaterial really does is render the geom twice …
@Override
public void render(Geometry geometry, LightList lights, RenderManager renderManager) {
// render the original material
if (baseMaterial != null) {
baseMaterial.render(geometry, lights, renderManager);
}
// render the outline
super.render(geometry, lights, renderManager);
}
… straight forward so far yes ?.
Now a simple vertex shader to scale along the normals …
vec3 P = inPosition + (inNormal * (m_Thickness/10.0) );
aaaaaaaaand profit.
Caveats :
- It will only work with smoothed faced (smooth normals) meshes, since it scales along normals A standard jme Cube (for example) would just push the faces out and not scale them up.
I probably have more to add but I have to start my Christmas shopping >=(
Cheers
James