[TECH DEMO] Zergification

Zergification tech demo is my final year project. The goal of the demo is to dynamically generate fantasy town and then slowly infest it with Zerg turning everything in to giant organic mess.

Visual inspiration for the town
http://s6.postimg.org/wzjvewbb1/Town_inspiration.jpg

Visual inspiration for Zerg infestation
http://s6.postimg.org/ey0qh3ha5/Zerg_inspiration.jpg

This is what i have at the moment.
https://youtube.com/watch?v=EKDj39WtZ_M

At the current stage tech demo can:
Generate of town layout
Construct walls using modular peaces
Construct roads and ramps using modular pieces
Construct cliff walls using modular peaces
Place correct size buildings

Now it is time to start making actual models.

I am super interested in how you generate the town.

Do you plan on releasing the town generator as a plugin on the marketplace or for free?

Just curious :slight_smile:

At the moment my time schedule is extremely tight, so I have no plans to put this on the marketplace. However I’m more than happy to answer any questions. Also some time in the future i’m planing to write more in depth post about generation and some tricks I had to come up with.

Awesome cant wait for the infestation to begin

Town generation

Time to explain in depth how I’m actually generating the town.

My initial plan was to put all the generation code in the single world_builder class, however, quite soon I realized that it takes a lot of time to compile a class that big and I’ll need to recompile it all the time. Because of that I have split the code into five classes:
• Builder_city
• Builder_wall
• Builder_buildings
• Builder_roads
• Builder_edges

Builder_city
The goal of this class is to create a smart looking town layout, save it to multiple 2d arrays and send it to the next builder class.

Step 1: Randomize grid size
I start by randomizing the size of the grids that i’m going to be using. This by changing variables at this stage I can easily change size and aspect ratio of the town I want to generate.

Step 2: Create terrain shape
Terrain only exist in the town, so by creating shapes of the terrain we are creating town shape. I do this by drawing 5 rectangles. First one is created in the middle of the grid and do not touch any of the grid the edges. Another 4 start at the middle square and are touching one of the grid edges.

http://s6.postimg.org/in3spyr0h/Generation_animation.gif

When I’m generating bottom square I’m saving its middle point, I’ll use it later to create a gate.

Step 3: Generate the height of the terrain
First of all I generate hill shape by cutting terrain horizontally and vertically.

http://s6.postimg.org/dm1glppvl/Generation_animation2.gif

Then I select few random square areas and set their values to the average:

http://s6.postimg.org/tybibg475/Generation_animation3.gif

Finally, I take care of the location next to the gate:

http://s6.postimg.org/a4zeiqqtd/Generation_animation4.gif

Step 4: Create wall array
Creating wall array is really easy. Just copy terrain array and apply this logic for every cell:
If (All surrounding cells empty) -> set cell empty
Else if (None of the surrounding cells are empty) -> set cell empty
Else -> set cell full

http://s6.postimg.org/gl8d8tzcx/Generation_animation5.gif

Step 5: Create road array
I start road creation by adding road seeds. In essence road seed is just a point with direction and length. I add them in the middle of the squares I used to create terrain shape, gate location and a few random areas. Then I create roads out of them, road stops if it reaches a wall or another road.

http://s6.postimg.org/bb3ehjf41/Generation_animation6.gif

Then it is time to break large empty areas. If the cell is empty and three cells to the left is empty or three cells down is empty set cell to full.

http://s6.postimg.org/4m1gf9j5t/Generation_animation7.gif

Next I check for for narrow areas, where is wall is on one side and cliff on the other. Places like that should always be a road.

Finally, I check for cells that have different state than non diagonal surrounding cells and share state with at least one diagonal surrounding cells.

http://s6.postimg.org/vxwpglnwh/Generation_animation8.gif

Step 6: Create buildings array
Building array is quite simple, it is an inverted road array.

Step 7: Spawn wall builder and send all data to it.

Obviously, no one could live in town with the layout like that, but it does not have to be logical, it just has to look like it. And there are many ways how to make it look logical, even when it is not.

Next time I’m going to write a bit more about wall_builder.

This is awesome… and already a very useful resource for those of us learning procedural generation and so on :slight_smile: Keep it up! The town already looks badass.

Outer wall generation

When starting to develop a complex system I like to start with a list of limitations that the system is going to have. You can use every limitation to your advantage.

Limitation 1: Walls have no T or X junctions.
Limitation 2: Walls always for closed loop.
Limitation 3: Walls can only placed on the flat surface.

What are the cons of these limitations ?
The general shape of the walls lacks variety.
Some of the popular patterns that are used in the real world can not be used.

Pros of the limitations?
Drastically reduces the number of modular pieces.
It is very easy to trace along the wall (it will solve a lot of problems in the future)

Now we can start thinking about modularity of the assets. Every wall piece can be described with 3 properties: top type, front type and side type.

Top type
Top type property describes the shape of the peace from top view. Red part of the wall is always facing outside.
http://s6.postimg.org/k2x2nr1vh/Wall_1.jpg
http://s6.postimg.org/95vqyzf3x/Wall_2.jpg

