Performance increase from soft particle code

I discovered a strange increase in fps performance after I copied and pasted the code from the soft particle example (lines 95-98) and later removed it but inadvertently left in

FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
TranslucentBucketFilter tbf = new TranslucentBucketFilter(true);
fpp.addFilter(tbf);
viewPort.addProcessor(fpp);

in simpleInitApp(). I am working on using a bunch of quads to give the illusion of volumetric clouds and since the performance difference is definitely not insignificant, I’d like to understand why the above code affects performance even though I’m not using any translucent objects nor any soft particles.

Without the code:

With the code:

Given that the code isn’t really doing anything if you aren’t using the translucent bucket, it’s easy to be skeptical that something else isn’t going on… especially when we can’t see anything else.

Also, how many times did you test one versus the other? How consistent are the frame rates? etc. I’ve seen that much swing before just when my GPU is overheating… makes timing things lots of fun. See something slow. Make a bunch of changes, recompile, fix syntax errors, recompile, run again (GPU has cooled down) get an extra 100+ FPS. Eureka! think I’ve discovered something only to find I haven’t.

So, we probably need more information.

Edit: also given that the two views are clearly different. Something has changed from one to the other. Make sure you use consistent randomness so that the view is the same every time.

I’ve cut down my code to its bare components and found that those four lines and the drawing of the quads are the only things that affect the performance. The performance difference is very consistent (except for when I force Java to use integrated graphics: then both get 29 fps); I’ve tried running one right after the other, running them with the computer under various loads, and comparing them both the computer’s startup and after hours of computer use. I removed the randomness and got the same results (though performance diminished for both, the difference is still there):

Without the code:

With the code:

Well, thanks for testing it consistently. It’s very strange.

…maybe we should all be adding the magic filter to our code. :smile:

What does ‘and the drawing of the quads’ part mean? You mean when you changed from random to consistent or is there another difference than the four lines in the two images?

Is the term I’m looking for… rendering? By “drawing of the quads” I guess I mean the number of quads rendered (?).

edit: that’s actually a great idea—what happens if I add all of the magic filters? :smiley:

I’m looking for all of the differences between the two pictures. If the number of quads rendered is the same then that’s not a difference and doesn’t affect the performance difference between those two images.

…and the stats indicate that the triangle count is the same. I just wanted to make sure that there wasn’t any other difference.

Yes, you’re correct! The only thing I’m changing between tests is whether or not I comment out those four lines. Everything else is untouched.

Update: other filters have a similar fps boost effect.

ColorOverlayFilter,
ComposeFilter,
FadeFilter,
PssmShadowFilter,
and TranslucentBucketFilter increase the performance the most (but only when used individually), while other filters like BloomFilter and CartoonEdgeFilter have a higher fps than without any filters at all… strange!

P.S. this is a great learning experience for me: I had never used WaterFilter before and it looks good

When you run, do you have AA turned on in the settings dialog?

I used setSamples(16) on the AppSettings. Is that the same thing?

Yes. Don’t do that and see if you get the same performance difference.

Guess: since you don’t set the number of samples on the filter post processor then you are effectively turning AA off whenever you have any filters.

1 Like

Your guess was right on, @pspeed! Thank you so much for your help. I guess there are sacrifices for better performance.

Have a great day, and I love your engine,

Lars

A blind shot out of pure theory.

Standard particle emitter doesn’t sort particles, and they are rendered with no depth test so there is a lot of overdraw.
With soft particles enabled, a sort of depth test is performed in the shader and irrelevant pixels are discarded, which dramatically reduce overdraw.

This only stands if depth write is enabled for the particles though, and I can’t remember if it’s the case by default. Also I guess the transparent nature of the particles kind of defeat that argument… Really…that’s strange…

EDIt…ok didn’t read all the posts… So it was AA…:stuck_out_tongue:

Except we already solved the problem.

For once someone was complaining that his game got faster all af a sudden… That’s a first :stuck_out_tongue:

5 Likes