Infinite detail engine concept
The general idea: break the scene into voxels, render one quad per plane. That way, every time you double the polygon count you get 8x the voxels.
To draw a 512x512x512 voxel scene, you need 513 + 513 + 513 quads.
To draw a 1024x1024x1024 voxel scene, you need 1025 + 1025 + 1025 quads. That's twice the quads for the GPU to draw, but 8x the resulting amount of voxels/details onscreen!
If we can do 4096x4096x4096 (giving us more detail in a scene than we can display) that's only 24576 polygons.
then we can draw front to back and use the GPU's z-buffer to avoid massive overdraw. Can the GPU handle 12,288 screen-sized quads if most of them ends up discarded or z-culled early?
Once we have our planes on the screen it's just a matter of figuring out where our fragment shader should read from within a large 3D texture.
There's too much wasted empty space in a basic 3D texture (a single 1024x1024x1024 uncompressed 4-channel 8-bit is 4gb, yikes!) so we need a system to eliminate most of the empty areas.
Here's my solution: large coarse tiles, 1 cubic meter in size. Each large coarse tile contains a target 3D rect within our massive 3D texture + a world space to texture space transformation matrix.
In your fragment shader you read the coarse tile source, discard if it's empty space (95% of the time), multiply your fragment shader's world space position by the texture space matrix, discard if you're outside the target 3D rect, read the texture, discard if the alpha is zero and write the final color. Maybe there's a trick to it, where you can sample the texture at the correct edge and draw only the edges where the result alpha's above zero but below 1 due to interpolating between solid and non-solid.
Coarse tiles solves the empty space problem to a certain extent, gives us a way to make densely packed maps, and adding a second layer of coarse tile data lets us add moving/interacting game objects.
To generate our massive 3D texture, we make a scene in blender, put our solid objects / geometry tiles close to each other, map the resulting bounding box to our 3D texture size and make a custom export script that checks if each point in our 3D texture point is inside the model (solid, color = color of the nearest surface) or outside (not solid) then we run the resulting texture through either NVidia or AMD's texture compression tools. It's still a HUGE waste on some types geometry, but mostly flat surfaces along the XY, XZ and YZ planes should stack and compress well.
Posted May 28, 2020, 8:30 PM UTC
Hey, yes, this is not a new idea and you got it quite right. You are thinking about "octrees", a way to save memory for empty spaces, while still retaining an
O(log n)lookup performance.As other redditors said, the problem with voxel rendering is not the performance, as the rendering can be optimized quite a lot and even run on limited hardware. The problem is with memory. Storing small voxels requires huge amounts of memory.
Computer scientists have been trying to further optimize memory usage by using "sparse octrees".
The problem with octrees (especially if sparse) is that they are difficult to update in real-time. Again, as other redditors pointed out, skeletal animations would be very difficult (impossible?) to implement. Every frame would require a copy of the scene, potentially a lot of memory necessary.
Here's a video that you might find inspirational or at least interesting: https://youtu.be/W_Gswk2lZ-w