I’m trying to achieve a selective outlining effect where a post-processing filter is applied to a subset of objects in the scene, but not to all of them. The goal is to have a “cartoon edge” outline on certain items (e.g., selectable objects) while leaving other parts of the scene (e.g., the environment) untouched.
I’ve been looking at the CartoonEdgeFilter , but it seems to apply the effect globally to everything rendered by the main viewport.
Here are some examples of the effect I’m trying to replicate from Unity:
My question is: What is the recommended or most effective way to handle this in jMonkeyEngine 3?
Is there a way to tell the CartoonEdgeFilter to ignore specific objects?
Should I be using a separate ViewPort that only renders the outlined objects, and then apply the filter to that specific viewport? If so, what is the best practice for setting up and blending this secondary viewport with the main scene?
Any guidance or a code example would be greatly appreciated. Thank you!
Geometries you want rendered with the effect are attached to cartoonView instead of viewPort.
The main drawback is that you can’t safely have a node containing both geometries with and geometries without the effect (just looking at the source code, geometries attached to both will have runControlRender called twice, and you’ll have to be careful when updating those geometries).
Another option is to render a mask to determine where in screenspace the post-processing is applied. CartoonEdgeFilter already renders the scene to get the normals, so you can just add the mask texture as another color target for that render.
The hard part in any solution is how to get the contour. Mostly because you have no information in the buffers outside of the object itself. a inline / mask color, or whatever you want inside the geometry itself is much easier because it does not suffer from these limitations