Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  Particle System Implementation  (Read 633 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727
« Posted 2014-04-23 00:15:30 »

To start this out:
I know all the math and stuff needed to create a particle system. It isn't very complicated and it isn't part of the question, so I'm just verifying that.

I plan to add a simple particle system to my (3D) engine that supports texturing, transformation, and additive blending, however I am not quite sure on how exactly to implement it graphics wise.
I have a mesh class that simply holds a vbo and an ibo which get drawn to the screen. The mesh class also holds an array of Vertex (one of my classes. Contains the position, texCoord, normal, and tangent) and integers.

So should I use this class with a shader in order to draw everything somehow, or should I render them some other way, completely different from my mesh class?

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline StrideColossus
« Reply #1 - Posted 2014-04-23 09:13:25 »

I think the question should be whether to use point sprites or not:

1. Bill-board approach:

Sort array of vertices by distance from the camera (for correct blending), generate bill-board quads from your array of vertices, buffer the data into a dynamic VBO, render each sprite as a quad or two triangles.  Your mesh would consist of VBOs for texture coordinates (and colours if required) as well as the quad vertices (or one inter-leaved VBO).

pros:
- re-uses your existing mesh code.

cons:
- over-head of having to orientate the quads to the camera.
- need to provide texture coordinates but these are usually the same for every sprite hence redundant data.

2. Point-sprites:

As #1 but use point sprites rather than billboard quads.

pros:
- re-uses your existing mesh code.
- no need to calculate billboard orientation or texture coordinates.
- usually faster rendering.
- supported by most (all) modern graphics cards (including OpenGL-ES).

cons:
- point sprites have some limitations (e.g. large sprites are culled if the centre point is outside the view frustum) but these are usually not relevant or can be worked around.

Either approach can be enhanced by using a vertex/fragment shader:
- more flexible rendering
- faster than fixed-function pipeline

Note sure why you would need an IBO for a particle system though, or is it just an optional part of your mesh class?

- stride
Offline Slyth2727
« Reply #2 - Posted 2014-04-24 01:05:51 »

The ibo is used so there aren't as many vertices needed overall but it would be trivial to make it optional.
Thanks for the reply, I'll do a bit more research on it now.
Also, when you say I can improve it using glsl you mean just rendering it with glsl correct? Because everything is rendered with shaders by default.

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 theagentd
« Reply #3 - Posted 2014-04-24 02:23:08 »

If you're okay with delving a bit deeper into graphics, you could look into using geometry shaders. That way you can get the best of both worlds.

Myomyomyo.
Offline Slyth2727
« Reply #4 - Posted 2014-04-24 02:32:51 »

I've researched them before and they seem intriguing. What I got from it was that they give the ability to change the primitive rendering type OpenGL uses as well as edit certain other attributes of.. and yeah that's where my knowledge ends.

Google, here I come. If you have any good resources feel free to post them here too.

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 #5 - Posted 2014-04-24 02:42:42 »

The information is out there, but what you can do with them is a bit harder to find. Basically you can draw your particles as "points" which have the attributes that you need: for example position, size, rotation and color. Then you can use a geometry shader to output 4 new vertices to form a quad, allowing you to do proper billboarding without transforming on the CPU (transform by view matrix first, expand to screen aligned quad, transform by projection matrix). You can also apply stuff like rotation and generate texture coordinates for each corner. Without geometry shaders you'd be forced to render the particles as quads with 4 vertices each, but a lot of this information is just data that's shared by all 4 vertices. For example there's no need to supply 4 positions when one position and a size is enough.

Myomyomyo.
Offline Slyth2727
« Reply #6 - Posted 2014-04-24 02:51:53 »

That's mind blowing. Wow that really is cool, thanks for elaborating!
When you say transform by view matrix, then expand to screen aligned quad, the screen aligned part refers to bill boarding part right?

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (40 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!