I’ve had a lot of trouble adequately developing my game that uses terrain for its world. It’s time consuming and just a hassle to do, and I’ve found that it’s related to the behavior caused by some of the tools given to developers for editing terrain. The physical appearance of the terrain is also a large factor of the issues in question.
The primary tools in focus are the Grow, Erode, and Smooth tools. These are the most faulty in the set we are given. The other tools are functional as-needed.
Grow / Erode:
Grow is a very handy tool for shaping terrain as you need it with variable intensity on height and other features. However, the way it works as well as the physical structure of the terrain have a critical flaw: Voxels aren’t full where they need to be.
(Erode is also included in this, but since the tools are so similar I will focus on Grow as it causes more issues)
I’ve made a couple of posts about these strange Occupancy values, one of which was showing a plugin designed to visualize occupancy, and I have pointed out that the way terrain is shaped is a huge factor in hiding these issues.
The grow tool has a side effect with the way it functions causing it to add voxels with fairly low occupancy. For the sake of showing something, I have created a 43 voxel (163 stud) box of terrain. All voxels have the Grass material, and all voxels have their occupancy value set to 0.1
.
Click to see the code I used to generate this
local Mtl = {}
local Occ = {}
for X = 1, 4 do
Mtl[X] = {}
Occ[X] = {}
for Y = 1, 4 do
Mtl[X][Y] = {}
Occ[X][Y] = {}
for Z = 1, 4 do
Mtl[X][Y][Z] = Enum.Material.Grass
Occ[X][Y][Z] = 0.1
end
end
end
workspace.Terrain:WriteVoxels(Region3.new(Vector3.new(0, 0, 0), Vector3.new(16, 16, 16)):ExpandToGrid(4), 4, Mtl, Occ)```
Click to see an image of the result
That box of terrain looks like it’s full of grass. Any developer would assume “Oh, that area is taken up by grass.” Now of course, Grow’s lack of adequate occupancy is nowhere near this level. On average I found that Grow will fill voxels around 50% to 80% depending on where the voxels are and how much you’ve grown. Voxels on the surface were not counted, only voxels that were encased by at least one voxel on all six sides + all eight corners.
This is a very grave flaw. Let’s say I mess up my terrain and I have to erase some stuff with erode. Most of the time, in these areas of low occupancy, terrain is harshly damaged. For perspective, I have created a gif of me using the erode tool with minimum strength on that box I created.
Click to view gif
When recording that, I had tapped my mouse twice when using Erode. The first tap was very brief and the second was about a quarter of a second long, give or take.
Now, imagine that effect but a bit slower. That’s one of the major issues that is caused by the Grow tool with terrain.
Smooth:
Smooth is a bit different in functionality of course, but it has the same exact issue as Grow: Bad occupancy!
In the case of Smooth, it’s not creating partially-full voxels like Grow is, but rather creating very rough areas of terrain especially on slopes. I found that, through visualizing occupancy on a slope that I smoothed out, the terrain could be really smooth if this one issue was solved. (The visualization is done by my plugin, where a black box represents a voxel and the colored box inside represents occupancy. Low occupancy makes a small red box, high occupancy makes a large green box)
Click to see the rough shape, created with three different sized clicks with the Add brush. The brush was set to snap to grid.
As you can see, the surface of that terrain is covered in very low occupancy voxels. I would expect to see a rough staircase-like pattern of large, green voxels (full) with voxels of slightly lower occupancy on top of that surface with slightly lowering values.
My plugin is capable of manually editing occupancy on a single voxel, so for the sake of showing that it looks quite a lot better with what I said, I recreated it manually. For the sake of saving time, I only did the four voxels on the end.
Click to view without and with visualization
I had to go under the surface in order to see the colored boxes. Relative to the image above, I have rotated left 90 degrees, gone under that portion of terrain, and looked up
You can see that it looks quite a lot smoother.
For the time being, I plan to work on plugins to aid developers with this, but I really think some of the stuff in those tools could be reworked to ensure terrain reflects its appearance within its occupancy, as well as giving them much better handling when editing.