Commit a7445df0 by Philipp Adolf

Add buffer for sharpness to edge shader

parent f804bd56
......@@ -24,6 +24,10 @@ layout(std430, binding=3) readonly buffer OutputOffset {
unsigned int output_offset;
};
layout(std430, binding=4) readonly buffer EdgeSharpness {
unsigned int sharpness[];
};
void main(){
edges[output_offset + gl_GlobalInvocationID.x].uv = vec2(0.0, 0.0);
......@@ -32,6 +36,8 @@ void main(){
Vertex c = vertices[indices[gl_GlobalInvocationID.x][2]];
Vertex d = vertices[indices[gl_GlobalInvocationID.x][3]];
unsigned int s = sharpness[gl_GlobalInvocationID.x];
vec3 pos;
edges[output_offset + gl_GlobalInvocationID.x].pos = 3.0f/8.0f * a.pos + 3.0f/8.0f * b.pos + 1.0f/8.0f * c.pos + 1.0f/8.0f * d.pos;
......
......@@ -971,6 +971,19 @@ Subdivision::Result Subdivision::runShader(Input input, Tables &tables) {
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, edge_indices_handle);
f->glBufferData(GL_SHADER_STORAGE_BUFFER, tables.edge_indices.size() * sizeof(GLuint), tables.edge_indices.data(), GL_DYNAMIC_DRAW);
//prepare sharpness buffer
QVector<unsigned int> sharpness;
for (int i = 0; i < tables.edge_indices.size(); i+= 4){
sharpness.push_back(0);
}
qCWarning(log_subdiv_trace)<<"Sharpness: "<< sharpness;
GLuint edge_sharpness_handle;
f->glGenBuffers(1,&edge_sharpness_handle);
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, edge_sharpness_handle);
f->glBufferData(GL_SHADER_STORAGE_BUFFER, sharpness.size() * sizeof(GLuint), sharpness.data(), GL_DYNAMIC_DRAW);
// Create an output buffer
// the new vertex buffer contains the old vertices + the new edge vertices + the modified non-edge vertices
unsigned int output_size = input.vertex_buffer.size() + tables.edge_indices.size() / 4 + (tables.vertex_offsets.size() - 1);
......@@ -999,7 +1012,7 @@ Subdivision::Result Subdivision::runShader(Input input, Tables &tables) {
GLuint *offset_buffer = (GLuint *) f->glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
*offset_buffer = input.vertex_buffer.size();
f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
runEdgeShader(tables.edge_indices.size() / 4, input.vb_handle, edge_indices_handle, output_handle, offset_handle);
runEdgeShader(tables.edge_indices.size() / 4, input.vb_handle, edge_indices_handle, edge_sharpness_handle, output_handle, offset_handle);
int edgeTime = timer.elapsed();
// move old vertices
......@@ -1077,13 +1090,19 @@ void Subdivision::runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_i
vertexShader->release();
}
void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset_handle) {
void Subdivision::runEdgeShader(GLuint size,
GLuint vb_handle,
GLuint edge_indices_handle,
GLuint edge_sharpness_handle,
GLuint output_handle,
GLuint offset_handle) {
edgeShader->bind();
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, vb_handle);
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, edge_indices_handle);
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, output_handle);
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, offset_handle);
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, edge_sharpness_handle);
// Run the shader
f->glDispatchCompute(size, 1, 1);
......@@ -1096,6 +1115,7 @@ void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indic
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, 0);
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, 0);
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, 0);
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, 0);
edgeShader->release();
}
......
......@@ -83,7 +83,7 @@ private:
Result runShader(Input input, Tables &tables);
void runCopyShader(GLuint size, GLuint vb_in, GLuint vb_out);
void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle, GLuint offset_handle);
void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset_handle);
void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint edge_sharpness_handle, GLuint output_handle, GLuint offset_handle);
void updateIrregularForDraw(const QVector<Triangle> &triangles, QMap<Triangle, Triangle::Neighbors> &neighbors, Result &result);
bool containsVertex(QVector<Vertex> &vertices, Vertex vertex);
QVector<Vertex> getAllVertices(const QVector<Triangle> &triangles);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment