GAMEDEV.NET
Buildings destruction for RTS games
Buildings destruction for RTS games Published December 28, 2024 by Kopavel Do you see issues with this article? Let us know. Advertisement Hello dear readers!I've been working on my RTS game for about 3 years, using my personal game engine, and one of the things I'm really happy with is the way buildings are demolished, have a look -We are a very small team, so I had some important conditions for destruction systemIt need to be easy to set up, because we don't have time and resources to i.e. decompose meshes and then animate themIt need to be reliable because I can't be coming back to it once it's doneIt need to look cool and make my game stand out among dozens of other RTS gamesThose points are especially important because we expect the community to make mods for our game, and our destruction solution should work out of the box for them.So here's how it's done in The Scouring.Part 1. SetupAll the artist need to do is attach mesh blobs to parts of the building that he wants to come off, like this -We use about 100-150 blobs for buildings, and it takes just a couple of hours to set them up.And that's it.Part 2. Mesh ProcessingMost destruction systems use geometric intersections (boolean operations) to break mesh into pieces. However, it is a very slow and complex process that generally requires the mesh to be constructed in a specific, “correct” way.Instead we use alpha-clipping to break the mesh into pieces.2.1. So the first thing is to generate blob intersections against the original mesh.These are our chunks that will break off the building.We also generate the “backsides” of each hole.This might be the trickiest part of the whole thing, but I would not like to go into details of it as it is very technical. Get in touch with me if you need more details.2.2. Next, generate a texture atlas for our buildingThere are publicly available libraries that can do that, I used https://github.com/jpcy/xatlas.For an RTS camera and a building like that, 512x512 atlas has enough accuracy.2.3. Iterate every pixel in the atlas, and mark it with chunk id when the corresponding 3d position on the building surface is within one of the “blobs” This is the most time-consuming process (relatively speaking, the whole process described in this paper takes 0.25 ms on my 10 years old PC).The most important thing to speed things up is to assume all blobs to be “convex” (and there is no reason not to do so).Checking if a given point is inside a 3d convex hull is trivial. And there is a public library that generates convex hulls - https://github.com/akuukka/quickhullPart 3. RuntimeSo when a unit hits a building, we detect the chunk that is closest to the hit position, and mark it as active. Each building has a texture buffer with the size of “n chunks”, storing a boolean for each chunk, whether it is active or not.In pixel shader, we read the texture atlas storing chunks id’s, and do a clip if this chunk is active.We also need to show the “backside” of a clipped hole. We render the “backsides” mesh, with the inverted logic of the check mentioned above (if a chunk is active - DON’T clip the backside).And of course the chunk itself. If the building is visible, we spawn a physical body for it. If not, we simply activate it in its resting position (next to the building). We only use 3 calls to draw the whole thing:Building itselfBacksidesChunks. We put all of the chunks geometry into a single geometry buffer, and use the same texture buffer in pixel shader to clip-out inactive chunks.When the building is being repaired, instead of activating the chunks, we deactivate them.Last (but not least) a few notes about additional effects.We separate the building into “burnable” and “static” parts. The “burnable” part slides down when the building is destroyed, and has some fancy shader effects applied to. The “static” parts simply dissolves (using a screen-space per-pixel technique)Thank you for reading!If you have any questions, please fire at pavzag@gmail.com!And please check out our game on Steam!https://store.steampowered.com/app/3338950/The_Scouring/ Cancel Save 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!
0 Commentarii 0 Distribuiri 49 Views