Java2D Bloom

Try to never squeeze out all your PCs performance. Its likely that you have a better PC than the average user.
And a game usually gets slower during development.

I try to keep a big enough buffer, and test on a relatively slow System.

Anyway, directly manipulating the pixels (((DataBufferInt) screen.getRaster().getDataBuffer()).getData():wink:
of the Raster is quite performant.

Very important is to keep the main rendering loop as short and direct as possible.
Dont do calculations there that you can buffer beforehand.
And dont create any Objects! only reference them

The JHLabs filters don’t offer very good performance for animation. They go through various hoops to keep the BufferedImage from being unmanaged - which is a pointless exercise when you’re updating them every frame. You should create 2 BufferedImages too, otherwise the filter will create a temporary image and do an unnecessary copy every frame. You should also probably not use the createCompatibleImage() method for this either, as the filter is converting the data to ARGB.

Your best bet is to create 2 ARGB BufferedImages, grab the data arrays like @Damocles suggests, and fork the filter code so that you can pass in the input and output arrays rather than BufferedImages. That should speed things up a bit.

You can also use optimized algorithm like in this paper: An efficient algorithm for Gaussian blur using finite-state machines

NOTE: That optimization and multi-dimensional arrays (in java) are mutually exclusive.

Not true, nobody sane uses multidimensional arrays in Java, you just index it manually in single dimensional array.

I don’t understand. You say “not true”, then repeat the same thing I said in different words.

@Roquen - where did multi-dimensional arrays come from?

@jezek2 - is there a Java implementation of that anywhere?

Maybe he referrs to my example code.
I know that single dimensional arrays are quicker. (around 30% for the pure lookup logic)
But I find that is an optimization that can be done in the end. During coding I see multi-dim arrays as much nicer to read and edit.

Things like making a multi to a single array is just mechanical optimization when cleaning up the program.

the main point of the example was to show how much faster direct pixel manipulation is

Oh sorry, thought you meant the optimization in the paper I posted link to.

What kind of dumb question is that? The pseudocode is trivial (and the text describing it is quite simple too), so you shouldn’t have any problem translating it to Java…

A TL;DR one! :wink: Have filed away for later perusal. Still, no matter how simple, it’s always useful when someone’s already done the work for you! ;D

Thank you all for the advice.

When I said 25% cpu I meant that is what your app was running at. I try to keep my stuff running around 5-8% cpu or lower. Currently, this bloom filter runs at 7-15 depending on how many particles there are. I changed the filter so it takes int[] of the pixels and outputs int[], this has sped things up a little I am very impressed. I am still really new to a lot of more complex things when it comes to coding. Here is what I have decided to make after having some fun with this thing.

http://s11.postimage.org/b3smmzfg3/png1.png

Its all done without any images and is very small. Kinda break it styled. Very hard to play because there is so much going on. Lots and lots of glowing particles to distract you from the glowing ball.

The screen looks really nice.

So nice that it is seriously screwing with my eyes. I imagine that is what it looks like when someone that really needs glasses takes them off.

Well done!

Yeah… It seems like your eyes like to do a gaussian-blurr-post-processing-shader instead of giving you a nice picture of what you see…

I’ve got eyes like that too, and if I stand up too quickly I get this wonderful particle effect too - just think of the power of the GPU in my head! :wink:

So everyone who’s ever done a tutorial or answered a question about making tilemaps is insane?

Do you mean I should do it with a 1D array and treat it as a matrix as described here

instead of this:


int[][] tiles = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};


???

I certainly believe not all tutorials uses multi-dimensional arrays, but I get the sentiment. :slight_smile:

There’s a ton of tilemap-implementations, and you can do it however you want. Using a single array is just more of a pain to implement versus the time spent. It’s not worth it, unless you’re looking for a tiny optimization. Mostly, you aren’t. The only “real” difference is the lookup time (it’s about double in the multidimensional), but it doesn’t really make a difference unless you’re quering a lot!

I think those tutorials use that memory layout for the sake of clarity, which is what a tutorial is all about anyway.

Eventually you’re going to store your level in a file, and from there on you don’t give a crap about what the sourcecode representation would be.

On the other hand, one dimensional or multi-dimensional array lookups (for a tile-engine) are not going to be your bottleneck either way.

Thanks for clearing that up. I was afraid I was in for a terribly confusing rewrite of my level-system :emo:

But since you’re querying all tiles in the tilemap (within the screen and all that) every update, wouldn’t it be a big optimization considering it takes half the time to do each look-up with a 1D array?

Don’t guess, measure.

Multiplying a tiny value by 2, still leaves you with a tiny number.