Oultine shader?

Start simple and move to more complex techniques if you are not happy.
Not perfect, but easy as hell. (Might be better to scale the highlight mesh on the shader in the direction of the normal)

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.light.AmbientLight;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

/**
 * test
 * @author normenhansen
 */
public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        Spatial jaime = this.assetManager.loadModel("Models/Jaime/Jaime.j3o");
        Material unshaded=new Material(this.assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
        Spatial jaimeClone=jaime.clone();
        unshaded.setColor("Color", ColorRGBA.Blue);
        unshaded.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Front);
        jaimeClone.setMaterial(unshaded);
        jaimeClone.scale(1.02f);
        jaimeClone.move(0, -0.01f,0);
        rootNode.attachChild(jaime);
        rootNode.attachChild(jaimeClone);
        
            /** A white ambient light source. */ 
    AmbientLight ambient = new AmbientLight();
    ambient.setColor(ColorRGBA.White);
    rootNode.addLight(ambient); 
    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }
}
3 Likes

Ah, nice! I’ll definitively try that! Thanks!

I did one of these a while ago. I think it was just a case of flagging the vertices whos normals are perpendicular to the camera direction and then setting them a different/modified colour in the fragment shader.

Saves rendering the whole object twice

Ok, you did everything in the fragment shader or?

That’s what the Shaderblow does really, you’d just have to pick the code there.

An awesome technique is explained here:

Scroll below to the “Silhouette Effect” section.

2 Likes

Interesting technique.

If you don’t need the glow effect, you might get the a similar result if you just render the object again in a post pass with nearly the same technique the use as a fullscreen pass. Depth to equal and you would elimiate also the overdraw and get the same outline as they get.

But maybe i am missing something…