Announcement

Collapse
No announcement yet.

[TECH DEMO] Zergification

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [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


    Visual inspiration for Zerg infestation


    This is what i have at the moment.


    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.

    #2
    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

    Comment


      #3
      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.

      Comment


        #4
        Awesome cant wait for the infestation to begin

        Comment


          #5
          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

          Comment


            #6
            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.

            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.


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


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


            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


            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.


            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.


            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.


            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.

            Comment


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

              Comment


                #8
                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.



                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.


                Side type
                Side type property describes how tall the wall is on the sides.

                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 12*3*16=576 variations ... scary number, but we need to remember that not all combinations are valid.

                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.

                Comment


                  #9
                  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.

                  Comment


                    #10
                    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.

                    Comment


                      #11
                      Wow, looks really good so far!
                      Check out our game Arcus!

                      Comment


                        #12
                        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.

                        Comment


                          #13
                          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!

                          Comment


                            #14
                            Really impressive stuff!

                            Comment


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

                              Game Design - Photogrammetry - Programming
                              Tutorials · Twitter · Twitch

                              Comment

                              Working...
                              X