Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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  
  Particles  (Read 2162 times)
0 Members and 1 Guest are viewing this topic.
Offline Mads

JGO Ninja


Medals: 24
Projects: 3


One for all!


« Posted 2010-08-28 21:54:44 »

How'd you go about making a particle system?
Make a thousand particle objects, that are painted seperately?
^How would you do that? Manually? A loop is impossible..

Am I overlooking something? How do you do it? Smiley

Offline ryanm

Senior Member


Projects: 1


Used to be bleb


« Reply #1 - Posted 2010-08-28 23:03:37 »

A loop is impossible..
Why?

There's not really any magic to particle systems, it's just a load of coordinate, velocity, and lifetime/colour/whatever data that you loop through to update and paint.
The thing not to do is have an object per particle to encapsulate this data - you'll waste enormous amounts of memory on object overhead and it probably wont be cache-friendly. Instead, pack the data for loads of particles into a few float arrays. For instance:
1  
2  
3  
4  
5  
6  
7  
float[] particles = new float[]{px1, py1, vx1, vy1, px2, py2, vx2, vy2, ...};
// move particles
for( int i = 0; i < particles.length; i+=4 )
{
   particles[ i ] += particles[ i+2 ] * timeDelta;
   particles[ i+1 ] += particles[ i+3 ] * timeDelta;
}
Offline Nate

JGO Kernel


Medals: 129
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #2 - Posted 2010-08-28 23:41:33 »

An example:
http://code.google.com/p/skorpios/source/browse/trunk/#trunk/skorpios-common/src/com/esotericsoftware/skorpios/opengl/particles
See Emitter and PointEmitter for the simplest example. Note the numbers are fixed point.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 12


Game Engineer


« Reply #3 - Posted 2010-08-29 01:53:18 »

Also, if you're using OpenGL, it helps to have particles sorted by texture, otherwise you're doing a whole lot of wasteful texture binding.

See my work:
OTC Software
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2010-08-29 12:08:08 »

Also, if you're using OpenGL, it helps to have particles sorted by texture, otherwise you're doing a whole lot of wasteful texture binding.

That usually only works well for sprites. Particles often have translucent textures, which means you have to depth-sort them.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 12


Game Engineer


« Reply #5 - Posted 2010-08-30 05:15:00 »

That usually only works well for sprites. Particles often have translucent textures, which means you have to depth-sort them.
This is a true statement. Instead you just put all your particles into a single giant texture atlas. :-)

See my work:
OTC Software
Offline Roquen
« Reply #6 - Posted 2010-08-30 10:02:31 »

Also, they don't have to be truly sorted.  If your willing to have minor defects (i.e. very unlikely to be noticed), they can be simply be "mostly" sorted.  There's also order independent transparency techniques.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2010-08-30 10:33:39 »

As particles often slowly change in relative depth, you can use gnome sort

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline OttoMeier

Senior Member


Medals: 4
Projects: 1



« Reply #8 - Posted 2010-09-09 17:16:57 »

why do to depth-sort?
I set the deepbuffer to readonly that should have the same effect or?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2010-09-09 17:20:38 »

When blending, order matters.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline OttoMeier

Senior Member


Medals: 4
Projects: 1



« Reply #10 - Posted 2010-09-09 18:21:25 »

When blending, order matters.
I still dont understand that. Do you know an example?
Offline lhkbob

JGO Knight


Medals: 32



« Reply #11 - Posted 2010-09-09 21:55:21 »

Lets say you have two particles that are overlapping. One particle is red and the other is blue. Their ideal colors would then be (1, 0, 0) and (0, 0, 1).  At a pixel where they're overlapping, they both have a transparency of .9

A common way of blending particles is additive blending:
1  
final_color = alpha * color + (1 - alpha) * old_color

If the red particle is drawn first, the final color is:
1  
.9 * (0, 0, 1) + .1 * (.9 * (1, 0, 0) + .1 * (0, 0, 0)) = (.09, 0, .9)


When the blue particle is draw first, the final color is:
1  
.9 * (1, 0, 0) + .1 * (.9 * (0, 0, 1) + .1 * (0, 0, 0)) = (.9, 0, .09)


Now, if the red particle is drawn first but has a nearer z level than the blue, you want to render the (.9, 0, .09) color but if you don't do depth sorting, you could display the (.09, 0, .9) color instead.  This is clearly wrong and can look weird when the perspective transform clearly tells the user that the blue is farther away but the colors claim the blue is nearer.

Offline OttoMeier

Senior Member


Medals: 4
Projects: 1



« Reply #12 - Posted 2010-09-11 15:34:37 »

thx for the example. Now i understand the problem Wink
I still not sure if i need depth-sort because the particles often have similar colors and i see no obvious faults in my examples. Do you use depth-sort in your particle engine?
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 12


Game Engineer


« Reply #13 - Posted 2010-09-11 19:56:06 »

thx for the example. Now i understand the problem Wink
I still not sure if i need depth-sort because the particles often have similar colors and i see no obvious faults in my examples. Do you use depth-sort in your particle engine?
I rarely depth sort my particles.

See my work:
OTC Software
Offline princec

JGO Kernel


Medals: 282
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #14 - Posted 2010-09-11 20:31:32 »

All of our particles are depth sorted. In fact all of our sprites are. It barely takes the blink of an eye compared to everything else going on.

Cas Smiley

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.

xsi3rr4x (31 views)
2014-04-15 18:08:23

BurntPizza (28 views)
2014-04-15 03:46:01

UprightPath (43 views)
2014-04-14 17:39:50

UprightPath (26 views)
2014-04-14 17:35:47

Porlus (42 views)
2014-04-14 15:48:38

tom_mai78101 (64 views)
2014-04-10 04:04:31

BurntPizza (124 views)
2014-04-08 23:06:04

tom_mai78101 (224 views)
2014-04-05 13:34:39

trollwarrior1 (190 views)
2014-04-04 12:06:45

CJLetsGame (198 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!