Billboard particles

Started by
10 comments, last by Rasmadrak 18 years, 5 months ago
Hi, I am having trouble rendering a batch of billboard particles using OpenGL. I've gone through some tutorials but I still can't get it to work. Some of the examples I've seen modify a particle's mesh everytime it is rendered. In my particle system, there is only one mesh loaded and is used by all particles. Every particle calculates its own world matrix (translation, rotation and scaling) that is then used to place the mesh in the world. How should I manipulate the camera and particle matrices to make the particle always face the viewer? I want to this to work regardless of the camera's position and orientation.
Advertisement
This is the way I do it...

clicky

Yepp.... that involves some knowledge in vector math, but I do think you should check it out! :)

Peace!
"Game Maker For Life, probably never professional thou." =)
Your technique requires that I manipulate the mesh's vertices. I'd rather not mess with the vertices and manipulate the matrices to achieve the same effect. Is that not possible?
Do I need to make any modifications to a particle's world matrix or do I just need to alter the camera matrix?
Yes, that's possible as well. :)

In my old code, I used glRotatef() and translate calls to position my particles, but that required every particle to have it's own glBegin/end etc...

The way I do it now, you can simply smack all your particles in one go, and doing it this way is also faster + you get to use vertex arrays.. ;)

I got some sample code that I could post, simple "reset" of the camera matrix - thus making the quad face the camera, when I get home from work, if your interested? But I really recommend to take the full step on this one, since it's definitly worth it! :D

Poor mans billboarding could be implemented as this:

get the direction of the camera (pitch and yaw).

for (each particle)
{
glPushMatrix();
glRotatef(-camera.yaw,1,0,0);
glRotatef(-camera.pitch,0,1,0);
Particle.draw(particle.pos);
glPopMatrix();
}

Note, that this means particles does not face the camera, but rather looking in the direction of the camera, as if the camera would be infite away.

Could work for fast particle systems thou, since no-one really cares when you're shooting people to bits! ;)

Peace!


EDIT:

inline void StartBillboard(){	float modelview[16];	int i,j;	// save the current modelview matrix  	glPushMatrix();	// get the current modelview matrix	glGetFloatv(GL_MODELVIEW_MATRIX , modelview);        // undo all rotations	// beware all scaling is lost as well	for( i=0; i<3; i++ )	    for( j=0; j<3; j++ ) {		if ( i==j )		    modelview[i*4+j] = 1.0;		else	  	    modelview[i*4+j] = 0.0;	    }	// set the modelview with no rotations	glLoadMatrixf(modelview);}inline void EndBillboard(){// restore the previously// stored modelview matrixglPopMatrix();}Usage:StartBillboard();glBegin(GL_QUADS);  jadadadada...glEnd();EndBillboard();


[Edited by - Rasmadrak on October 21, 2005 8:50:34 AM]
"Game Maker For Life, probably never professional thou." =)
I've read the tutorial at LightHouse3D and remember seeing the piece of code you posted (i.e. Cheap Spherical Billboards).

I am trying to implement True Spherical Billboards and even though I use the exact same code, I am still getting errors.

I would appreciate if you posted the code that you are currently using.
hehe, I did post the code I'm currently using, check the link "Clicky"! :)
"Game Maker For Life, probably never professional thou." =)
I thought you were a different poster, :p

Your technique requires that I manipulate the mesh's vertices diretly. I'd rather not mess with the vertices and manipulate the matrices to achieve the same effect. Is that not possible?
I don't think it's possible to not mess with the particles if you want dynamic size AND using vertex arrays or VBO's...

however, if you stick to using immediate mode, you could simply use the code from lighthouse, since it works great! :)
When you say mesh, is it a quad or an actual object (a rock etc)...?

if it's more than a quad, you should store it as a display list or something similar... :)


"Game Maker For Life, probably never professional thou." =)
I am using immediate mode and the particles in this case are just quads, but they can be any kind of shape (e.g. spheres, cubes, etc).

It is just that when I use quads, I'd like them to be facing the viewer at all times.

If and when I get the particle system working properly, then I'll try to optimise.

This topic is closed to new replies.

Advertisement