🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Demonstration of Map Mesh

posted in jhocking
Published August 27, 2019 Imported
Advertisement

Last month I described in words how I was building a clickable map using vertex colors. Well, a reader requested I make some visuals to demonstrate what I was talking about, so I whipped up a demo in Unity and grabbed a video of my screen:

strat-map-action

You can see a tile grid with vertex colors, and all the colors are scrambled every click. Technically you could do this with multiple materials, but you would need a lot of materials (one for every color, which is basically every tile) with that approach. That creates two problems:

  1. You would need to store and keep track of all those materials. This is actually not that bad, but would be really annoying, and a waste of memory for a big map.
  2. Every material forces a draw call. This is the bigger deal, since lots of draw calls is bad for performance.

By using vertex colors, the entire map is just one mesh with one material (using a custom shader that displays vertex colors). And it’s super fast to update the colors, as opposed to rendering onto a texture or something.

The other thing apparent in this demo is the sphere moving around. I threw that in as a quick demonstration of mouse interaction. By doing a raycast against the map mesh, I can easily determine the triangle that the mouse is over. I can use that to index into a list of tile data that was generated along with the mesh, returning (among other things) the center of that tile. You can’t see it in this recording, but the debug console is also printing the name assigned to each tile.

So like I said last month, this kind of proc-gen mesh is really useful for doing a strategy game’s map!


View the full article

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement