Access vertex array in compute shader

Started by
2 comments, last by JvdWulp 9 years, 6 months ago

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);
glEnableVertexAttribArray(vertexAttributeLocation);
glDrawArrays(GL_TRIANGLES, 0, vertexCount);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableVertexAttribArray(vertexAttributeLocation);

Compute shader invocation:



glUseProgram(compute_shader_program);

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

Advertisement

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?

std140 layout pads a vec3 to 4.

New C/C++ Build Tool 'Stir' (doesn't just generate Makefiles, it does the build): https://github.com/space222/stir

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.

This topic is closed to new replies.

Advertisement