# Billboard geometry shader

**URL:** <https://community.khronos.org/t/billboard-geometry-shader/65613>\
**Category:** OpenGL\
**Tags:** glsl\
**Created:** [September 16, 2011, 10:07am UTC](https://community.khronos.org/t/billboard-geometry-shader/65613 "2011-09-16T10:07:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vexator](https://community.khronos.org/user_avatar/community.khronos.org/vexator/32/4000_2.png) [@Vexator](https://community.khronos.org/u/Vexator)\
**Post date:** [September 16, 2011, 10:07am UTC](https://community.khronos.org/t/billboard-geometry-shader/65613/1 "2011-09-16T10:07:08Z")

</div>

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!

```auto
#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:

---

<div class="post-metadata">

**Author:** ![Ilian\_Dinev](https://community.khronos.org/user_avatar/community.khronos.org/ilian_dinev/32/109_2.png) [@Ilian\_Dinev](https://community.khronos.org/u/Ilian_Dinev)\
**Post date:** [September 16, 2011, 3:44pm UTC](https://community.khronos.org/t/billboard-geometry-shader/65613/2 "2011-09-16T15:44:55Z")

</div>

Try ideas from:  
[http://www.opengl.org/discussion\_boards/ubbthreads.php?ubb=showflat&Number=301806#Post301806](http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=301806#Post301806)

---

<div class="post-metadata">

**Author:** ![Vexator](https://community.khronos.org/user_avatar/community.khronos.org/vexator/32/4000_2.png) [@Vexator](https://community.khronos.org/u/Vexator)\
**Post date:** [September 17, 2011, 3:30pm UTC](https://community.khronos.org/t/billboard-geometry-shader/65613/3 "2011-09-17T15:30:44Z")

</div>

Thank you, that does the trick!

---

<div class="post-metadata">

**Author:** ![system](https://community.khronos.org/uploads/default/original/2X/b/ba89cb49313a0e869198c8be354afde8bcae027e.png) [@system](https://community.khronos.org/u/system)\
**Post date:** [October 19, 2021, 7:21pm UTC](https://community.khronos.org/t/billboard-geometry-shader/65613/4 "2021-10-19T19:21:03Z")

</div>

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