Objective:
I wish to design a 3D game that allows players to place modular objects for building purposes. The placed objects will always be upright, and may occasionally clip through terrain to remain upright.
Question:
Is there a performance friendly way to allow the placed object to delete/mask the intersecting terrain in run time, by the player?
I was contemplating 3 potential approaches, but alternatives are welcome:
Use some form of boolean subtract,
but this could be costly during run
time, and might not function well
with complex geometry like terrain.
Design a voxel based terrain, where
it deletes an area of voxels in a
specified direction of the placed
object.
Find a way to mask the undesired
portion of terrain and it’s attached
physics.
I’ve attached an image of what I am trying to accomplish. Any suggestions on ways to possibly accomplish this scenario are greatly appreciated.
Voxel terrain (using the asset “Voxeland” as my point of reference):
Pros:
Capable of high detail/realistic textures
Allows easy creation of tunnels in terrain
Supports decent water shaders
Supports near limitless terrain sizes
Can be edited by the player during run time, with manageable performance
Cons:
Limitation on the maximum amount of textures. With texture arrays enabled, the number of possible block types (texture channels) is limited to 24 for all platforms that support texture arrays. When disabled, the maximum number of block types is limited to 4-16 depending on the build platform.
Edit height map data with TerrainData.SetHeights:
Pros:
Near limitless amount of textures can be used
Easily customizable terrain deforming brushes and falloffs can be used to edit terrain by the player in run time
CPU strain can be eased if using tessellation with GPU
Works well with many mesh editors and shaders
Cons:
Doesn’t allow tunnels through terrain due to 0-1 black/white height map (A work around for tunnels, is a time consuming process of manually creating a new object to shape as the tunnel with the exit point matching the exact exterior of the intersecting terrain)
May run into performance issues if running multiplayer, or too much terrain being edited (performance can be improved by using TerrainData.SetHeightsDelayLOD instead, followed by Terrain.ApplyDelayedHeightmapModification)
Unable to undo terrain changes, as they override the height map
Texture quality might suffer in and around terrain changes, if not using tesselation
Contrary to the high pros and low cons, the limitation on the amount textures for voxel terrain makes me lean towards editing the heightmap as my preffered method so far.
I will be looking into masking options next, to see if masking is a viable solution to my goal. With the little research I did on boolean subtracting meshes, it seemed far too unstable for complex meshes, for me to consider looking into that option further.
If anyone has any input on my current provided research, or any alternate solutions that I haven’t considered yet, please advise.
Here are some of the sources of my current research, for any interested: