diff --git a/vis/shaders/slice/deferred.vs.glsl b/vis/shaders/slice/deferred.vs.glsl index a411c07..ed65fd7 100644 --- a/vis/shaders/slice/deferred.vs.glsl +++ b/vis/shaders/slice/deferred.vs.glsl @@ -10,8 +10,10 @@ layout(std140, binding=1) uniform Matrices { }; layout(location=0) in ivec4 inds; +layout(location=1) in vec4 col; out ivec4 vInds; +out vec4 vCol; out gl_PerVertex { vec4 gl_Position; @@ -20,6 +22,7 @@ out gl_PerVertex { void main() { vInds = inds; + vCol = col; vec4 pos = view * verts[vInds.x]; gl_Position = proj * vec4(pos.xyz, 1); diff --git a/vis/shaders/slice/slice.gm.glsl b/vis/shaders/slice/slice.gm.glsl index 3fafcb6..a7c81d9 100644 --- a/vis/shaders/slice/slice.gm.glsl +++ b/vis/shaders/slice/slice.gm.glsl @@ -13,8 +13,10 @@ layout(std140, binding=1) uniform Matrices { }; in ivec4 vInds[]; +in vec4 vCol[]; out vec4 pos; +out vec4 col; out gl_PerVertex { vec4 gl_Position; @@ -26,6 +28,7 @@ float unmix(float u, float v) { void emit(vec4 v) { pos = v; + col = vCol[0]; gl_Position = proj * vec4(v.xyz, 1); EmitVertex(); } diff --git a/vis/shaders/solid.fs.glsl b/vis/shaders/solid.fs.glsl index 11f3ec0..e977491 100644 --- a/vis/shaders/solid.fs.glsl +++ b/vis/shaders/solid.fs.glsl @@ -1,12 +1,14 @@ #version 430 -layout(location=2) uniform vec3 c; +//layout(location=2) uniform vec3 c; in vec4 pos; +in vec4 col; out vec4 color; void main() { - float d = smoothstep(-2, 2, pos.z); - color = vec4(c * d, 1); + color = col; +// float d = smoothstep(-2, 2, pos.z); +// color = vec4(c * d, 1); } diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 74ccee9..b5f3da0 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -51,7 +51,7 @@ struct DeferredMesh { cgl::vertexarray vao; cgl::buffer> ibo; - explicit DeferredMesh(const Mesh &mesh) + explicit DeferredMesh(const Mesh &mesh, const cgl::buffer &color) : ibo(), vao() { ibo.put(mesh.prims); @@ -61,6 +61,10 @@ struct DeferredMesh { glEnableVertexAttribArray(0); glVertexAttribIPointer(0, N, GL_INT, 0, nullptr); }); + color.bound(GL_ARRAY_BUFFER, [&]() { + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, nullptr); + }); }); } @@ -153,8 +157,17 @@ void run(GLFWwindow *window) { auto wire_data = merge(poly_parts<2>(group)); DirectMesh<2> wires(GL_LINES, wire_data); - auto slice_data = merge(poly_parts<4>(group)); - DeferredMesh<4> slices(slice_data); + const auto slice_parts = poly_parts<4>(group); + auto slice_data = merge(slice_parts); + auto slice_colors = std::vector(slice_data.size()); + for (int i = 0, k = 0; i < slice_parts.size(); ++i) { + glm::vec3 color((float) i / (float) (slice_parts.size() - 1)); + for (int j = 0; j < slice_parts[i].size(); ++j, ++k) { + slice_colors[k] = glm::vec4(color, 1); + } + } + cgl::buffer slice_colors_buf(slice_colors); + DeferredMesh<4> slices(slice_data, slice_colors_buf); //endregion @@ -176,17 +189,12 @@ void run(GLFWwindow *window) { Matrices mats = build(window, st); ubo.put(mats); - const auto wires_dark = glm::vec3(.3, .3, .3); - const auto wires_light = wires_dark; - glLineWidth(1.5); - glProgramUniform3f(solid, 2, 0.9, 0.9, 0.9); - proj_pipe.bound([&]() { - wires.draw(); - }); +// proj_pipe.bound([&]() { +// wires.draw(); +// }); - glProgramUniform3f(solid, 2, 0.9, 0.1, 0.1); slice_pipe.bound([&]() { slices.draw(); });