Front type
Front type property describes where the piece is vertically. If the wall is taller than 3 pieces, middle pieces can be duplicated without breaking modularity.
http://s6.postimg.org/fkurvnltp/Wall_3.jpg

Side type
Side type property describes how tall the wall is on the sides.
http://s6.postimg.org/bmkzswx19/Wall_4.jpg
Some of you might notice that there are no “one lower” condition. I treat it the same way as “same level”, because next to it is always a piece with “one higher” condition and i made sure they would connect seamlessly.

So we have 12316=576 variations … scary number, but we need to remember that not all combinations are valid.
http://s6.postimg.org/heppdsw8t/Wall_5.jpg
Now we have 12(16+4+1)=252 variations … still kind of scary. But 252 conditions do not mean 252 modular pieces, we can reuse same meshes and simply rotate and/or flip them. With that in mind it brings us down to 3(10+3+1)=42. Still a lot, but at the moment I could not come up with the method to reduce this number. Later I have found some ways to do it and I used that for road generation. I’ll explain them when I’ll be talking about roads.

Builder_wall
The goal of this class is to take wall array and create a wall out of modular pieces.

Step 1: Randomizing wall height
In order to create a more interesting silhouette I select random areas of the wall and add some height to them.

Step 2: Calculating “Top type” property
At first I take wall array and read it from left to right starting with top left corner. First not empty cell is always L4 type. Then i trace the wall from that point(clockwise), always checking which wall is previous and next cell. This way i can identify type of every piece in the wall. For example I3 type always have previous cell on the left and next on the right.

Step 3: Spawn gate
I grab gate position from city_builder, spawn gate into the world, change height of the wall in the place where it connects to the gate, mark cells that overlap with a gate as “created”.

Step 4: Spawn special pieces
In the video that I posted this was not implemented, but in the new version I’m replacing some of the areas of the wall with special peaces, like guard towers at the corners. The procedure is identical to spawning gates, except for the location. I get the location for the special peaces by tracing wall and checking for patterns in “top type” property. For example, if I find the sequence I3, I3, L1, I4, I4, I know that it is the corner and I replace it with the guard tower.

Step 5: Spawn generic pieces
And finally go through the wall array one last time, checking for the cells not marked as “created” and spawn mesh based on 3 properties described earlier.

Step 6: Spawn building builder and send all relevant data to it

Next time I’ll talk a bit more about how and where i spawn buildings. Also hopefully by then i’ll have new video that will show you some more features.

If you have any questions or you want me to explain something in more detail, don’t hesitate to ask.

As promised, new video.

New features:
Some new meshes
Few new materials
Sand generation system
Different districts
System for special wall pieces

And as always, nothing is final, nothing is finished.

Wow, looks really good so far!

I’m not dead !

This is the video of the latest build. Still working on procedural generation, making assets takes a lot of time.

If you are interested in any specific features, ask, I can make quick tutorial that would explain it.

I’ve just stumbled on this thread and it’s really inspiring. I made a really rough and ready village blueprint for a project a few months ago which built a circular wall with a gate and towers and places buildings inside, but this knocks the spots off that. Are you doing it all in blueprints? How is performance? My villages we supposed to be on a small scale and there were about 20 of them in the scene but I never managed to get instancing working. Also - my villages had to explode when huge boulders were dropped on them.

How do you think this would scale for very large cities etc. Could you generate a much larger initial shape? What about building many towns and joining them so any common edges or overlaps were blended together?

I’ll be watching this with great interest - it’s great to see stuff like this come together and the thought processes behind it.

Thanks!

Really impressive stuff!

This is looking really nice. I would love to the a game using this system. All the details are awesome :slight_smile:

• Are you doing it all in blueprints?
Yes I am.

• How is performance?
It takes about two seconds to generate new town. To feel performance drop I need to increase town size 4 times. At the moment I’m not using instances meshes, however, most of my meshes are really low poly and I reuse a lot of same textures.
Everything in my project is data driven, I’m not using collision checks, ray casts or anything like that. Instead, I generate a set of data and then use builder classes to build, walls, buildings, roads and so on.

• Could you generate a much larger initial shape?
Yes, by changing value of the single variable. However, my macro variation system does not take that into account, so if I drastically increase town size they start to look alike.

• What about building many towns and joining them so any common edges or overlaps were blended together?
Yes, my framework supports that. At the moment what does not look very good, I would need to adjust some stuff if I would like to do that properly.

http://s6.postimg.org/cmfaqbv7h/Large_town.jpg

http://s6.postimg.org/kdw0ovzct/Multiple_towns.jpg

@Vaidas This is looking great! Are You going to make some king of mini game after that? (Give a character flamethrower to burn the infest, maybe with some ‘specials’ puckups)
Anyway, even as a tech demo this is looking great! I’m in love of everything procedurally generated.

I’m not going to resist making game out of this in the end, but that is far far in the future.
I have multiple ideas for it and in most of them you are controlling the Zerg and controlling everything from the top view.

Man, I really hope you consider putting up what you have now on the marketplace as I would happily pay money to get a good look at how you handle all the generation in blueprints. I am at the moment using streamed levels loading in and out to create a procedural workflow but I would kill to see how you have set it all up haha.

Keep going on, man! It’s really great stuff.