mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
drawable to "slice" and add builder factory method
This commit is contained in:
@@ -64,14 +64,6 @@ void main() {
|
|||||||
normal = cross(sect[1].xyz - sect[0].xyz, sect[2].xyz - sect[0].xyz);
|
normal = cross(sect[1].xyz - sect[0].xyz, sect[2].xyz - sect[0].xyz);
|
||||||
normal = normalize(normal);
|
normal = normalize(normal);
|
||||||
|
|
||||||
float r = dot(normal, sect[0].xyz);
|
|
||||||
|
|
||||||
if (abs(r) < 0.001)
|
|
||||||
r = dot(normal, sect[0].xyz + vec3(0, 0, 1));
|
|
||||||
|
|
||||||
if (r < 0)
|
|
||||||
normal *= -1;
|
|
||||||
|
|
||||||
for (int s = 0; s < S; ++s) {
|
for (int s = 0; s < S; ++s) {
|
||||||
emit(sect[s]);
|
emit(sect[s]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
layout(location=2) uniform vec4 col;
|
layout(location=2) uniform vec4 col;
|
||||||
|
|
||||||
|
layout(location=0) in vec3 pos;
|
||||||
layout(location=2) in vec3 normal;
|
layout(location=2) in vec3 normal;
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float bright = dot(normal, normalize(vec3(-0.6, 1, 2)));
|
float depth = .1 + .9 * smoothstep(-2, 2, pos.z);
|
||||||
bright = .6 + .3 * bright;
|
float bright = abs(dot(normal, normalize(vec3(-0.6, 1, 2))));
|
||||||
|
bright = .6 + .3 * bright * depth;
|
||||||
|
|
||||||
color = col;
|
color = col;
|
||||||
color.xyz *= bright;
|
color.xyz *= bright;
|
||||||
|
|||||||
140
vis/src/main.cpp
140
vis/src/main.cpp
@@ -33,33 +33,6 @@ struct Matrices {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<unsigned N>
|
|
||||||
struct Drawable {
|
|
||||||
GLenum mode{};
|
|
||||||
cgl::VertexArray vao{};
|
|
||||||
cgl::Buffer<Primitive<N>> ibo{};
|
|
||||||
|
|
||||||
Drawable(GLenum mode) : mode(mode), vao(), ibo() {}
|
|
||||||
|
|
||||||
Drawable(Drawable &) = delete;
|
|
||||||
|
|
||||||
Drawable(Drawable &&) = delete;
|
|
||||||
|
|
||||||
void draw_deferred() {
|
|
||||||
vao.bound([&]() {
|
|
||||||
glDrawArrays(GL_POINTS, 0, ibo.count() * N);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_direct() {
|
|
||||||
vao.bound([&]() {
|
|
||||||
ibo.bound(GL_ELEMENT_ARRAY_BUFFER, [&]() {
|
|
||||||
glDrawElements(mode, ibo.count() * N, GL_UNSIGNED_INT, nullptr);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Matrices build(GLFWwindow *window, float st) {
|
Matrices build(GLFWwindow *window, float st) {
|
||||||
int width, height;
|
int width, height;
|
||||||
glfwGetFramebufferSize(window, &width, &height);
|
glfwGetFramebufferSize(window, &width, &height);
|
||||||
@@ -81,10 +54,11 @@ Matrices build(GLFWwindow *window, float st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned N, class T>
|
template<unsigned N, class T>
|
||||||
auto hull(const tc::Group &group, T all_sg_gens) {
|
auto hull(const tc::Group &group, T begin, T end) {
|
||||||
std::vector<std::vector<Primitive<N>>> parts;
|
std::vector<std::vector<Primitive<N>>> parts;
|
||||||
auto g_gens = gens(group);
|
auto g_gens = gens(group);
|
||||||
for (const auto &sg_gens : all_sg_gens) {
|
while (begin != end) {
|
||||||
|
const auto &sg_gens = *(++begin);
|
||||||
const auto &base = triangulate<N>(group, sg_gens);
|
const auto &base = triangulate<N>(group, sg_gens);
|
||||||
const auto &tiles = each_tile(base, group, g_gens, sg_gens);
|
const auto &tiles = each_tile(base, group, g_gens, sg_gens);
|
||||||
for (const auto &tile : tiles) {
|
for (const auto &tile : tiles) {
|
||||||
@@ -94,6 +68,20 @@ auto hull(const tc::Group &group, T all_sg_gens) {
|
|||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<vec4> points(const tc::Group &group, const std::vector<float> &coords) {
|
||||||
|
auto cosets = group.solve();
|
||||||
|
auto mirrors = mirror<5>(group);
|
||||||
|
|
||||||
|
auto corners = plane_intersections(mirrors);
|
||||||
|
|
||||||
|
auto start = barycentric(corners, coords);
|
||||||
|
|
||||||
|
const auto &higher = cosets.path.walk<vec5, vec5>(start, mirrors, reflect<vec5>);
|
||||||
|
std::vector<vec4> lower(higher.size());
|
||||||
|
std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>);
|
||||||
|
return lower;
|
||||||
|
}
|
||||||
|
|
||||||
class Shaders {
|
class Shaders {
|
||||||
public:
|
public:
|
||||||
cgl::pgm::vert defer = cgl::pgm::vert::file(
|
cgl::pgm::vert defer = cgl::pgm::vert::file(
|
||||||
@@ -116,27 +104,41 @@ public:
|
|||||||
"shaders/diffuse.fs.glsl");
|
"shaders/diffuse.fs.glsl");
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<vec4> points(const tc::Group &group, const std::vector<float> &coords) {
|
template<unsigned N>
|
||||||
auto cosets = group.solve();
|
struct Slice {
|
||||||
auto mirrors = mirror<5>(group);
|
GLenum mode;
|
||||||
|
vec4 color;
|
||||||
|
cgl::VertexArray vao;
|
||||||
|
cgl::Buffer<vec4> vbo;
|
||||||
|
cgl::Buffer<Primitive<N>> ibo;
|
||||||
|
|
||||||
auto corners = plane_intersections(mirrors);
|
Slice(GLenum mode, vec4 color) : mode(mode), color(color), vao(), ibo(), vbo() {}
|
||||||
|
|
||||||
auto start = barycentric(corners, coords);
|
Slice(Slice &) = delete;
|
||||||
|
|
||||||
auto higher = cosets.path.walk<vec5, vec5>(start, mirrors, reflect<vec5>);
|
Slice(Slice &&) noexcept = default;
|
||||||
std::vector<vec4> res(higher.size());
|
|
||||||
std::transform(higher.begin(), higher.end(), res.begin(), stereo<4>);
|
|
||||||
|
|
||||||
return res;
|
void draw() {
|
||||||
}
|
vao.bound([&]() {
|
||||||
|
glDrawArrays(GL_POINTS, 0, ibo.count() * N);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
static Slice<N> build(const tc::Group &g, const std::vector<float> &coords, vec4 color, T begin, T end) {
|
||||||
|
Slice<N> res(GL_POINTS, color);
|
||||||
|
|
||||||
|
res.vbo.put(points(g, coords));
|
||||||
|
res.ibo.put(merge<N>(hull<N>(g, begin, end)));
|
||||||
|
res.vao.ipointer(0, res.ibo, 4, GL_UNSIGNED_INT);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void run(GLFWwindow *window) {
|
void run(GLFWwindow *window) {
|
||||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
|
||||||
glEnable(GL_POINT_SMOOTH);
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
// glEnable(GL_CULL_FACE);
|
|
||||||
glCullFace(GL_BACK);
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
@@ -155,37 +157,19 @@ void run(GLFWwindow *window) {
|
|||||||
|
|
||||||
auto group = tc::schlafli({5, 3, 3, 2});
|
auto group = tc::schlafli({5, 3, 3, 2});
|
||||||
|
|
||||||
auto slice_faces = hull<4>(group, (std::vector<std::vector<int>>) {
|
const auto combos = Combos<int>({0, 1, 2, 3, 4}, 3);
|
||||||
{0, 1, 2},
|
|
||||||
});
|
|
||||||
|
|
||||||
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
|
auto white = Slice<4>::build(
|
||||||
std::default_random_engine rand(seed);
|
group,
|
||||||
std::shuffle(slice_faces.begin(), slice_faces.end(), rand);
|
{0.3f, 0.1f, 0.1f, 0.1f, 0.05f},
|
||||||
slice_faces.erase(slice_faces.begin(), slice_faces.begin() + slice_faces.size() / 2);
|
{0.9f, 0.9f, 0.9f, 1.0f},
|
||||||
|
combos.begin(), combos.end());
|
||||||
|
|
||||||
auto slice_face_data = merge<4>(slice_faces);
|
auto black = Slice<4>::build(
|
||||||
auto slice_edges = hull<4>(group, (std::vector<std::vector<int>>) {
|
group,
|
||||||
{0, 1, 3},
|
{1.0f, 0.1f, 0.1f, 0.1f, 0.5f},
|
||||||
{0, 1, 4},
|
{0.3f, 0.3f, 0.3f, 1.0f},
|
||||||
{0, 2, 3},
|
combos.begin()++, combos.end());
|
||||||
{0, 2, 4},
|
|
||||||
{1, 2, 3},
|
|
||||||
{1, 2, 4},
|
|
||||||
{1, 3, 4},
|
|
||||||
});
|
|
||||||
auto slice_edge_data = merge<4>(slice_edges);
|
|
||||||
|
|
||||||
Drawable<4> edges(GL_POINTS);
|
|
||||||
edges.ibo.put(slice_edge_data);
|
|
||||||
edges.vao.ipointer(0, edges.ibo, 4, GL_UNSIGNED_INT);
|
|
||||||
|
|
||||||
Drawable<4> faces(GL_POINTS);
|
|
||||||
faces.ibo.put(slice_face_data);
|
|
||||||
faces.vao.ipointer(0, faces.ibo, 4, GL_UNSIGNED_INT);
|
|
||||||
|
|
||||||
auto pbo_thick = cgl::Buffer<vec4>(points(group, {1.0f, 0.2f, 0.1f, 0.05f, 0.025f}));
|
|
||||||
auto pbo_thin = cgl::Buffer<vec4>(points(group, {1.0f, 0.2f, 0.1f, 0.05f, 0.025f}));
|
|
||||||
|
|
||||||
auto ubo = cgl::Buffer<Matrices>();
|
auto ubo = cgl::Buffer<Matrices>();
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
|
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
|
||||||
@@ -204,13 +188,13 @@ void run(GLFWwindow *window) {
|
|||||||
glLineWidth(1.5);
|
glLineWidth(1.5);
|
||||||
|
|
||||||
slice_pipe.bound([&]() {
|
slice_pipe.bound([&]() {
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, pbo_thick);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, white.vbo);
|
||||||
glProgramUniform4f(sh.solid, 2, 1.0, 1.0, 1.0, 1.0);
|
glProgramUniform4fv(sh.solid, 2, 1, &white.color.front());
|
||||||
edges.draw_deferred();
|
white.draw();
|
||||||
|
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, pbo_thin);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, black.vbo);
|
||||||
glProgramUniform4f(sh.solid, 2, 0.7, 0.7, 0.7, 1.0);
|
glProgramUniform4fv(sh.solid, 2, 1, &black.color.front());
|
||||||
faces.draw_deferred();
|
black.draw();
|
||||||
});
|
});
|
||||||
|
|
||||||
glfwSwapInterval(2);
|
glfwSwapInterval(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user