diff --git a/res/dpr/strategy/mesh_based_reprojection/mesh_based_reprojection_edge_detection.comp b/res/dpr/strategy/mesh_based_reprojection/mesh_based_reprojection_edge_detection.comp index 8945baeaf11ce8b016ca92c1b974561b840d916d..33ec9b3bec17512e67fa553957e057685c6f015b 100644 --- a/res/dpr/strategy/mesh_based_reprojection/mesh_based_reprojection_edge_detection.comp +++ b/res/dpr/strategy/mesh_based_reprojection/mesh_based_reprojection_edge_detection.comp @@ -15,6 +15,36 @@ layout(push_constant) uniform Parameters MeshBasedReprojectionEdgeDetectionParameters parameters; }; +bool check_depth(ivec2 coord) +{ + for(int offset_y = -1; offset_y <= 1; offset_y++) + { + for(int offset_x = -1; offset_x <= 1; offset_x++) + { + ivec2 sample_coord = coord + ivec2(offset_x, offset_y); + + if(sample_coord.x < 0 || sample_coord.x >= parameters.layer_resolution.x) + { + continue; + } + + if(sample_coord.y < 0 || sample_coord.y >= parameters.layer_resolution.y) + { + continue; + } + + float depth = texelFetch(sampler_layer_depth, sample_coord, 0).x; + + if(depth <= parameters.depth_threshold) + { + return true; + } + } + } + + return false; +} + float compute_laplacian(ivec2 coord) { if(coord.x - 1 < 0 || coord.x + 1 >= parameters.layer_resolution.x) @@ -38,7 +68,7 @@ float compute_laplacian(ivec2 coord) if(offset_x == 0 && offset_y == 0) { - weight = 8.0; + weight = 4.0; } laplacian += weight * depth; @@ -79,14 +109,13 @@ float compute_normal_change(ivec2 coord) void main() { ivec2 coord = ivec2(gl_GlobalInvocationID); - float depth = texelFetch(sampler_layer_depth, coord, 0).x; - /*if(depth > parameters.depth_threshold) + if(!check_depth(coord)) { imageStore(image_layer_edge, coord, vec4(0.0)); return; - }*/ + } float laplacian = compute_laplacian(coord); float normal_change = compute_normal_change(coord); diff --git a/src/strategy/mesh_based_reprojection.cpp b/src/strategy/mesh_based_reprojection.cpp index 8ba427a50c785e8de2fae0360def305c428e8035..1839377d68dd32d148a4517e8b6fb9ced24999df 100644 --- a/src/strategy/mesh_based_reprojection.cpp +++ b/src/strategy/mesh_based_reprojection.cpp @@ -2126,6 +2126,8 @@ void MeshBasedReprojection::worker_process_edge_buffer(uint32_t layer, MeshBased triangulation.insert_constraint(edge_start, edge_end); } + std::vector<MeshBasedReprojectionEdge> debug_edges; + for (FaceHandle face_handle : triangulation.finite_face_handles()) { std::array<glm::vec3, 3> points; @@ -2228,6 +2230,49 @@ void MeshBasedReprojection::worker_process_edge_buffer(uint32_t layer, MeshBased sample_direction.x = this->triangle_depth_offset * glm::cos(center_angle); sample_direction.y = this->triangle_depth_offset * glm::sin(center_angle); + for (const MeshBasedReprojectionEdge& edge : edge_buffer->edges) + { + glm::vec2 edge_start = glm::vec2(edge.start) - sample_base; + glm::vec2 edge_end = glm::vec2(edge.end) - sample_base; + + if (glm::all(glm::lessThan(edge_start, glm::vec2(0.1f)))) + { + continue; + } + + if (glm::all(glm::lessThan(edge_end, glm::vec2(0.1f)))) + { + continue; + } + + float edge_length = glm::distance(edge_end, edge_start); + glm::vec2 edge_direction = (edge_end - edge_start) / edge_length; + glm::vec2 edge_normal = glm::vec2(edge_direction.y, -edge_direction.x); + + float factor = glm::dot(sample_direction, edge_normal); + + if (factor == 0.0f) + { + continue; + } + + float lambda = glm::dot(edge_start, edge_normal) / factor; + + glm::vec2 edge_intersect = lambda * sample_direction; + float edge_lambda = glm::dot(edge_intersect - edge_start, edge_direction); + + if (edge_lambda < 0.0 || edge_lambda > edge_length) + { + continue; + } + + if (0.0f < lambda && lambda < 1.0f) + { + sample_direction = edge_intersect / 2.0f; + } + } + + /*for (uint32_t edge_index = 0; edge_index < partion_edges.size() - 1; edge_index++) { Edge face_edge1 = partion_edges[edge_index]; @@ -2295,7 +2340,7 @@ void MeshBasedReprojection::worker_process_edge_buffer(uint32_t layer, MeshBased } } - else + /* else { MeshBasedReprojectionEdge line1; line1.start = glm::ivec2(sample_base) + glm::ivec2(5, 5); @@ -2307,12 +2352,24 @@ void MeshBasedReprojection::worker_process_edge_buffer(uint32_t layer, MeshBased edge_buffer->edges.push_back(line1); edge_buffer->edges.push_back(line2); - } + }*/ glm::ivec2 sample_point = glm::ivec2(sample_base) + sample_offset; sample_point = glm::clamp(sample_point, glm::ivec2(0), glm::ivec2(resolution - 1u)); + MeshBasedReprojectionEdge line1; + line1.start = glm::ivec2(sample_point) + glm::ivec2(1, 1); + line1.end = glm::ivec2(sample_point) - glm::ivec2(1, 1); + + MeshBasedReprojectionEdge line2; + line2.start = glm::ivec2(sample_point) + glm::ivec2(1, -1); + line2.end = glm::ivec2(sample_point) - glm::ivec2(1, -1); + + debug_edges.push_back(line1); + debug_edges.push_back(line2); + float sample_depth = depth_image_pointer[sample_point.y * resolution.x + sample_point.x]; + sample_depth = glm::min(sample_depth, this->edge_detection_depth_threshold); points[index] = glm::vec3(vertex->point().x(), vertex->point().y(), sample_depth); } @@ -2340,6 +2397,7 @@ void MeshBasedReprojection::worker_process_edge_buffer(uint32_t layer, MeshBased this->edge_geometry_list[layer].clear(); this->edge_geometry_list[layer].insert(this->edge_geometry_list[layer].begin(), edge_buffer->edges.begin(), edge_buffer->edges.end()); + this->edge_geometry_list[layer].insert(this->edge_geometry_list[layer].end(), debug_edges.begin(), debug_edges.end()); this->triangle_geometry_list[layer].clear(); this->triangle_geometry_list[layer].insert(this->triangle_geometry_list[layer].begin(), edge_buffer->triangles.begin(), edge_buffer->triangles.end()); @@ -2625,7 +2683,7 @@ bool MeshBasedReprojection::worker_intersect_edge(MeshBasedReprojectionEdgeBuffe continue; } - if (glm::max(-closest_distance, -edge_length) < lambda && lambda < closest_distance) + if (glm::max(-glm::abs(closest_distance), -edge_length / 2.0f) < lambda && lambda < glm::abs(closest_distance)) { closest_distance = lambda; closest_point = intersect;