Practising with fireworks

I wanted to play a bit with particle systems, also the new (for me) java.util.concurrent classes. So I made a little multithreaded fireworks demo.

On my notebook drawing semi-transparent images is really slow. I suspect that with other graphics hardware it will be better. The other thing that bugs me is that despite threading, I could not get to 100% CPU, so my threads sleep/wait too often.

The demo will try to move as many particles as possible while retaining 30 FPS. On my notebook the screen looks a bit empty, but maybe you can get more out of it :smiley: (33kb executable jar file).

http://www.java-gaming.org/user-generated-content/members/132627/fireworks-r3.jar

This looks good. :slight_smile: I got 13k particles on spikes, and about 50% CPU usage. I have a quad-core processor.

Thanks for the feedback :slight_smile:

13k particles should give a good firework impression. Some day I want to make more colorful and more detailed particles. But I’m afraid Java2D isn’t the right tool for that.

Cool :slight_smile:

Got 6k particels at max, but 25% cpu :P.
Nice stuff for java2d.

[quote=“Varkas,post:3,topic:40872”]
Well… :persecutioncomplex: I don’t think so either! Most of us have GPU’s though. :point:

23-24k particles here, around 37.5% CPU usage (100% on 3 cores I guess). If you’re interested, I’ve made a few particle engines using different techniques (all using LWJGL though). If you search around the forum you can check them out if you want. One of my first ones used all available cores in your computer to update particles and can render 2 million particles at 60 FPS with 95-100% load on my hyperthreaded quad core (8 threads). It’s actually RAM bandwidth limited, so that number would probably bump up a bit if I got some faster RAM for $40 or so.

That logic doesn’t seem to work for me - ever increasing particle count and ever decreasing framerate - 30k particles at 1 FPS! ;D

Are you using drawImage() for this? From multiple threads? There’s quite a lot in AWT that is single-threaded so could be causing contention.

Would you be willing to share code for this? I’d be interested in converting to run on the software pipeline in Praxis to see what performance is like there for comparison.

This old thread has various blendmodes for working directly with pixel arrays (as used in Praxis). Additive is quite good for particles. http://www.java-gaming.org/topics/some-new-blendmodes-add-multiply-overlay-etc/24529/view.html

Memory accesses are quite expensive indeed. I assume my own demo makes very bad use of cache and memory, many scattered reads and writes.

There are truly amazing particle engines, but in this case it’s less the particle management but the drawing which is the bottleneck. I could use BufferedImages and write directly into the buffer like my raytracing demo does, but I wanted to use Java2D functions this time.

At the moment I’m trying to get a feeling what is slow and what is fast, and what are good ways to display graphics with Java if one doesn’t want to bundle extra libs.

I have a demo which might look a bit better and might have better frame rate control, but it’s hard to guesstimate if this code will adapt well to other machines:

http://www.java-gaming.org/user-generated-content/members/132627/fireworks-r3.jar

Not too bad! You should consider more complex effects… like a particle effect that shoots up and has a particle trail and when it reaches the end it explodes. You could also have the particles that shoot out of that explode as well (much like actual fireworks).

The fountains are fun particle effects, but they’re way too slow for compared to actual fireworks.

Source: I’m a firework

[quote=“ClickerMonkey,post:9,topic:40872”]
Awesome. Never met a… firework, before. :persecutioncomplex:

The new one won’t go over 13k particles, so there’s no way to say if it’s better or worse than the old one.

I’ve been trying to have it going smooth rather than fast. But it’s alright, it’s been an experiment and I’ll let it rest now. I’ve learned a bit again, and want to work on a different project next, which was on hold for more than a year … oh well. I just have too many ideas. I really must convince myself not to try to make an action RPG in low-graphics style in addition to all the other projects.

And I must look into music, what tools are nowadays used. I want to make a new raycasting demo with music and movements choreographed together - but the last time I tried to compose something was in the early 1990’s when MOD files were popular and trackers were the tool of the trade ( http://en.wikipedia.org/wiki/Soundtracker#1990s_and_the_PC )

I’ve been trying to replace painting semi-transparent images for the glow effects with direct data buffer accesses and my own blending methods. I’d have expected that the standard Java implementation (which can use low level C libraries) is at least as efficient as my pure Java solution, but for some strange reason it isn’t.

Latest version with above mentioned changes, and an upped particle limit (should max out at 26k particles, and still be more CPU efficient than before):

http://www.java-gaming.org/user-generated-content/members/132627/fireworks-r4.jar

Edit: seems I have a race condition in the threading code which shows up more frequently now that the painting got more efficient. If the demo doesn’t start or locks up, just kill it and start it again …

Edit: Now also with less Math.sqrt … (don’t ask, I just had a brain fail when I coded that)

http://www.java-gaming.org/user-generated-content/members/132627/fireworks-r5.jar

Edit: If I have to do my own shading for the glow anyways, I can let the shading change with particle age …

http://www.java-gaming.org/user-generated-content/members/132627/fireworks-r6.jar

I get ~21k particles and a steady 30fps. :slight_smile: (With the r6 version)

Good to know :slight_smile:

I’ve been finetuning my blending routines, and tried to balance the threading better. It should consume less CPU time now while showing a bit more particles than before. No big change in particle numbers though.

http://www.java-gaming.org/user-generated-content/members/132627/fireworks-r7.jar

I’m getting 22k particles with r7, and ~103% cpu usage, the r6 gave me ~145% cpu usage. (Dual core with hyper threading, so I guess 1 core and 1.5 cores?)

It’s looking good though. :slight_smile:

Averages at around 10% CPU load now.