when I add a ShadowFilter on my FilterPostProcessor. I understand it’s because the order of application of filters. I have a FXAA and a Bloom at application startup, and later I have to add one or many shadow filters.
FilterPostProcessor doesn’t allow to add filters at a specific index. So I tried this hack :
List<Filter> save = new ArrayList<>();
save.add(shadowFilter);
for(Filter f : filterPostProc.getFilterList())
save.add(f);
filterPostProc.cleanup();
for(Filter f : save)
filterPostProc.addFilter(f);
It works but is certainly not the best practice. Any advice ?
I’m quite confused with filters too. I just tracked down why I have this exception:
java.lang.UnsupportedOperationException: FrameBuffer already initialized.
at com.jme3.texture.FrameBuffer.setDepthTexture(FrameBuffer.java:448)
at com.jme3.post.FilterPostProcessor.initFilter(FilterPostProcessor.java:171)
at com.jme3.post.FilterPostProcessor.addFilter(FilterPostProcessor.java:112)
And the thing is the order of the filters.
The OP’s solution does the trick but I’ll like to know which is the problem and if it can’t be solve on another way. Why is this happening?, which pieces of filter’s code causes the problem?
An example is using an outline filter and a fog filter. The problem comes if the fog is added after the outline’s. But, why?. I look at the code and I can’t find the reason.
I’m a real noob at filters and post-processors, so… please, have some piety!.
I’d like to share how I solve the ordering problem:
In my games I usually register filters by adding app states. The problem is, that I can’t assure in which order the app states are initialized because they are loaded in a random order from a plugin system.
So I came up with this wrapper for the FilterPostProcessor that allows me to add filters by priority.
For example: lights have priority 500, the sun light 1000 because it flushes the light queue, fxaa has priority 10000, so it is the last one.