Vertex shader particle billboarding question - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Vertex shader particle billboarding question (/thread-2401.html)
Vertex shader particle billboarding question - TomorrowPlusX - Sep 13, 2008 10:14 AM
I've implemented billboarding in my vertex shader and it works.
Now here's the issue: I've been experimenting with individual per-particle rotation in my vertex shader. So each particle has a vertex attribute "Rotation" which is the amount to rotate that particle in radians. The effect looks awesome... smoke appears to sort of "billow" and flames "roil" and so on.
That being said, my implementation only sort-of works. The particles do rotate, but they lose billboarding as they rotate and the camera moves about.
To give you an idea, here are two screenshots. In the first, the camera's looking pretty much straight down +y ( I use z-up ) and the rotating particles look great:
In the second, I'm looking diagonally, and you can see some particles are sheared:
The approach I'm taking is to get "right" and "up" vectors from the modelview matrix and to then rotate them by the particle's rotation about the camera look vector. Then I do the standard pushing of gl_Vertex in the right direction for that vertex.
Note: If I remove the rotation math, or set the rotation to zero, it looks great.
Now, my guess is that one or both of two things could be happening:
1) My principle is fundamentally flawed! I should be doing it some non-boneheaded way. If this is the case, please let me know!
2) My math for making a matrix that rotates a vector about some other vector is flawed. This strikes me as being a likely culprit. I got this matrix after googling... I've never used it before, since I usually use quaternions for this kind of rotation.
Here's the relevant bits of my vertex shader. The fragment shader is irrelevant here.
Any help is greatly appreciated. That being said, I'm going to see if implementing a quaternion in GLSL isn't too slow for real time stuff.
Vertex shader particle billboarding question - TomorrowPlusX - Sep 13, 2008 10:36 AM
OK, I fixed it by implementing it with a quaternion. Here's the new rotationAboutAxis() method:
It works! And I'm still getting 60fps.
Vertex shader particle billboarding question - Cochrane - Sep 14, 2008 10:39 AM
Just a note: When doing something for which there is already an OpenGL function, then it's always a good idea to look at the code of Mesa3D. The license is liberal enough. By the way, their implementation of glRotatef is nearly identical to your solution.
Vertex shader particle billboarding question - TomorrowPlusX - Sep 15, 2008 06:46 AM
You know, that's funny. It's been so long since I used a direct call to glRotate that I forgot it takes an axis and produces a matrix representing a rotation about it. Also, I agree with using Mesa code for reference... I used it to figure out gluUnproject and friends a while back.