Progress of my voxelengine after 1 week:
Its half time now and I could gather a lot of knowledge about voxel engines. The current engine now has an octree which supports a depth of 8 while maintianing decent framerate. It could go deeper but therefore either a better pc is required or better oprimized code. The most difficult part is the visual hull construction which must be very fast. I also tested a different data structure similar to octree but each node has 64 children instead of eight which basically skips one depth. However it was slower than the normal octree. The next week will fokus on the visual hull construction and optimisation.
Visual hull construction:
Whenever the state of a voxel changes, the visual representation and colliders must be updated. Now when many voxels are changed, it would attemt to create a new representation for each change done. To prevent this, the changes are collected and a certain amount is processesd after each update. When a voxel changes, an upward check is done to find a start node which is then added to an queue if it does not exist there already. Start nodes are those where the depth modulo meshdeepness results in zero. For example a meshdeepness of 2 means that a start node will group all voxels two depths below including the start node.
The visual hull generation process takes a set amount of start nodes each update and generates the visual mesh. For each gathered start node, a mesh is generated by gathering all leafs below to a certain depth and applies the visual hull construction to get one single mesh. The visual hull construction is currently simply baking a predifned mesh together.
Unitys new Job system:
Unity 2018 has a new feature which allows multithreading which improved the visual hull construction speed by an significant amount.A Job is an interface which implements a function called Execute(int Index) where the parallelized stuff is implemented.and behaves similar to an shader.
The downside is that these Jobs are C# structs and are restricted by Unity to only allow structs as members. The job system also requires a data oriented design in order to gain performance instead of losing it. Baking meshes together using one mesh was suitable because an output array is filled with vertex information according to position,size and shape information. It should also work with other visual hull construction and just different input information like neighbors are required.
Currently using the Job system is not possible for the whole voxel engine as it is not possible to access the octree unless an linear octree is used which would explode the memory requirement.