1
\$\begingroup\$

For my game, I have a tool that lets me quickly create map geometry. You can see a (albeit early version) demo of the tool here. The main problem with the tool is that even a semi-large map can EASILY amount to around thousands to even 10s of thousands of tiles. The easiest way to fix this, I found, was to use a script I found online to merge all of the tiles into one mesh at the start of runtime (this is because I want to still be able to edit my tilemap in the editor)

This works and has a noticable improvement to the performance (especially if post-processing is enabled) however I'm left with a mesh that has a bunch of triangles that just aren't needed. You can see an image of the mesh here. The problem with this is that if I want to do any kind of point lights with shadows (baked lighting isn't possible, really, due to the interactivity of my game since you can turn lights on/off and I have a weird day/night system that is split into multiple periods of the day and only changes after a mission/event) would mean I'm rendering that mesh again from each point lights POV (and I need a LOT of point lights). I can't really just not use shadows since it causes very noticable light bleeding at walls.

I've tried to find some sort of algorithm to simplify the mesh and I came across a script that seems to do exactly what I want, but I couldn't get it to do anything except cause my mesh to become completely black with seemingly no change in mesh topology. Here's the script by the way

I've also found an algorithm called Greedy Meshing which seems to also do what I want, but seems to be meant for voxel based worlds like minecraft and I'm not sure how to implement it in my case since my tiles aren't voxels.

I've been trying to find other algorithms but the various game dev servers on discord can't seem to help me. Does anyone know how I can solve this problem? I'm not really smart enough to come up with my own algorithm/system to simplify the mesh.

\$\endgroup\$
  • \$\begingroup\$ The algorithm must limit the aggregation process to polygons all having the same material and it must apply this material to the resulting polygons. Probably the script is simply ignoring the material and creates polygons with no material set. This would explain the black mesh. \$\endgroup\$ – Olivier Jacot-Descombes Jul 27 at 16:01
  • \$\begingroup\$ I don't think so, since a mesh with no attached materials is always pink for me. \$\endgroup\$ – Ducktor Jul 27 at 17:22
0
\$\begingroup\$

I have solved this for the most part, atleast for floor tiles.

I was able to get the script, that I spoke about in the OP that didn't work, working and was able to get it to simplify the floor tile mesh (wall simplification doesn't work yet, sadly.)

Here's an image of the tilemap in the editor and the tilemap at runtime

Essentially:

  • Tiles are first merged using Unity's MeshCombiner utility
  • Then the mesh simplification classes 'Weld' function is used to remove any duplicate vertices
  • Then the mesh simplification classes 'Simplify' function is used to simplify the mesh
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.