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=0) in ivec4 inds;
|
||||||
|
layout(location=1) in vec4 col;
|
||||||
|
|
||||||
out ivec4 vInds;
|
out ivec4 vInds;
|
||||||
|
out vec4 vCol;
|
||||||
|
|
||||||
out gl_PerVertex {
|
out gl_PerVertex {
|
||||||
vec4 gl_Position;
|
vec4 gl_Position;
|
||||||
@@ -20,6 +22,7 @@ out gl_PerVertex {
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vInds = inds;
|
vInds = inds;
|
||||||
|
vCol = col;
|
||||||
|
|
||||||
vec4 pos = view * verts[vInds.x];
|
vec4 pos = view * verts[vInds.x];
|
||||||
gl_Position = proj * vec4(pos.xyz, 1);
|
gl_Position = proj * vec4(pos.xyz, 1);
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ layout(std140, binding=1) uniform Matrices {
|
|||||||
};
|
};
|
||||||
|
|
||||||
in ivec4 vInds[];
|
in ivec4 vInds[];
|
||||||
|
in vec4 vCol[];
|
||||||
|
|
||||||
out vec4 pos;
|
out vec4 pos;
|
||||||
|
out vec4 col;
|
||||||
|
|
||||||
out gl_PerVertex {
|
out gl_PerVertex {
|
||||||
vec4 gl_Position;
|
vec4 gl_Position;
|
||||||
@@ -26,6 +28,7 @@ float unmix(float u, float v) {
|
|||||||
|
|
||||||
void emit(vec4 v) {
|
void emit(vec4 v) {
|
||||||
pos = v;
|
pos = v;
|
||||||
|
col = vCol[0];
|
||||||
gl_Position = proj * vec4(v.xyz, 1);
|
gl_Position = proj * vec4(v.xyz, 1);
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
#version 430
|
#version 430
|
||||||
|
|
||||||
layout(location=2) uniform vec3 c;
|
//layout(location=2) uniform vec3 c;
|
||||||
|
|
||||||
in vec4 pos;
|
in vec4 pos;
|
||||||
|
in vec4 col;
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float d = smoothstep(-2, 2, pos.z);
|
color = col;
|
||||||
color = vec4(c * d, 1);
|
// float d = smoothstep(-2, 2, pos.z);
|
||||||
|
// color = vec4(c * d, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ struct DeferredMesh {
|
|||||||
cgl::vertexarray vao;
|
cgl::vertexarray vao;
|
||||||
cgl::buffer<Primitive<N>> ibo;
|
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(), vao() {
|
||||||
|
|
||||||
ibo.put(mesh.prims);
|
ibo.put(mesh.prims);
|
||||||
@@ -61,6 +61,10 @@ struct DeferredMesh {
|
|||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribIPointer(0, N, GL_INT, 0, nullptr);
|
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));
|
auto wire_data = merge(poly_parts<2>(group));
|
||||||
DirectMesh<2> wires(GL_LINES, wire_data);
|
DirectMesh<2> wires(GL_LINES, wire_data);
|
||||||
|
|
||||||
auto slice_data = merge(poly_parts<4>(group));
|
const auto slice_parts = poly_parts<4>(group);
|
||||||
DeferredMesh<4> slices(slice_data);
|
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
|
//endregion
|
||||||
|
|
||||||
@@ -176,17 +189,12 @@ void run(GLFWwindow *window) {
|
|||||||
Matrices mats = build(window, st);
|
Matrices mats = build(window, st);
|
||||||
ubo.put(mats);
|
ubo.put(mats);
|
||||||
|
|
||||||
const auto wires_dark = glm::vec3(.3, .3, .3);
|
|
||||||
const auto wires_light = wires_dark;
|
|
||||||
|
|
||||||
glLineWidth(1.5);
|
glLineWidth(1.5);
|
||||||
|
|
||||||
glProgramUniform3f(solid, 2, 0.9, 0.9, 0.9);
|
// proj_pipe.bound([&]() {
|
||||||
proj_pipe.bound([&]() {
|
// wires.draw();
|
||||||
wires.draw();
|
// });
|
||||||
});
|
|
||||||
|
|
||||||
glProgramUniform3f(solid, 2, 0.9, 0.1, 0.1);
|
|
||||||
slice_pipe.bound([&]() {
|
slice_pipe.bound([&]() {
|
||||||
slices.draw();
|
slices.draw();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user