Jump to content
  • Advertisement
Sign in to follow this  

Access vertex array in compute shader

This topic is 1498 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

Hello Everyone,


I want to process a vertex buffer for now I just want to keep it simple so I am just adding .20 to the y value of each vertex. That way I could see the mesh move up. But I ran into a little issue. It seems that the array containing the vertexes isn't aligned properly. Instead of all vertexes moving on the y axis the some seems to move on the x axis, some on the y axis and some on the z axis. I am confused about this.


My vertexes are just basic points with floating point x,y,z components.


Buffer initiation code:

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, vertexCount * 3 * sizeof(float), vertexData, GL_STATIC_DRAW); 

Render code:

glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(vertexAttributeLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL);
glDrawArrays(GL_TRIANGLES, 0, vertexCount);
glBindBuffer(GL_ARRAY_BUFFER, 0);

Compute shader invocation:


glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, vbo);

glDispatchCompute(vertexCount, 1, 1);

Compute shader:

#version 430 compatibility

#extension GL_ARB_compute_shader : enable
#extension GL_ARB_shader_storage_buffer_object : enable

layout( std140, binding=3 ) buffer Vertexes {
 vec3 Positions[ ]; 


layout( local_size_x = 1, local_size_y = 1, local_size_z = 1 ) in;

void main() {

uint globalId = gl_GlobalInvocationID.x;

vec3 p = Positions[ globalId ];

p.y += 0.20;

Positions[ globalId ] = p;


Greetz Jaap

Share this post

Link to post
Share on other sites

Strangely enough I do get the expected result when I add a 4th component to my vertexes. I am not sure why. Any one got any ideas on why the data seems to be misaligned without the 4th component?

Share this post

Link to post
Share on other sites

std140 layout pads a vec3 to 4.

Thanks, I was thrown of for a bit because in the vertex shader I could use vec3 and it worked just fine. I Guess I should have read the specs better.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!