Jump to content

  • Log In with Google      Sign In   
  • Create Account


Billboarding particles + VBO issue


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Rld_   Members   -  Reputation: 1383

Like
0Likes
Like

Posted 11 April 2013 - 07:20 AM

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)
{
	m_ParticleShader->Bind();
	glActiveTexture(GL_TEXTURE0);
	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);

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

	glDrawArrays(GL_TRIANGLES, 0, m_VertexBuffer.size());
	glDisableVertexAttribArray(0);
	glDisableVertexAttribArray(1);
	m_ParticleShader->Unbind();

	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!



Sponsor:

#2 Rld_   Members   -  Reputation: 1383

Like
0Likes
Like

Posted 11 April 2013 - 07:35 AM

As I posted this, I decided to try out my own suggestion and simply billboard in my C++ code. It's working fine now :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS