Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
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 1147 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:: http://www.java-gaming.org/topics/particle-editor-tool/28535/view.html :: 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

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
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.

Myomyomyo.
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!

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (32 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (41 views)
2014-10-26 19:37:11

Luminem (22 views)
2014-10-26 10:17:50

Luminem (27 views)
2014-10-26 10:14:04

theagentd (33 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (58 views)
2014-10-16 15:22:06

Norakomi (47 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!