Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
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  
  Storing / Adding / Drawing particles  (Read 2824 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 http://www.java-gaming.org/index.php?topic=27016.0 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)

Thanks,
roland
Online Riven
« League of Dukes »

JGO Overlord


Medals: 818
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
1  
GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE);


And another for smoke:
1  
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);



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: 56
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.

http://home.comcast.net/~tom_forsyth/blog.wiki.html#%5B%5BPremultiplied%20alpha%5D%5D

[ TriangularPixels.com - 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.

 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
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!