Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#Actualharshman_chris

Posted 05 April 2013 - 08:07 AM

So I am looking for a way to pass a Matrix4 from my program into my shader as an attribute.

 

As for the reason why, I am working on a particle system and every particle requires its own Model matrix so I can do things like per particle rotation.

 


I know you cannot just do this, because you can only used 1,2,3,4 where the 16 is. I do know I could split this into 4 vectors, but then I have to reassemble on the other side so I would rather not do that.

glVertexAttribPointer(3, 16, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (const GLvoid*)36);

 

 

Is there a way to pass this into the shader some way that doesn't involve me adding code to disassemble and reassemble my matrix?

 

Edit:

I should add I have a struct that holds the information for each particle so I am using interleaving to pass data.

 

I also found a code sample that works for non interleaving:

 

for (unsigned int i = 0; i < 4 ; i++) 
{
glEnableVertexAttribArray(WVP_LOCATION + i);
glVertexAttribPointer(WVP_LOCATION + i, 4, GL_FLOAT, GL_FALSE, sizeof(Matrix4f), (const GLvoid*)(sizeof(GLfloat) * i * 4));
glVertexAttribDivisor(WVP_LOCATION + i, 1);
}

 

 

 

As a side note, I am applying my ModelView to a GL_POINT which then gets passed into a Geometry shader, if I apply a rotation to that GL_POINT will it be reflected on the textured triangle strip that comes out the other side.

 

 

Edit:

 

Just my luck, I spend hours searching for an answer, decide to post and find it within 5 minutes after posting...

 

I just need to add the offset of 36 to the code above.


#3harshman_chris

Posted 05 April 2013 - 08:07 AM

So I am looking for a way to pass a Matrix4 from my program into my shader as an attribute.

 

As for the reason why, I am working on a particle system and every particle requires its own Model matrix so I can do things like per particle rotation.

 


I know you cannot just do this, because you can only used 1,2,3,4 where the 16 is. I do know I could split this into 4 vectors, but then I have to reassemble on the other side so I would rather not do that.

glVertexAttribPointer(3, 16, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (const GLvoid*)36);

 

 

Is there a way to pass this into the shader some way that doesn't involve me adding code to disassemble and reassemble my matrix?

 

Edit:

I should add I have a struct that holds the information for each particle so I am using interleaving to pass data.

 

I also found a code sample that works for non interleaving:

 

for (unsigned int i = 0; i < 4 ; i++) 
{
glEnableVertexAttribArray(WVP_LOCATION + i);
glVertexAttribPointer(WVP_LOCATION + i, 4, GL_FLOAT, GL_FALSE, sizeof(Matrix4f), (const GLvoid*)(sizeof(GLfloat) * i * 4));
glVertexAttribDivisor(WVP_LOCATION + i, 1);
}

 

 

 

As a side note, I am applying my ModelView to a GL_POINT which then gets passed into a Geometry shader, if I apply a rotation to that GL_POINT will it be reflected on the textured triangle strip that comes out the other side.

 

 

Edit:

 

Just my luck, I spend hours searching for an answer, decide to post and find it within 5 minutes after posting...

 

 


#2harshman_chris

Posted 05 April 2013 - 08:05 AM

So I am looking for a way to pass a Matrix4 from my program into my shader as an attribute.

 

As for the reason why, I am working on a particle system and every particle requires its own Model matrix so I can do things like per particle rotation.

 


I know you cannot just do this, because you can only used 1,2,3,4 where the 16 is. I do know I could split this into 4 vectors, but then I have to reassemble on the other side so I would rather not do that.

glVertexAttribPointer(3, 16, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (const GLvoid*)36);

 

 

Is there a way to pass this into the shader some way that doesn't involve me adding code to disassemble and reassemble my matrix?

 

Edit:

I should add I have a struct that holds the information for each particle so I am using interleaving to pass data.

 

I also found a code sample that works for non interleaving:

 

for (unsigned int i = 0; i < 4 ; i++) 
{
glEnableVertexAttribArray(WVP_LOCATION + i);
glVertexAttribPointer(WVP_LOCATION + i, 4, GL_FLOAT, GL_FALSE, sizeof(Matrix4f), (const GLvoid*)(sizeof(GLfloat) * i * 4));
glVertexAttribDivisor(WVP_LOCATION + i, 1);
}

 

 

 

As a side note, I am applying my ModelView to a GL_POINT which then gets passed into a Geometry shader, if I apply a rotation to that GL_POINT will it be reflected on the textured triangle strip that comes out the other side.


#1harshman_chris

Posted 05 April 2013 - 07:57 AM

So I am looking for a way to pass a Matrix4 from my program into my shader as an attribute.

 

As for the reason why, I am working on a particle system and every particle requires its own Model matrix so I can do things like per particle rotation.

 


I know you cannot just do this, because you can only used 1,2,3,4 where the 16 is. I do know I could split this into 4 vectors, but then I have to reassemble on the other side so I would rather not do that.

glVertexAttribPointer(3, 16, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (const GLvoid*)36);

 

 

Is there a way to pass this into the shader some way that doesn't involve me adding code to disassemble and reassemble my matrix?

 

 

As a side note, I am applying my ModelView to a GL_POINT which then gets passed into a Geometry shader, if I apply a rotation to that GL_POINT will it be reflected on the textured triangle strip that comes out the other side.


PARTNERS