Hi,
I’m trying to write a basic compute shader, the ultimate goal will be to deform the vertices using a noise function but to start with just setting the vertex points to 1.0f.
The shader doesn’t seem to be modifying any of the values, as they are being read the same as they went in.
Here is the basic glsl code:
#version 460 core
layout(local_size_x = 1) in;
layout(std430, binding = 0) buffer Vertex {
vec3 outVertices[];
};
void main() {
outVertices[gl_GlobalInvocationID.x * 3] = vec3(1.0f);
}
and this C++ code:
ComputeShader computeShader("addSimplexNoise.comp.glsl");
glUseProgram(computeShader.getShaderProgram());
GLuint vertexSSBO;
glGenBuffers(1, &vertexSSBO);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, vertexSSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER, vertices.size() * sizeof(glm::vec3), vertices.data(), GL_DYNAMIC_DRAW);
glDispatchCompute(vertices.size(), 1, 1);
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, 0);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vertexSSBO);
glm::vec3 *ptr;
int numVertices = vertices.size();
ptr = (glm::vec3 *) glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);
vertices.clear();
for (int i = 0; i < numVertices; i++) {
vertices.push_back(ptr[i]);
}
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);