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  
  Storing / Adding / Drawing particles  (Read 7355 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: 1371
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  

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

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

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

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

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

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

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

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

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

nelsongames (5115 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!