add more checks in triangle raster code
This commit is contained in:
parent
79a678f162
commit
9550d34e65
7 changed files with 357 additions and 260 deletions
|
|
@ -91,6 +91,21 @@ static void calculate_texture_axes(const pxl8_vec3 normal, pxl8_vec3* u_axis, px
|
|||
}
|
||||
}
|
||||
|
||||
static inline void compute_face_aabb(pxl8_bsp_face* face, const pxl8_bsp_vertex* verts, u32 vert_idx) {
|
||||
face->aabb_min = (pxl8_vec3){1e30f, 1e30f, 1e30f};
|
||||
face->aabb_max = (pxl8_vec3){-1e30f, -1e30f, -1e30f};
|
||||
|
||||
for (u32 i = 0; i < 4; i++) {
|
||||
pxl8_vec3 v = verts[vert_idx + i].position;
|
||||
if (v.x < face->aabb_min.x) face->aabb_min.x = v.x;
|
||||
if (v.x > face->aabb_max.x) face->aabb_max.x = v.x;
|
||||
if (v.y < face->aabb_min.y) face->aabb_min.y = v.y;
|
||||
if (v.y > face->aabb_max.y) face->aabb_max.y = v.y;
|
||||
if (v.z < face->aabb_min.z) face->aabb_min.z = v.z;
|
||||
if (v.z > face->aabb_max.z) face->aabb_max.z = v.z;
|
||||
}
|
||||
}
|
||||
|
||||
static void cave_grid_initialize(cave_grid* grid, f32 density) {
|
||||
for (i32 y = 0; y < grid->height; y++) {
|
||||
for (i32 x = 0; x < grid->width; x++) {
|
||||
|
|
@ -189,6 +204,8 @@ static pxl8_result cave_to_bsp(pxl8_bsp* bsp, const cave_grid* grid) {
|
|||
bsp->surfedges[edge_idx + i] = edge_idx + i;
|
||||
}
|
||||
|
||||
compute_face_aabb(&bsp->faces[face_idx], bsp->vertices, vert_idx);
|
||||
|
||||
vert_idx += 4;
|
||||
edge_idx += 4;
|
||||
face_idx++;
|
||||
|
|
@ -220,6 +237,8 @@ static pxl8_result cave_to_bsp(pxl8_bsp* bsp, const cave_grid* grid) {
|
|||
bsp->surfedges[edge_idx + i] = edge_idx + i;
|
||||
}
|
||||
|
||||
compute_face_aabb(&bsp->faces[face_idx], bsp->vertices, vert_idx);
|
||||
|
||||
vert_idx += 4;
|
||||
edge_idx += 4;
|
||||
face_idx++;
|
||||
|
|
@ -251,6 +270,8 @@ static pxl8_result cave_to_bsp(pxl8_bsp* bsp, const cave_grid* grid) {
|
|||
bsp->surfedges[edge_idx + i] = edge_idx + i;
|
||||
}
|
||||
|
||||
compute_face_aabb(&bsp->faces[face_idx], bsp->vertices, vert_idx);
|
||||
|
||||
vert_idx += 4;
|
||||
edge_idx += 4;
|
||||
face_idx++;
|
||||
|
|
@ -282,6 +303,8 @@ static pxl8_result cave_to_bsp(pxl8_bsp* bsp, const cave_grid* grid) {
|
|||
bsp->surfedges[edge_idx + i] = edge_idx + i;
|
||||
}
|
||||
|
||||
compute_face_aabb(&bsp->faces[face_idx], bsp->vertices, vert_idx);
|
||||
|
||||
vert_idx += 4;
|
||||
edge_idx += 4;
|
||||
face_idx++;
|
||||
|
|
@ -321,6 +344,8 @@ static pxl8_result cave_to_bsp(pxl8_bsp* bsp, const cave_grid* grid) {
|
|||
bsp->surfedges[edge_idx + i] = edge_idx + i;
|
||||
}
|
||||
|
||||
compute_face_aabb(&bsp->faces[face_idx], bsp->vertices, vert_idx);
|
||||
|
||||
vert_idx += 4;
|
||||
edge_idx += 4;
|
||||
face_idx++;
|
||||
|
|
@ -350,6 +375,8 @@ static pxl8_result cave_to_bsp(pxl8_bsp* bsp, const cave_grid* grid) {
|
|||
bsp->surfedges[edge_idx + i] = edge_idx + i;
|
||||
}
|
||||
|
||||
compute_face_aabb(&bsp->faces[face_idx], bsp->vertices, vert_idx);
|
||||
|
||||
vert_idx += 4;
|
||||
edge_idx += 4;
|
||||
face_idx++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue