March 22, 2016 By: David Tse
This last month has been a pretty big one for Survive
development. Houses are finally in the game! Then if that wasn’t enough I also made significant progress on house generation 2.0! I’m working really hard to get this to a base level where I can release it to you guys as soon as possible. Then I can start doing much quicker generation/content updates with improved house/city layouts and new assets. Until then here’s all the stuff I got done over the last month.
The first thing I had to do to get houses into the game was to decide where they should actually be placed in the world. Right now the algorithm is fairly simple, but I think it’s pretty powerful. It can also be extended fairly easily to place much larger buildings and lots in the future.
View of generated house from the outside. Ignore the hole between top and bottom of the roof, it will be connected.
The way it works is it goes through all the roads and looks on both sides of it to see if there is room for a house with a yard. If there is it simply places a house. This is the part that will be extended to handle large buildings and areas. Instead of searching both sides looking for a house sized space it will try to find enough room for a large supermarket and parking lot for example.
After the building is placed there is also a driveway road generated that connects the building to the road, but I haven’t gotten around to saving/loading them yet. This connector road can be a simple driveway for houses or longer roads connecting a parking lot.
Close up view of a neighborhood.
Once the house lots have been placed there is a culling pass where we go through all the houses and delete any of them that are overlapping with each other or other roads. After that the remaining houses are shifted and resized a little to try and fill any gap left over. This part is not 100% done yet which is why you will see overlapping houses at road intersections.
Like I said before the algorithm is fairly simple, but should be good enough to place all the buildings we will need. Well, At least for now. It may require a more complex solution in the future, but this was the first thing I tried and it seems like it will be able to produce the results we need.
Once I got the house lots placed it was now time to revisit the original house generation algorithm I worked on and posted a video about a while ago. That first attempt was OK in that it made houses with all the required rooms. The problem was it didn’t really account for the exterior at all and was not that realistic because most houses don’t have so much wasted space.
Same neighborhood as before with roofs cut off to show they all have interiors. You can enter every single house!
So the solution was to completely scrap it and think of a new generation algorithm that could generate both realistic interiors and exteriors. After many different failed attempts and algorithms I ended up with one I think will do this pretty well making totally unique and realistic house.
Basically the generation works by starting with a random house rectangle. Then we take both the front and back sides of the house and recursively subdivide them while moving new segments in. This creates a house like border that seems to be pretty realistic.
High level view of a city and all the houses next to the roads.
Once we have the border we go along the sides we just subdivided and extrude new walls into the house. Then we go through all these new walls and raycast in both directions. With this information we shift the wall to create rooms that are as square as possible.
This is still more work to be done in this area, but it does generally make good looking interior layouts. After this we need to go through and break down some walls to make more interesting layouts and open areas, but I haven’t implemented this part just yet.
Now that we have the wall outlines the next step is to create a voxel grid for the house and intersect all the walls with it. With this grid we do a series of flood fills to determine the different rooms and what’s outside/inside. This information is really important for the next step and in the future will be used to place furniture and loot!
After setting up the grid we need to go through and create a bunch of doors and windows. I haven’t done any work on the actual door and window placement just yet so I’ll talk more about that in the next update, but it will probably do some sort of path finding to create all the doors and make sure the house is playable.
View of a generated house without the roof on the voxel grid. You can see that every room is a different color and the random door/window hole punching in action.
The only work I did do for the doors and windows was put in place the actual hole punching we need. Each voxel gets a bit of extra data to tell if there should be a hole in it. You can see in the screenshots all the random holes I created to test the system.
The final step is to use this voxel grid to create the actual wall mesh. We do this by checking every voxel in the grid and if it’s a wall it creates triangles on any side that it touches a voxel that isn’t a wall. Then we have some special logic for punching holes on top of that. I really like the way this voxel system turned out and I think it will be a really powerful base for all the building generation in Survive
Now the basic house walls are done we need to create the roof mesh. This is a little more difficult to get right because you can have sort of odd house layouts and it’s not a huge deal, but if you screw up the roof it just doesn’t look like a house. Because of that it will take a little more time and art assets before it starts to look good.
Screenshot showing a better view of roof generation. Will have connector meshes at intersections and a lot more polish, but you can get the idea.
That being said I think the base algorithm is good and once we get all the correct looking art in it will look like a house. So for the actual algorithm we start off by creating the main roof. To do this we find the skinniest part of the house and create a large roof across that. This creates a solid base that all the sub roofs can connect to.
Then we need to go and create the sub roofs. The way it works is similar to the interior wall generation. It goes through the subdivided front and back walls and creates a sub roof for every segment. This is then extended into the house until it’s attached to the main roof.
Same house with the roof cut off so you can see how the roof fits with the actual house.
This roof generation seems to do pretty well, but we won’t really know for sure until I start to add all the extra assets and polish that make the roof look like an actual roof. The large base shapes are there and should make some good looking houses once that other stuff is in. If not then we’ll just throw it out and try something else! The nature of these generation algorithms is about constantly trying stuff until it works and the generation pipeline we have now makes it really easy to do just that.
I’m super excited to finally start getting this stuff into the game, and the rate of stuff going in is going to start growing rapidly. With this we now have a fully functional generation pipeline which is the foundation and core of the entire game:
Continent Generation -> City Distribution -> Interstate Creation -> Main City Road Generation -> Neighborhood/Block Generation -> House/Building Placement -> House/Building Generation -> In-Game Streaming
It’s all working and flowing now it’s just a matter of improving the generation algorithms and integrating the art assets. The framework is there now it’s time for the really fun stuff!
I probably should have done a video for all of this, but in just a few weeks the houses are going to look significantly better so I’m holding off a bit longer. If there’s anything you guys want to see specifically in the video that I might not think of just let me know.
So that’s what I’ve been up to for the last month and boy was it an exciting one. The next update will probably(no promises) be sooner and more in the 2 week from now range because I would like these posts to be a little shorter and there’s just so much to talk about now! As always if you want to see frequent updates about the generation and sick screenshots/gifs go follow me on twitter