mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
per-primitive coloring
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ struct DeferredMesh {
|
||||
cgl::vertexarray vao;
|
||||
cgl::buffer<Primitive<N>> ibo;
|
||||
|
||||
explicit DeferredMesh(const Mesh<N> &mesh)
|
||||
explicit DeferredMesh(const Mesh<N> &mesh, const cgl::buffer<glm::vec4> &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<glm::vec4>(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<glm::vec4> 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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user