Skip to content

Commit 965f453

Browse files
committed
fuck yeah vgeom fix
1 parent b280c2a commit 965f453

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Common/helper_cuda.h

+2
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,15 @@ static const char *_cudaGetErrorEnum(NppStatus error) {
579579
}
580580
#endif
581581

582+
#include <cassert>
582583

583584
template <typename T>
584585
void check(T result, char const *const func, const char *const file,
585586
int const line) {
586587
if (result) {
587588
fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line,
588589
static_cast<unsigned int>(result), _cudaGetErrorEnum(result), func);
590+
assert(0);
589591
exit(EXIT_FAILURE);
590592
}
591593
}

src/render/virtual_geometry/analyzer/mesh_analyzer.cu

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
#include "../../../util/const.h"
66
#include "mesh_analyzer.h"
77

8+
__device__ int get_subdivision_count(float area, int threshold) {
9+
float unit = area;
10+
int count = 1;
11+
while (unit > threshold) {
12+
unit /= 4;
13+
count *= 4;
14+
}
15+
return count;
16+
}
17+
818
template <typename ShaderType>
919
__global__ void analyze_faces(DrawCallBaseArgs args, ModelDrawCallArgs model_args, const Image image, int threshold, bool *face_mask, int n_faces, int *new_virtual_faces) {
1020
int position = blockIdx.x * blockDim.x + threadIdx.x;
@@ -21,7 +31,7 @@ __global__ void analyze_faces(DrawCallBaseArgs args, ModelDrawCallArgs model_arg
2131
if (pts[0].y==pts[1].y && pts[0].y==pts[2].y) return;
2232

2333
glm::vec2 bboxmin{float(image.width-1), float(image.height-1)};
24-
glm::vec2 bboxmax{0., 0.};
34+
glm::vec2 bboxmax{0.01, 0.01};
2535
glm::vec2 clamp{float(image.width-1), float(image.height-1)};
2636
for (auto &pt : pts) {
2737
bboxmin.x = max(0.0f, min(bboxmin.x, pt.x));
@@ -31,9 +41,11 @@ __global__ void analyze_faces(DrawCallBaseArgs args, ModelDrawCallArgs model_arg
3141
bboxmax.y = min(clamp.y, max(bboxmax.y, pt.y));
3242
}
3343

34-
float area = (bboxmax.x - pts[0].x) * (bboxmax.y - pts[0].y);
44+
45+
float area = (bboxmax.x - bboxmin.x) * (bboxmax.y - bboxmin.y);
3546
if (area > threshold) {
36-
atomicAdd(new_virtual_faces, ceil(area / (float)threshold));
47+
auto count = get_subdivision_count(area, threshold);
48+
atomicAdd(new_virtual_faces, count);
3749
face_mask[position] = true;
3850
}
3951
}

src/render/virtual_geometry/virtual_model/virtual_model.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ void VirtualModel::accept(ModelDrawCallArgs args, bool *disabled_faces_to_copy,
3434

3535
int max_texture_index = args.model.max_texture_index;
3636

37-
auto multiplier = 9;
37+
auto multiplier = 3;
3838
auto vvert_count = multiplier * vface_count;
3939

40+
4041
if (vface_count > n_allocated_faces)
4142
{
4243
n_allocated_faces = vface_count;

0 commit comments

Comments
 (0)