Commit 8c68e838 by Philipp Adolf

temp

parent d08d0b1b
...@@ -25,12 +25,16 @@ layout(std430, binding=3) buffer Output { ...@@ -25,12 +25,16 @@ layout(std430, binding=3) buffer Output {
int neighbors[][3]; int neighbors[][3];
}; };
bool areEqual(vec3 a, vec3 b) {
return all(lessThan(abs(a - b), vec3(0.01)));
}
int shared_edge(vec3 u, vec3 v, vec3 w, vec3 a, vec3 b, vec3 c) { int shared_edge(vec3 u, vec3 v, vec3 w, vec3 a, vec3 b, vec3 c) {
if (u == a && v == c) { if (areEqual(u, a) && areEqual(v, c)) {
return 0; return 0;
} else if (u == a && w == b) { } else if (areEqual(u, a) && areEqual(w, b)) {
return 2; return 2;
} else if (v == a && w == c) { } else if (areEqual(v, a) && areEqual(w, c)) {
return 1; return 1;
} }
return -1; return -1;
...@@ -50,7 +54,7 @@ void main() { ...@@ -50,7 +54,7 @@ void main() {
vec3 v = vb[ib[3 * (gl_GlobalInvocationID.x + offset_in) + 1]].pos; vec3 v = vb[ib[3 * (gl_GlobalInvocationID.x + offset_in) + 1]].pos;
vec3 w = vb[ib[3 * (gl_GlobalInvocationID.x + offset_in) + 2]].pos; vec3 w = vb[ib[3 * (gl_GlobalInvocationID.x + offset_in) + 2]].pos;
for (int i = 0; found < 3 && i < 128 && (3 * gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 2 < ib.length(); i++) { for (int i = 0; i < 128 && (3 * gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 2 < ib.length(); i++) {
vec3 a = vb[ib[3 * (gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 0]].pos; vec3 a = vb[ib[3 * (gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 0]].pos;
vec3 b = vb[ib[3 * (gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 1]].pos; vec3 b = vb[ib[3 * (gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 1]].pos;
vec3 c = vb[ib[3 * (gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 2]].pos; vec3 c = vb[ib[3 * (gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 2]].pos;
......
...@@ -89,15 +89,18 @@ void Subdivision::subdivide(Mesh *mesh, int level) { ...@@ -89,15 +89,18 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
Tables tables = precomputeTables(input); Tables tables = precomputeTables(input);
Result result = runShader(input, tables); Result result = runShader(input, tables);
QVector<Triangle> triangles;
ibToTriangles(&result.vertex_buffer, tables.index_buffer, triangles);
QVector<Triangle> all_triangles; QVector<Triangle> all_triangles;
ibToTriangles(&result.vertex_buffer, tables.index_buffer, all_triangles); ibToTriangles(&result.vertex_buffer, tables.extra_triangles, all_triangles);
all_triangles += triangles;
QMap<Triangle, Triangle::Neighbors> neighbors; QMap<Triangle, Triangle::Neighbors> neighbors;
buildNeighborsMap(result.vertex_buffer, all_triangles, neighbors); buildNeighborsMap(result.vertex_buffer, all_triangles, neighbors);
QVector<Triangle> regular; QVector<Triangle> regular;
QVector<Triangle> irregular; QVector<Triangle> irregular;
findRegular(all_triangles, neighbors, regular, irregular); findRegular(triangles, neighbors, regular, irregular);
qCDebug(log_subdiv) << "Indices" << tables.index_buffer.length(); qCDebug(log_subdiv) << "Indices" << tables.index_buffer.length();
qCDebug(log_subdiv) << "subdivide: regular" << regular.length(); qCDebug(log_subdiv) << "subdivide: regular" << regular.length();
...@@ -177,6 +180,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -177,6 +180,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
subTimer.restart(); subTimer.restart();
updateIndexBuffer(tables.index_buffer, modified_vertices); updateIndexBuffer(tables.index_buffer, modified_vertices);
updateIndexBuffer(tables.extra_triangles, modified_vertices);
qCDebug(log_timing) << "updateIndexBuffer:" << formatTimeMeasurement(subTimer.elapsed()); qCDebug(log_timing) << "updateIndexBuffer:" << formatTimeMeasurement(subTimer.elapsed());
qCDebug(log_subdiv) << "Precompute Tables Done"; qCDebug(log_subdiv) << "Precompute Tables Done";
...@@ -370,11 +374,12 @@ void Subdivision::buildNeighborsMap(QVector<Vertex> &vb, QVector<Triangle> &tria ...@@ -370,11 +374,12 @@ void Subdivision::buildNeighborsMap(QVector<Vertex> &vb, QVector<Triangle> &tria
QVector<Triangle> Subdivision::vertexNeighbors(Triangle &triangle, Triangle::Neighbor current_neighbor, QMap<Triangle, Triangle::Neighbors> neighbors) { QVector<Triangle> Subdivision::vertexNeighbors(Triangle &triangle, Triangle::Neighbor current_neighbor, QMap<Triangle, Triangle::Neighbors> neighbors) {
QVector<Triangle> ns; QVector<Triangle> ns;
do { do {
assert(current_neighbor.triangle != NULL); // qDebug() << current_neighbor.triangle;
// assert(current_neighbor.triangle != NULL);
ns.push_back(*current_neighbor.triangle); ns.push_back(*current_neighbor.triangle);
current_neighbor = neighbors.value(*current_neighbor.triangle).get_neighbor(rotate_edge_name(current_neighbor.edge.name)); current_neighbor = neighbors.value(*current_neighbor.triangle).get_neighbor(rotate_edge_name(current_neighbor.edge.name));
} while (*current_neighbor.triangle != triangle); } while (current_neighbor.triangle != NULL && *current_neighbor.triangle != triangle);
assert(current_neighbor.triangle != NULL); // assert(current_neighbor.triangle != NULL);
return ns; return ns;
} }
...@@ -410,14 +415,16 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian ...@@ -410,14 +415,16 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
*/ */
Triangle::Neighbors ns = neighbors.value(*triangle); Triangle::Neighbors ns = neighbors.value(*triangle);
if (!irregular_triangles.contains(*ns.uv.triangle)) { QVector<Triangle> neighboring_triangles;
extra_triangles.insert(*ns.uv.triangle, true); neighboring_triangles += vertexNeighbors(*triangle, ns.uv, neighbors);
} neighboring_triangles += vertexNeighbors(*triangle, ns.vw, neighbors);
if (!irregular_triangles.contains(*ns.vw.triangle)) { neighboring_triangles += vertexNeighbors(*triangle, ns.wu, neighbors);
extra_triangles.insert(*ns.vw.triangle, true); QVectorIterator<Triangle> extra(neighboring_triangles);
} while (extra.hasNext()) {
if (!irregular_triangles.contains(*ns.wu.triangle)) { Triangle extra_triangle = extra.next();
extra_triangles.insert(*ns.wu.triangle, true); if (!irregular_triangles.contains(extra_triangle)) {
extra_triangles.insert(extra_triangle, true);
}
} }
// indices of the three vertices added to the edges of this triangle // indices of the three vertices added to the edges of this triangle
...@@ -491,10 +498,13 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian ...@@ -491,10 +498,13 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
tables.index_buffer.push_back(wu); tables.index_buffer.push_back(wu);
} }
qDebug() << "extra triangles" << extra_triangles.size();
QMapIterator<Triangle, bool> extra_it(extra_triangles); QMapIterator<Triangle, bool> extra_it(extra_triangles);
while (extra_it.hasNext()) { while (extra_it.hasNext()) {
extra_it.next(); extra_it.next();
Triangle triangle = extra_it.key(); Triangle triangle = extra_it.key();
qDebug() << triangle;
unsigned int uv, vw, wu; unsigned int uv, vw, wu;
Edge edge; Edge edge;
......
...@@ -165,6 +165,18 @@ bool Triangle::operator<(const Triangle &other) const { ...@@ -165,6 +165,18 @@ bool Triangle::operator<(const Triangle &other) const {
return false; return false;
} }
bool Triangle::operator<=(const Triangle &other) const {
return (*this < other) || (*this == other);
}
bool Triangle::operator>(const Triangle &other) const {
return !((*this < other) || (*this == other));
}
bool Triangle::operator>=(const Triangle &other) const {
return !(*this < other);
}
void Triangle::rotate_indices() { void Triangle::rotate_indices() {
unsigned int a = u_; unsigned int a = u_;
u_ = v_; u_ = v_;
......
...@@ -57,6 +57,9 @@ class Triangle { ...@@ -57,6 +57,9 @@ class Triangle {
bool operator==(const Triangle &other) const; bool operator==(const Triangle &other) const;
bool operator!=(const Triangle &other) const; bool operator!=(const Triangle &other) const;
bool operator<(const Triangle &other) const; bool operator<(const Triangle &other) const;
bool operator<=(const Triangle &other) const;
bool operator>(const Triangle &other) const;
bool operator>=(const Triangle &other) const;
bool next_ctrclockwise(Edge first, Edge next) const; bool next_ctrclockwise(Edge first, Edge next) const;
bool next_clockwise(Edge first, Edge next) const; bool next_clockwise(Edge first, Edge next) const;
......
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