I have a question related to new computational shaders. I am currently working on a particle system. I store all my particles in a storage-shader-buffer for access to them in a computational shader. Then I send a one-dimensional workgroup.
#define WORK_GROUP_SIZE 128 _shaderManager->useProgram("computeProg"); glDispatchCompute((_numParticles/WORK_GROUP_SIZE), 1, 1); glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
My computational shader:
#version 430 struct particle{ vec4 currentPos; vec4 oldPos; }; layout(std430, binding=0) buffer particles{ struct particle p[]; }; layout (local_size_x = 128, local_size_y = 1, local_size_z = 1) in; void main(){ uint gid = gl_GlobalInvocationID.x; p[gid].currentPos.x += 100; }
But one way or another, not all particles are affected. I do it the same way as it was done in this example, but it does not work. http://education.siggraph.org/media/conference/S2012_Materials/ComputeShader_6pp.pdf
Edit:
After calling glMemoryBarrier (GL_SHADER_STORAGE_BARRIER_BIT), I continue:
_shaderManager->useProgram("shaderProg"); glBindBuffer(GL_ARRAY_BUFFER, shaderStorageBufferID); glVertexPointer(4,GL_FLOAT,sizeof(glm::vec4), (void*)0); glEnableClientState(GL_VERTEX_ARRAY); glDrawArrays(GL_POINTS, 0, _numParticles); glDisableClientState(GL_VERTEX_ARRAY);
So, which bit would be appropriate to use in this case?
Stan
source share