"Toon" effect indescernible

Hi.

I just typed the “toon effect” exercise from the beginner’s book, and can’t really see any visible difference. The geometries have that black edge, but it does not seem to make a difference if I call the makeToonish() method or not. I was actually expecting a really strong effect here. So, did I type something wrong, or is the toon effect meant to be hardly visible? I know it does “hit” the geometries, because if I put traces in it, they come out on the console…

Here’s the code:

[java]package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.ZipLocator;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.CartoonEdgeFilter;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.texture.Texture;

public class Cartoon extends SimpleApplication {

private FilterPostProcessor fpp;
private Spatial sceneGeo;
private CartoonEdgeFilter toon;

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

private void makeToonish(Spatial spatial) {
    if (spatial instanceof Node) {
        for (Spatial s : ((Node) spatial).getChildren()) {
            makeToonish(s);
        }
    } else if (spatial instanceof Geometry) {
        Geometry g = (Geometry) spatial;
        Material m = g.getMaterial();
        if (m.getMaterialDef().getName().equals("Phong Lighting")) {
            Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png");
            m.setTexture("ColorRamp", t);
            m.setBoolean("VertexLighting", true);
            m.setBoolean("UseMaterialColors", true);
            m.setColor("Specular", ColorRGBA.Black);
            m.setColor("Diffuse", ColorRGBA.White);
        }
    }
}

@Override
public void simpleInitApp() {
    fpp = new FilterPostProcessor(assetManager);
    viewPort.addProcessor(fpp);
    toon = new CartoonEdgeFilter();
    fpp.addFilter(toon);
    
    assetManager.registerLocator("town.zip", ZipLocator.class);
    sceneGeo = assetManager.loadModel("main.scene");
    rootNode.attachChild(sceneGeo);

    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(0.3f, -0.5f, -0.5f));
    rootNode.addLight(sun);
    
    makeToonish(rootNode);
    
    // Default speed is too slow
    flyCam.setMoveSpeed(20f);
    flyCam.setZoomSpeed(5f);
}

@Override
public void simpleUpdate(float tpf) {
    // NOP
}

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

}
[/java]

I dont think The color ramp is being applied correctly, I’m looking into it now …

Ok, So everything is working as it should, you are correct, in this example, the makeToonish effect is hardly visible. This is because it only effects how the lighting is applied to a Spatial, by adding this ColorRamp it effectively cuts down the shading down from an infinately smooth gradient to only 4 steps or colors. This does not effect the diffuse texture. Since this town scene is mostly flat surfaces it is very hard to see any difference.

I added a sphere to your code by adding the following @ line 61 :

[java]
// ----------- add a sphere to the test scene ----------- //
// create a new sphere
Spatial s = new Geometry(“sphere”, new Sphere(20,20,4));
s.move(0, 4, 0);

    // create a simple lit material for it
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setColor("Diffuse", ColorRGBA.White);
    
    // apply material
    s.setMaterial(mat);
    
    // add sphere to rootNode
    rootNode.attachChild(s);
    
    // move inital camera location to make comparison screen shots easier
    cam.setLocation(new Vector3f(0,4,20));       
    
    // ----------- ----------------------------- ----------- //

[/java]

You can see how the color ramp (makeToonish) is being applied to the lighting on the sphere in the right half of the screen shot :

Hope this helps clear up any confusion =)

  • James

tl:dr - nothing broken; color ramps effect only lighting not diffuse maps ; the town.zip scene is a poor example of makeToonish / color ramps; bacon is awesome;

3 Likes

Thanks! Very helpful answer. :slight_smile: