Billboard geometry shader

I’m writing my first geometry shader in glsl. I want to extrude points uploaded to the gpu to two triangles facing the camera (spherical billboards). The idea is to calculate the three axes of the billboard (typical lookat() function) and then position the vertices along these axes. What i’ve got somehow works but the billboards start rotating in the wrong direction when the camera moves close and/or spin around their z axis. Any ideas what i’m missing? What bothers me is that the camera’s rotation is not considered; shouldn’t the billboards’ rotation have to be influenced by that?

Thanks!

#version 330 core

layout (points) in;
layout (triangle_strip) out;
layout (max_vertices = 4) out;

layout(std140) uniform;

uniform Transform
{
        mat4 view;
        mat4 model;

        vec4 animate;
        mat4 bones[64];
} transform;

uniform Projection
{
        mat4 perspective;
        mat4 orthographic;
} projection;

uniform vec3 cameraPosition;

out vec2 textureCoords;

void main()
{
        mat4 mvp = projection.perspective*transform.view*transform.model;

        vec3 center = gl_in[0].gl_Position.xyz;

        vec3 zAxis = normalize( cameraPosition-center );
        vec3 yAxis = vec3( 0.0, 1.0, 0.0 );
        vec3 xAxis = normalize( cross(zAxis, yAxis) );

        yAxis = normalize( cross(xAxis, zAxis) );

        vec3 x = xAxis*0.5;
        vec3 y = yAxis*0.5;

        gl_Position = mvp*vec4( center-x-y, 1.0 );
        textureCoords = vec2( 0.0, 0.0 );
        EmitVertex();

        gl_Position = mvp*vec4( center-x+y, 1.0 );
        textureCoords = vec2( 0.0, 1.0 );
        EmitVertex();

        gl_Position = mvp*vec4( center+x-y, 1.0 );
        textureCoords = vec2( 1.0, 0.0 );
        EmitVertex();

        gl_Position = mvp*vec4( center+x+y, 1.0 );
        textureCoords = vec2( 1.0, 1.0 );
        EmitVertex();

        EndPrimitive();
} 

This is what it looks like atm:

Try ideas from:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=301806#Post301806

Thank you, that does the trick!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.