jpaver / opengametools

A set of open c++ game development tools that are lightweight, easy-to-integrate and free to use. Currently hosting a magicavoxel .vox full scene loader.
MIT License
373 stars 35 forks source link

draft: Voxel tessellation filter. #9

Closed mrpossoms closed 3 years ago

mrpossoms commented 3 years ago

Hey @jpaver time for me to bug you again 😄

This time I added a function pointer parameter to ogt_stream_from_paletted_voxels_simple to allow a user function to specify conditions for which tessellation for any given voxel should be skipped. For me this is useful to dynamically filter out specific voxel types at tessellation time, so the user can view different sets of voxel types which comprise the volume.

Just let me know if you'd like me to change anything.

mrpossoms commented 3 years ago

I realized that the function needs to be queried for each adjacent voxel for this to work. Will revise.

jpaver commented 3 years ago

Hey @jpaver time for me to bug you again 😄

Haha, no problem it doesn't bug me at all :)

Hi Kirk, sorry I only noticed this now. It sounds like a good use-case, but I'm not sure how generally useful a general mechanism for doing this would be.

I do think the user would be able to do this already (and be able to highly customize their logic) by generating a temporary voxel grid that has zeroes where voxels have been filtered out. It'd look something like this:

eg.

void meshify_with_filter(original_voxel_grid, temp_voxel_grid, filter_func) {
   for each cell {
       temp_voxel_grid[cell] = filter_func(original_voxel_grid[cell]) ? original_voxel_grid[cell] : 0;
   }
   meshify(temp_voxel_grid);
}

The disadvantage is that it requires double the voxel memory during meshification and an additional pass over your voxel data. Not sure how perf sensitive your use-case is but I don't think it'd be too much slower (especially if your grids fit in L1/L2).

The advantage is that it should work with all meshifier algorithms: simple/greedy/polygon.

jpaver commented 3 years ago

Sorry @mrpossoms, I forgot to @ you above.