Marching cubes #9

Open
opened 2022-03-05 14:43:20 +00:00 by mars · 0 comments
Owner

a very useful tool to have earlier in design is marching cubes. with it we could do some procedural cave generation, terrain generation, cloud rendering, or any shape that can be generated with an SDF or pseudo-SDF. Inigo Quilez's work will come in handy. CSG-based modeling could also have a jumping-off point by using this. if the marching cubes algorithm is fast enough, maybe we could do some real-time generation of complex moving shapes like metaballs.

the implementation would be pretty simple, in my opinion: the marching cubes function takes:

  • a distance field function
  • a set of boxes aligned on the grid, specifying the cubes that need to be marched
    and spits out:
  • an array of vertices with positions and normals
  • an array of indices, as a triangle list pointing to the vertices

a basic implementation could:

  • generate SDF values at the corners of all the cubes
  • iterate over each cube, and look up the geometry in a table
  • derive the fine positions ans normals of each vertex from the SDF values
  • append the triangles to the output arrays

vertex deduplication can be done in post, at the expense of processing time. the next improvement on the algorithm would be to deduplicate vertices as cubes are being marched by smartly reusing them from other cubes.

someone out there has figured out how to cache-optimize this for sure, that'll need some research tho

triplanar mapping shaders and the basic algorithm could be used to do some simple terrain generation pretty easily, as a demo.

advanced features i'd like to explore are:

  • use of octree-like partioning and true SDF lookups to quickly discard large swaths of cubes in a radius at once
  • LOD: double/halve the cube size smoothly, and fix the seams between... somehow
a very useful tool to have earlier in design is marching cubes. with it we could do some procedural cave generation, terrain generation, cloud rendering, or any shape that can be generated with an SDF or pseudo-SDF. Inigo Quilez's work will come in handy. CSG-based modeling could also have a jumping-off point by using this. if the marching cubes algorithm is fast enough, maybe we could do some real-time generation of complex moving shapes like metaballs. the implementation would be pretty simple, in my opinion: the marching cubes function takes: - a distance field function - a set of boxes aligned on the grid, specifying the cubes that need to be marched and spits out: - an array of vertices with positions and normals - an array of indices, as a triangle list pointing to the vertices a basic implementation could: - generate SDF values at the corners of all the cubes - iterate over each cube, and look up the geometry in a table - derive the fine positions ans normals of each vertex from the SDF values - append the triangles to the output arrays vertex deduplication can be done in post, at the expense of processing time. the next improvement on the algorithm would be to deduplicate vertices as cubes are being marched by smartly reusing them from other cubes. someone out there has figured out how to cache-optimize this for sure, that'll need some research tho triplanar mapping shaders and the basic algorithm could be used to do some simple terrain generation pretty easily, as a demo. advanced features i'd like to explore are: - use of octree-like partioning and true SDF lookups to quickly discard large swaths of cubes in a radius at once - LOD: double/halve the cube size smoothly, and fix the seams between... somehow
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cyborg/cyborg#9
No description provided.