Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (707)
Games in Android Showcase (207)
games submitted by our members
Games in WIP (781)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Additive Blending with Images and Optimal Sprite Drawing Speeds  (Read 2286 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727
« Posted 2013-03-10 00:51:38 »

For future reference, and for my particle engine, I need to know how to take multiple images and make their colors additively blend for something like fire particles and such. Take a look at StumpyStrusts particle engine:: :: to get a feeling of what I am aiming for. Also, what is a good method for drawing many many sprites at once? I can get up to 50,000 and then I drop to 20 fps without re sizing the image with g.drawImage(pixel, x, y, WIDTH, HEIGHT);. However, when I do resize it, my fps is absolutley horrendous with only 5000 sprites. Any suggestions? Thanks, -cMp
Offline theagentd

« JGO Bitwise Duke »

Medals: 916
Projects: 4
Exp: 8 years

« Reply #1 - Posted 2013-03-10 02:44:32 »

I'd strongly recommend that you move on to OpenGL, either through LWJGL or LibGDX. Although it's possible to get good performance with Java2D, it's inconsistent and has other problems. With OpenGL, you'll get access to your GPU in a much more efficient and powerful way. GPUs have hardware for texture filtering which means that resizing does not cost anything except for the increase in the number of pixels your GPU has to fill. Blending is also extremely fast.

Let's say your particles are 100x100 pixels. That's 10 000 pixels for a single particle. 50 000 of them is 500 000 000 pixels per frame. At 60 FPS, that's 30 000 000 000 pixels per second, or 30Gpixel/sec. On most hardware you're going to get far below 60 FPS, but guess what? A GTX 680 actually has a (theoretical) fillrate of 32.2GPixel/sec, so it's not impossible. When it comes to texture filtering speed, a GTX 680 has an astounding 128.8GTexels/sec, so we're perfectly fine there.

Of course, reducing the number of particles, the size of each particle or the FPS target will reduce the number of pixels per second your GPU has to fill drastically. This was just an example. ^^

The reason why GPUs are so much faster at rendering is because they use lots of stream processing cores. Note that the following numbers are extremely simplified, there's a lot more going on that needs to be taken into consideration to accurately compare performance like this.
 - A quad-core CPU at 3GHz can process 3 000 000 000 * 4 instructions per second = 12 000 000 000 instructions per second.
 - A GTX 680 has 2 688 cores running at around 1GHz ---> 2 688 * 1 000 000 000 = 2 688 000 000 000 instructions per second, which is over 200x as fast.

Offline Slyth2727
« Reply #2 - Posted 2013-03-10 03:11:50 »

Great advice I was already thinking of this too... I would prefer to learn LibGDX, where do you think I should start? I have searched around the internet alot over the past week but havent found a whole lot. Thanks again for the information, I never knew any of that stuff!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline StumpyStrust
« Reply #3 - Posted 2013-03-10 05:07:05 »

You cannot do additive blending with java2d and remain accelerated. I use opengl for my particle engine which is how I can do additive blending. Particles are basically sprites. So if you want lots of them you need a fast sprite batcher. Libgdx has a good one. You should be able to get 50k no problem which actually is more then you should ever need. Both me and davedes posted a tutorial on how to make one if you want to get into opengl.

The biggest bottle neck you will most likely hit in a 2D game is what theagentd talked about which is texture fill. Too many pixels put simply. The more particles you have the smaller they have to be in order to not hit that bottle neck. That is why creating good particle effects can be hard. You don't want too many particles but you also don't want too large of images being used.

Also, my particle engine works for libgdx and they have a particle engine which is probably better but I don't think it can do animated particles. So unless you really want to, don't remake something that has already been done for you.

On a java2d note, I kinda figured out a hack to keep images accelerated whilst doing additive blending but it only works for non opaque pixels which makes it useless.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Galdo (369 views)
2017-01-12 13:44:09

Archive (525 views)
2017-01-02 05:31:41

0AndrewShepherd0 (994 views)
2016-12-16 03:58:39

0AndrewShepherd0 (924 views)
2016-12-15 21:50:57

Lunch (1057 views)
2016-12-06 16:01:40

ral0r2 (1289 views)
2016-11-23 16:08:26

ClaasJG (1386 views)
2016-11-10 17:36:32

CoffeeChemist (1384 views)
2016-11-05 00:46:53

jay4842 (1468 views)
2016-11-01 19:04:52

theagentd (1243 views)
2016-10-24 17:51:53
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!