PDA

View Full Version : Particle engine and billboarding



3_of_8
20-02-2007, 11:41 PM
I'm currently working on a small particle engine. I have to billboard the particles, so I gotta get them perpendicular to the camera. How do I best do that?

When the particle rendering procedure is called, the camera is already translated and rotated. I know the coordinated and the rotation matrix of the camera. How can I get the particles perpendicular?

grudzio
21-02-2007, 12:37 PM
If you use OpenGL then you can use GL_Point_Sprite_ARB (http://oss.sgi.com/projects/ogl-sample/registry/ARB/point_sprite.txt) extension which does all work for you. Take a look at this sample (http://www.codesampler.com/oglsrc/oglsrc_6.htm#ogl_point_sprites).

3_of_8
21-02-2007, 03:00 PM
I don't think that's a good idea. Without that I have FPS at 60, with that extension I have FPS of 3.

3_of_8
21-02-2007, 03:34 PM
Alright, I got it running with that. One problem: How can I do the blending stuff? I mean, my particles should be rendered additive or subtractive, but the background should never shine through.

grudzio
21-02-2007, 04:00 PM
How about glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)?

Nitrogen
21-02-2007, 08:47 PM
Hmm I get the feeling that my site is not as visible as it should be..

I've written a tutorial on how to get billboard sprites in OpenGL.
Get it here: http://www.nitrogen.za.org/viewtutorial.asp?id=12

3_of_8
22-02-2007, 12:08 AM
Billboarding works fine now, thank you. I think I would have never figured that out without your help.

But, blending still doesn't work as it's supposed to. I have about 10 quads overlapping each other and I want them to be blended additively, but I don't want the background to shine through. I got the same problem with subtractive blending.

Huehnerschaender
22-02-2007, 08:49 AM
Seems to be the order in which you draw things... if you don't want to shine things through, draw in reversed order, saying from camera to the back.

3_of_8
22-02-2007, 10:16 AM
I'm drawing the background first, then the particles. Doing it the other way round, all particles are black.

Huehnerschaender
22-02-2007, 11:28 AM
I can imagine 2 reasons why the particles are black:
- you multiply the colors (multiply with black is black)
- you disable zbuffer when rendering the particles... then the background will be drawn "over" the particles.

hmmm... I don't really know what kind of effect you want to achieve... any chance you post a screenshot and explain it a bit clearer?

3_of_8
22-02-2007, 01:22 PM
Did you get what I want it to look like?
http://upload6.postimage.org/380689/particle_right.jpg (http://upload6.postimage.org/380689/photo_hosting.html)

http://upload6.postimage.org/380691/particle_wrong.jpg (http://upload6.postimage.org/380691/photo_hosting.html)

Huehnerschaender
22-02-2007, 02:11 PM
I guess the way the fire looks in the first picture is the way you want it to look like, right?

Now, the problem you have in picture 2 is not a problem of the blending... you add colors, and the blending itself works perfect...

But to achieve the effect you want, you don't have to use ANY effect except using alpha channel.

So the problem lies not in your code, but in your fire image.

This one should be designed with alpha channel, so the parts which should be visible are with no or a bit transparency, and to the edges with more transparency.

3_of_8
22-02-2007, 02:16 PM
I have no fire image. These are all just untextured quads with different alpha values.

Huehnerschaender
22-02-2007, 02:57 PM
Don't you think this is a little "overload" for a fireparticle? :)

Have you tried not to use any blend effect? Just using Alpha? And if so, try decreasing transparency... maybe your "quads" are too transparent.

3_of_8
22-02-2007, 03:32 PM
Well, what do you suggest else? And no blending looks... crappy...

Nitrogen
23-02-2007, 08:12 AM
Instead of GL_ONE, GL_ONE

Try GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA

Or GL_ONE, GL_SRC_ALPHA

(I always forget which argument is which, so if it looks wrong you can try swap the two around aswell.)

3_of_8
23-02-2007, 09:45 AM
The first one doesn't look good and the background shines through, the second one brings the same result I had with GL_SRC_ALPHA, GL_DST_ALPHA. Nice on black background, but not nice on not-black background.

Huehnerschaender
23-02-2007, 11:29 AM
Hi 3_of_8,

I am sorry for not aswering anymore. But I guess I cannot help you any further here, because I am no OpenGL guy. I don't know the renderstates of OpenGL or what they do.

In general I would use a bitmap for fire, no GLQuads. I made fire effects a thousand times in DirectX and never had any problems with it using ADD effect or only Alpha for transparency. Don't know how people do fireeffects in OpenGL, but I cannot imagine that you are the first person with those "problems" :)

3_of_8
23-02-2007, 11:48 AM
Never mind.

Well, you say bitmaps. What do you mean, saying "bitmaps"? A number of Textured quads acting like fire particles or one textured quad which has an animated flame texture on it?

Robert Kosek
23-02-2007, 12:49 PM
What he means is a few texture quads, over just one animated quad. In fact, you can just use an image of a white square, so long as the background fades out correctly. Then you can draw it with a slightly different color and make it vary a little. Or reuse the particle for other effects, like beams and gauss blasts. ;)