problem: directional billboarding
Posted: 04 Aug 2007, 20:31
i am writting a particle system in lua and trying to convert the simpleparticle class to use shaders.
now i have a problem with the "directional" feature of csimpleparticle.
first what it does: it rotates the quad (it is still billboarded) so it points to the speed vector, i.e. an effect that start in a point and the particles escaping from it -> all quads would point away from the start point.
the code that does this is in worldspace:(dir1 is the up vector and dir2 the right vector)
now i can't copy this code, cuz i use the a vertex shader to billboard my quads. so i have to rotate the quads in eyespace, but all my tries (>4 different codes) don't worked at all or only if the speed vector directly points to the sky (in worldspace coord)
my concept is:
now i have a problem with the "directional" feature of csimpleparticle.
first what it does: it rotates the quad (it is still billboarded) so it points to the speed vector, i.e. an effect that start in a point and the particles escaping from it -> all quads would point away from the start point.
the code that does this is in worldspace:
Code: Select all
float3 dif(particles[i].pos-camera->pos);
float camDist=dif.Length();
dif/=camDist;
float3 dir1(dif.cross(particles[i].speed));
dir1.Normalize();
float3 dir2(dif.cross(dir1));
now i can't copy this code, cuz i use the a vertex shader to billboard my quads. so i have to rotate the quads in eyespace, but all my tries (>4 different codes) don't worked at all or only if the speed vector directly points to the sky (in worldspace coord)

my concept is:
- convert the speed vector into eyespace coord: vec3( gl_ModelViewMatrix * vec4(speed,0.0) )
- calculate the 2d angle between the eyespace up vector and the eyespace speed vector. i tried many codes to do so, but none worked
(please note the speed vector still has a z coord, but i only want the up and right components of the speed vector) - rotate the quad with: mat2 rotation = mat2( cos(alpha), -sin(alpha), sin(alpha), cos(alpha) )