Oultine shader?

Ok, is that a shader?

Because, I need several functionalities in my shader. Currently I made a modified version of the default Light/Lighting shader that is included. I added this functionality: Shader Nodes, Inputs for LightMapping node? (Solved) - #6 by afflicto

Yes it is but it’s registered as a filter by jme.

You can take the code and use it as you want.

Ok, I’ll looking into that, thanks!

Ok, so apparently the cartoon edge filter works on the entire scene, not just on specific objects. (according to this post: Cartoon Edge Filter - insight needed - #2 by nehon)

So I can’t use it :\

Maybe is it a good idea to highlight the entire object?
The most easy way to do is to make an Class that implements SceneProcessor. Such renderer should have an setObjectForHighlight or addObjectForHighlight, I dont know if you need to highlight just one or more objects at a time. Anyway, in postFrame you need to test if the object is on viewport’s queue, if so:

    _renderManager.setForcedTechnique("Highlight");
    
    Camera cam = _viewPort.getCamera();
    _viewPort.getQueue().renderShadowQueue(_list, _renderManager, cam, false);
    
    //_renderManager.setForcedMaterial(null);
    _renderManager.setForcedTechnique(null);
    _renderManager.setCamera(cam, false);

Where _list contains your object.

And the entire magic comes with .frag:

void main()
{
    gl_FragColor = vec4(0.2, 0.2, 0.2, 0.5);
}

Set Blend to Additive in Technique.

The result:

in the Shaderblow plugin I think there is an outline capability directly in the lighting shader.

unofrtunately Google decided to make google code painful so you can’t consult the code online anymore because there are too much sub folders in the ocntribution repo…so you either have to checkout the SVN repo, either to use the plugin int he SDK and look at the code
Edit look for lightBlow.j3md

Hi, thanks. I suppose I could do that. The only issue is, I’m using color to distinguish between players (I’m making an RTS), so changing the entire color is not the best approach.

For some reason, it seems I can’t install any plugins in the SDK. It just says it failed to install the plugin. Running 3.0 stable on Ubuntu 14.04.

I guess I can checkout the SVN repo and copy-paste :\

Is the player’s color an parameter passed to the shader? If so, use it in Highlight too.

What I mean is that, changing the entire color of the object is not a good idea because of UX (user experience) since the color of the object serves a purpose (to distinguish players). I’m working on implementing this though for testing purposes.

My guess is that they are rendering the object twice.

for each highlighted object
Pass 1: increase the size a little bit, cull front faces, render solid color
Pass 2: render as usual

Might be also possible to render pass 1 after pass 2 as post filter

chown +x jmonkeyplatform/jdk/bin/*

Hm, interesting approach. Although, since it’s rendering the object twice, wouldn’t this be costly?

Easy to test i guess :wink:
As a shot in the dark, i would assume way cheaper then a fullscreen pass.

Did that, still get the same error:

The Plugin Installer found problem timeout of loading shaderblowlib[shaderblowlib/0.1.1469]
while install the following plugins:

shaderblowlib

I’m gonna move this to a separate topic. I can’t seem to be able to update the core JME application either.

Actually, there seems to me other topics about the exact same issue.

Sure. Not sure how though, gotta read up on SceneProcessor and stuff, I guess.

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?