Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (725)
Games in Android Showcase (216)
games submitted by our members
Games in WIP (791)
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  
  Storing / Adding / Drawing particles  (Read 4856 times)
0 Members and 1 Guest are viewing this topic.
Offline roland
« Posted 2012-08-18 04:15:26 »

Hey, I am drawing about 5000 particles. There will probably be 10-20 different types of particles in there, each with different images.
Since switching textures seems to take time, I think the best way is to draw each type 1 particle with the first texture, then each type 2 particle with the next texture, etc until I have drawn all the particles.

I have come up with two different ways to do this, I am wondering which is better? or there is an even better way?

1. have a single list of particles, and loop through it N times where N is the number of different types of particles.
    This means if there are 100 particle types I will have to loop through all the particles 100 times when drawing. But adding particles will be fast.

2. have a Map<ParticleType, List<Particle>> but then whenever I add a new particle I have to find out which list it belongs to.
Using the double-arraylist switching method talked about here by theagentd and princec
means that each time I swap the lists I have to reinsert the list back into the hashmap after I swap it (I would use 2 Maps, one for the current and one for the next)

Offline Riven

« JGO Overlord »

Medals: 1276
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #1 - Posted 2012-08-18 05:33:38 »

Push all your particle sprites in the same texture. Pointing

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline davedes
« Reply #2 - Posted 2012-08-18 06:02:03 »

There are several steps you can take to improving sprite/particle performance with OpenGL:

1. Use a single sprite sheet like Riven said. This really should be the first optimization for any game.
2. Batch all particle quads into a single list -- for example, glBegin, then draw each particle, then glEnd. This should be performant enough to render 5000+ sprites on modern hardware.
3. Simple culling -- don't render anything outside of your desired view.
4. Use GL_TRIANGLES and VBOs (or simple vertex arrays) to further improve performance, instead of immediate mode and glBegin/glEnd. This would probably lead to a LibGDX SpriteBatch-like implementation.
5. If geometry shaders are supported, use them instead of rendering triangles.
6. If performance is still not suitable, look into specific optimizations such as storing velocity/position in a float texture, using OpenCL/CUDA, or what have you.

Generally you'll find your game is "fast enough" at step 3, and the rest exist more or less for the heck of it.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline roland
« Reply #3 - Posted 2012-08-18 06:32:15 »

Thanks for the replies  Grin I will definitely follow the first 3 steps.

What if I want to switch between blend modes for different particle types? should I loop through the list of particles once for each blend mode?
Offline Danny02
« Reply #4 - Posted 2012-08-18 10:47:47 »

why you want to have different blend modes, try to split the particles up in two list. I would think that you won't change the blend modes of a living particle, so that shouldn't be a problem.

Also, as an addition to the optimization list, in OpenGL there is this great PointSpirits extension, were you only have to provide the center point for each particle and OpenGL will expand it automatically to a screen aligned Quad.
Offline roland
« Reply #5 - Posted 2012-08-18 11:55:28 »

I actually only really want two blendmodes at this point:
Additive, for fire, etc

And another for smoke:

If there's a way to just use a single blend mode that will work for both I would like to know it Smiley
otherwise I will use two lists, thanks.

I can't use point sprites because I want rotation as well Sad

Offline Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

Monkey for a head

« Reply #6 - Posted 2012-08-18 12:02:07 »

If there's a way to just use a single blend mode that will work for both I would like to know it Smiley

Pre-multiplied alpha.

[ - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline davedes
« Reply #7 - Posted 2012-08-18 15:37:43 »

Simple solution: use two lists, one containing all "normal blend" particles, another containing all "additive blend" particles. That way you are still taking advantage of batching. A more advanced solution would be to sort all particle elements based on their properties: texture, blend mode, etc.

Fixed function point sprites are generally not a great idea... Maximum size varies wildly between systems, they get culled based on their center, can't use texture atlases, can't use rotation as roland was saying, etc. GL_POINTS and geometry shaders (if supported) would be a better bet.

Offline roland
« Reply #8 - Posted 2012-08-19 04:09:00 »

Ok, I got pre-multiplied alpha working  Smiley I will make a tutorial on it I think
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Archive (63 views)
2017-04-27 17:45:51

buddyBro (275 views)
2017-04-05 03:38:00

CopyableCougar4 (700 views)
2017-03-24 15:39:42

theagentd (701 views)
2017-03-24 15:32:08

Rule (744 views)
2017-03-19 12:43:22

Rule (718 views)
2017-03-19 12:42:17

Rule (722 views)
2017-03-19 12:36:21

theagentd (732 views)
2017-03-16 05:07:07

theagentd (665 views)
2017-03-15 22:37:06

theagentd (506 views)
2017-03-15 22:32:18
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51 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!