Jump to content
  • Advertisement
Sign in to follow this  

Billboarding particles + VBO issue

This topic is 1865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,


I'm working on a simple particle system, but I'm having an issue.


I am not that unfamiliar with the concept of using an VBO and I successfully use it for rendering my meshes and such. When I started with my particle system, I plugged in all the relevant data and the particles render how I expect them to be and on the right positions.


However, because I use one VBO for all the particles, the entire VBO will be rendered as a billboard instead of them being separate particles, this is normal behaviour if you think about it, but not the kind of behaviour I want.


I simply want to put all my positions/uvs and whatnot in a single VBO and render them like they are individual particles, but I am not sure how to do this in a proper way.


I'm using a shader to billboard the object. This is what I have:


void Liqua::ParticleSystem::Render(glm::mat4 a_Projection, glm::mat4 a_View)
	glBindTexture(GL_TEXTURE_2D, m_Tex);

	glm::mat4 ModelView = a_View * m_ModelMatrix;

	m_ParticleShader->SetUniformMatrix("ProjectionMatrix", glm::value_ptr(a_Projection));
	m_ParticleShader->SetUniformMatrix("ModelViewMatrix", glm::value_ptr(ModelView));

	glEnableVertexAttribArray(0); // 0 for vertex positions
	glBindBuffer(GL_ARRAY_BUFFER, m_BufferIndex);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);

	glBindBuffer(GL_ARRAY_BUFFER, m_UVBufferIndex);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);

	glDrawArrays(GL_TRIANGLES, 0, m_VertexBuffer.size());

	glBindTexture(GL_TEXTURE_2D, 0);


And the vertex shader that performs the billboarding:


layout (location = 0) in vec3 Position;
layout (location = 1) in vec2 TexCoord;
layout (location = 2) in vec3 Normal; 

uniform mat4 ProjectionMatrix;
uniform mat4 ModelViewMatrix;

out vec2 TexCoord0;
out vec3 Normal0;
out vec3 WPos0;

void main(void)
	gl_Position = ProjectionMatrix * (vec4(Position.x, Position.y, Position.z, 1) + vec4(ModelViewMatrix[3].xyz, 0));
	TexCoord0 = TexCoord;
	Normal0 = (ModelViewMatrix * vec4(Normal, 0.0)).xyz;
	WPos0 = (ModelViewMatrix * vec4(Position, 1.0));


I do not want to create a VBO for every particle for obvious reasons. Perhaps this is not the best way to do billboarding and instead make them face the camera in C++ instead of in the shader. Or perhaps I'm just missing the obvious here.


I'm free for any suggestion, as long as it's not making use of the fixed function pipeline. 


Thanks in advance!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!