External Publication
Visit Post

CartoonEdgeFilter makes the entire background black

jMonkeyEngine Hub February 20, 2026
Source

I am using an offscreen viewport to render an object to a texture. I need the texture to be transparent, but as soon as I apply the CartoonEdgeFilter, it makes the background of the texture black:

This is an example where I reproduced this issue:

package com.mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.CartoonEdgeFilter;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.texture.FrameBuffer;
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture2D;
import com.jme3.ui.Picture;

/**
 * This is the Main Class of your Game. You should only do initialization here.
 * Move your Logic into AppStates or Controls
 *
 * @author normenhansen
 */
public class Main extends SimpleApplication {

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

    @Override
    public void simpleInitApp() {

        // The object we want to have an edge
        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);


        Node offscreenNode = new Node("OffscreenNode");
        offscreenNode.attachChild(geom);
        offscreenNode.updateGeometricState();


        int w = 512;
        int h = 512;

        ViewPort offView = renderManager.createPreView("OffscreenView", cam.clone());
        offView.setClearFlags(false, true, true);
        offView.setBackgroundColor(new ColorRGBA(0, 0, 0, 0)); // Transparant!
        offView.attachScene(offscreenNode);

        //Offscreen framebuffer
        FrameBuffer offBuffer = new FrameBuffer(w, h, 1);
        Texture2D offTex = new Texture2D(w, h, Format.RGBA8);
        offBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
        offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex));
        offView.setOutputFrameBuffer(offBuffer);

        // Create the Toon-filter
        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        fpp.setNumSamples(1);
        CartoonEdgeFilter toon = new CartoonEdgeFilter();
        toon.setEdgeIntensity(1.0f);
        toon.setEdgeWidth(4.0f);
        toon.setNormalThreshold(0.5f);
        toon.setDepthThreshold(0.8f);

        fpp.addFilter(toon);
        offView.addProcessor(fpp);

        Picture pic = new Picture("Resultaat");
        pic.setTexture(assetManager, offTex, true);
        pic.setWidth(w);
        pic.setHeight(h);
        pic.setPosition(settings.getWidth() / 2f - w / 2f, settings.getHeight() / 2f - h / 2f);

        pic.getMaterial().getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);

        guiNode.attachChild(pic);


        geom.setLocalRotation(new Quaternion().fromAngles(FastMath.QUARTER_PI, FastMath.QUARTER_PI, 0));


        viewPort.setBackgroundColor(ColorRGBA.DarkGray);


        offscreenNode.updateLogicalState(0f);
        offscreenNode.updateGeometricState();
    }

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

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

How do I get the background to be transparent?

Discussion in the ATmosphere

Loading comments...