PDA

View Full Version : Problems with drawing primitives as billboards



frankie
10-20-2014, 11:58 PM
I am currently trying to draw primitives as billboards (make them faced to screen). I already know how to draw texture as billboards.

For some reasons I see nothing. I already made some efforts but they are failed. Please, consider my shaders code.

Vertex Shader


in vec3 position;

uniform mat4 og_modelViewPerspectiveMatrix;
uniform mat4 og_viewportTransformationMatrix;

vec4 ModelToWindowCoordinates(
vec4 v,
mat4 modelViewPerspectiveMatrix,
mat4 viewportTransformationMatrix)
{
v = modelViewPerspectiveMatrix * v; // clip coordinates
v.xyz /= v.w; // normalized device coordinates
v.xyz = (viewportTransformationMatrix * vec4(v.xyz, 1.0)).xyz; // window coordinates
return v;
}

void main()
{
//gl_Position = ModelToWindowCoordinates(vec4(position, 1.0f), //Code which should draw billboards (I comment it because it is not working
// og_modelViewPerspectiveMatrix, og_viewportTransformationMatrix);

gl_Position = og_modelViewPerspectiveMatrix * vec4(position, 1.0f);
}

Geometry Shader


layout(lines) in;
layout(line_strip, max_vertices = 2) out;

uniform mat4 og_viewportOrthographicMatrix;

void main()
{
int i = 0;

for (i = 0; i < gl_in.length(); i++)
{

//gl_Position = og_viewportOrthographicMatrix * gl_in[i].gl_Position; //Code which should draw billboards (I comment it because it is not working
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
}

Fragment Shader


out vec4 fragmentColor;

void main()
{
fragmentColor = vec4(1.0f, 0.5f, 0.3f, 1.0f);
}


When I am drawing without billboarding code, geometry is drawn as regular primitives. This is what I actually get as output:

1493

My goal is to draw the same but make the "head" of arrow be always oriented to screen. When I change code to billboards pieces - simply get clean screen as output.

Please, help me to find solution.