Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
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 3813 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
« 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  

Riven (579 views)
2019-09-04 15:33:17

hadezbladez (5497 views)
2018-11-16 13:46:03

hadezbladez (2398 views)
2018-11-16 13:41:33

hadezbladez (5757 views)
2018-11-16 13:35:35

hadezbladez (1220 views)
2018-11-16 13:32:03

EgonOlsen (4659 views)
2018-06-10 19:43:48

EgonOlsen (5680 views)
2018-06-10 19:43:44

EgonOlsen (3196 views)
2018-06-10 19:43:20

DesertCoockie (4094 views)
2018-05-13 18:23:11

nelsongames (5113 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 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!