top of page
Search

Voxel Project: Improving Performance

  • Writer: Kyle W
    Kyle W
  • Jun 16, 2022
  • 2 min read

Bugs

It turns out there's a lot of ways that there's a lot of different patterns of shapes that can happen, and I haden't quite thought of what happens when certain shapes are next to each other. for example, I hadn't thought about how a front-left facing corner next to a right facing slope creates a gap in the mesh. While I fixed a number of these, in the current setup these have to be handles on a case by case basis, and there are likely more of these that I missed, not to mention what would happen if I added a new shape. Unless I rethink how I approach storing voxel information, this will likely be repeating issue.

ree
Probably going to see more of these in the future

There is also a bug with the way block placement/removal was handled up until now. Until now, I had been targeted the grid via raycast, converted the point hit into grid coordinates, then rounded up & down to get the block that was hit, as well as a block adjacent to it, but this doesn't really work if you hit a slope. I tried to fix this by using the direction of the raycast, but this doesn't really work if you hit a block from an angle. For now, this bug will have to be put aside for next week.

Less Triangles, More Frames

While the voxel grid works, it is far from perfect, and with larger grids it will become much more slower. To start off, I needed a way to measure performance, so I added an FPS counter to the UI for quick reference.

ree

We can also use the stats menu in Unity to measure things like vertex and poly count, time spent by the CPU (It also has an FPS counter, but this one updates too fast to read).

ree
Don't mind the big numbers, most of the tris and verts are from the skybox.

For starters, one of the first things I could do was reduce the complexity of the collider. Until now, the grid has used the same mesh shape as the grid itself, which is a lot of unnecessary vertices. I tried to make a system that combines squares of the same shape together to make one square, and was successful up to a certain point.

ree
Before

ree
After

However, because this only checks based on the Z axis, it doesn't work for blocks that are X or Y aligned to each other, as seen on the edges of the screen. This approach of combining colliders also required some reordering of the vertices to work, which most likely caused more gaps that were previously filled to appear in the mesh.

ree
Initial attempt with a smaller grid

Additionally, I reduced the number of unnecessary checks made whenever the grid was edited, as up until now whenever a single block was modified, the entire grid was checked to see if any shapes had to be updated; I've reduced this to only include adjacent blocks.

Next

I think I'd like to follow up on some of the bugs I found this week (including coming up with a more permenant solution to the gaps), as well as improve on the collider, since it clearly has some room for improvement.

 
 
 

Recent Posts

See All
Voxel Project: Summary

When I started this project, I wanted to get a better understanding of how voxels are implemented, and the different potential...

 
 
 

Comments


bottom of page