Post processor filters' order

Hi there !

I’ve got an exception saying :

FrameBuffer already initialized

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 ?

Thanks !

Add all of your filters in a consistent order and then enable/disable them?

There may be unstated reasons that’s not possible, I guess. It’s how I’ve resolved the issue personally.

I will remember the enable/disable tip but I don’t know at startup how many shadow map I will need, this should stay dynamic.

I will just put the code to restack the filters in a method and that will do the trick.

But I’m curious. Since the order is important, what is the reason that led to set the filter’s list unmodifiable in the post processor filter?

Thanks !

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!.

Wiki link to the effects subject.

I’ll look into it.

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.

https://github.com/shamanDevel/shaman.rpg/blob/712f0cab6c650061b0dba9336489e41dc9c0861a/Engine/Engine-Core/src/org/shaman/rpg/engine/core/FilterContainer.java

1 Like