Skip to content

Commit

Permalink
use hull in big scene
Browse files Browse the repository at this point in the history
  • Loading branch information
kannoneer committed Oct 20, 2023
1 parent 4dd3487 commit f4f8cb1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
9 changes: 5 additions & 4 deletions examples/occlusion/occdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ void render_big_scene(surface_t* disp)
// HACK: always draw occluders to SW Z-buffer even if they didn't pass the rough check
if (true || visible) {
// also draw to software zbuffer
occ_draw_mesh(culler, sw_zbuffer, &cube_hull.mesh, xform);
//occ_draw_mesh(culler, sw_zbuffer, &cube_hull.mesh, xform);
occ_draw_hull(culler, sw_zbuffer, &cube_hull, xform);
}
if (visible) {
big_scene.stats.num_drawn++;
Expand Down Expand Up @@ -526,9 +527,9 @@ void render()
occ_set_view_and_projection(culler, &g_view, &g_projection);

//render_door_scene(disp);
//render_big_scene(disp);
render_big_scene(disp);
//render_2d_scene(disp);
render_single_cube_scene(disp);
// render_single_cube_scene(disp);

gl_context_end();

Expand Down Expand Up @@ -698,7 +699,7 @@ int main()

rspq_flush();
uint32_t ticks_end = get_ticks();
if (false) {
if (true) {
double delta = (ticks_end - ticks_start) / (double)TICKS_PER_SECOND;
debugf("deltatime: %f ms\n", delta * 1000.0);
prof_print_stats();
Expand Down
19 changes: 9 additions & 10 deletions examples/occlusion/occlusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const float inv_subpixel_scale = 1.0f / SUBPIXEL_SCALE;
#define ZBUFFER_UINT_PTR_AT(zbuffer, x, y) ((u_uint16_t *)(zbuffer->buffer + (zbuffer->stride * y + x * sizeof(uint16_t))))

#define DUMP_WHEN_Z_OVERFLOWS 1
#define SCREENSPACE_BIAS (-0.5f) // bias for (x,y) screenspace coordinates to make them cover RDP draw pixels
#define SCREENSPACE_BIAS (-0.50f) // an empirical bias for (x,y) screenspace coordinates to make them cover OpenGL drawn pixels

// Rasky's "defer statement" implementation.
#define PPCAT2(n,x) n ## x
Expand Down Expand Up @@ -232,7 +232,7 @@ void draw_tri(
occ_raster_query_result_t* result,
surface_t *zbuffer)
{
// The -0.5 screenspace bias is added to empirically match SW depth map pixels to hi-rez RDP picture.
// The screenspace bias is added to empirically match SW depth map pixels to hi-rez RDP picture.
vec2 v0 = {SUBPIXEL_SCALE * (v0f.x+SCREENSPACE_BIAS) + 0.5f, SUBPIXEL_SCALE * (v0f.y+SCREENSPACE_BIAS) + 0.5f};
vec2 v1 = {SUBPIXEL_SCALE * (v1f.x+SCREENSPACE_BIAS) + 0.5f, SUBPIXEL_SCALE * (v1f.y+SCREENSPACE_BIAS) + 0.5f};
vec2 v2 = {SUBPIXEL_SCALE * (v2f.x+SCREENSPACE_BIAS) + 0.5f, SUBPIXEL_SCALE * (v2f.y+SCREENSPACE_BIAS) + 0.5f};
Expand Down Expand Up @@ -504,17 +504,17 @@ void occ_draw_indexed_mesh_flags(occ_culler_t *occ, surface_t *zbuffer, const ma

if (tri_normals) {
int num_tris = mesh->num_indices/3;
debugf("num_tris: %d\n", num_tris);
// debugf("num_tris: %d\n", num_tris);
for (int i = 0; i < num_tris; i++) {
float n_model[4] = {tri_normals[i].x, tri_normals[i].y, tri_normals[i].z, 0.f};
float n[4];
//TODO use inverse transpose if non-uniform scale?
matrix_mult(&n[0], modelview, &n_model[0]);
view_normals[i] = (vec3f){n[0], n[1], n[2]};
debugf("[%-2d] (%f, %f, %f, %f) -> (%f, %f, %f, %f)\n",
i,
n_model[0], n_model[1], n_model[2], n_model[3],
n[0], n[1], n[2], n[3]);
// debugf("[%-2d] (%f, %f, %f, %f) -> (%f, %f, %f, %f)\n",
// i,
// n_model[0], n_model[1], n_model[2], n_model[3],
// n[0], n[1], n[2], n[3]);
}
}
prof_end(REGION_TRANSFORM);
Expand Down Expand Up @@ -571,13 +571,12 @@ void occ_draw_indexed_mesh_flags(occ_culler_t *occ, surface_t *zbuffer, const ma
}

if (tri_neighbors) {
// Silhouette edges join triangles with different view space Z signs
for (int j = 0; j < 3; j++) {
uint16_t other = tri_neighbors[tri_idx * 3 + j];
// debugf("j=%d, other=%u\n", j, other);
if (other != OCC_NO_EDGE_NEIGHBOR) {
vec3f *N_other = &view_normals[other];
if (N_other->z < 0) {
// debugf("tri_idx=%d, N->z = %f, N_other = %f\n", tri_idx, N->z, N_other->z);
edge_flag_mask |= (RASTER_FLAG_SHRINK_EDGE_01 << j);
}
}
Expand Down Expand Up @@ -896,7 +895,7 @@ bool occ_hull_from_flat_mesh(const occ_mesh_t* mesh_in, occ_hull_t* hull_out)

m->num_vertices = 0; // will be incremented in the loop below

bool verbose = true;
bool verbose = false;

for (uint32_t vertex_idx=0; vertex_idx < mesh_in->num_vertices; vertex_idx++) {
float f[3] = {
Expand Down

0 comments on commit f4f8cb1

Please sign in to comment.