I'm doing another low poly generation micro project. This time is skyscrapers. As you might have guessed, it's a baby sister project to my recent car generator. By the law of diminishing returns this ought to be less complicated and less interesting. Skyscrapers are just boxes after all. So I'm giving it no longer than the end of week. Will try to update often as it develops.

Starting with a sketch of form variations I'm planning to include:

There will again be some severe self-imposed limitations on the system to prevent the feature creep. The idea is to be able to generate whole skylines within a single MultiMeshInstance. So all buildings will be compositions of instances of a single mesh object. After meditating for 3 weeks at the top of the local mountain it came to me in a vision that this object should be a box 🙂

So I manually modeled this magical cube. It has a side length of exactly 1, pivot at the bottom, and each side's UVs cover the full 0-1 range:

Hopefully, it can self-replicate into all of the form variations from the sketch, using only linear transformations and a bit of vertex shader trickery.

This revolutionary technology will completely change the face of the world in the next 6 months, I'm telling you 😃

Development is moving forward at lightning speeds 🙂

The box stacking mechanism is in place now and the magic cube works as planned.

I introduced some basic parameters to the system. Firstly, every building's got its total x, y and z size. This size is vertically subdivided into towers. So the whole building can be a single tower or can have for example 2x3 towers. Towers can optionally vary in height.

Towers are further subdivided horizontally into 1 to 5 sections. Section height can be uniform or can increase or decrease in arithmetic progression as we go up the tower.

    xyz Great work for now, you may add also more sections for towers and add rotation in fixed step between each to make something like the Shanghai Tower in Lego

    • xyz replied to this.

      JusTiCe8 Thanks! Yeah rotation would be nice but I'd consider it a feature creep.
      In order to finish the project by the end of week, I have to keep my feature creep defense shields up at all times 😃
      But it's a good idea and I'll put it on the list for version 1.1.

      cars... , buildings...., add people and u have a procedural city generator 😉

      • xyz replied to this.

        DJM It's coming. It'll probably be just portraits though. Thinking of it I should also add a pack of player controlled godzillas to make things fun. Just not sure I have enough wits to make a low poly godzilla generator 😰

        I implemented magic cube's vertex shader. It gets 4 parameters via custom instance data and insets the upper vertices accordingly. The shader also takes care of properly altering slanted face normals. The magic cube can now be transmogrified into various prisms and pyramids. Those are placed as roofs on top of towers.
        An inset/outset base box is also inserted beneath towers, adding yet more to visual complexity.

        Looks like the greeble factor of generated designs is starting to increase. Everybody rejoice!

        By now I almost hear our friend @Erich_L saying: "But but @xyz, every construction engineer knows that you should start raising a building from its defining feature - the windows!"

        Fear not, here they come - the windows.

        I introduced 3 additional parameters to the system to describe the window pattern: margin, size and spacing. This is in practice actually 6 parameters because we need them for 2 dimensions. Here's a sketch I made earlier:

        Looks like windows are also boxes. However, it'd be borderline insane to instantiate a flattened cube for each and every window. The only reasonable option is drawing them from a pixel shader. It's almost like I knew having 0-1 UV space on each side of the magic cube would eventually come in handy.

        There's a problem though; we need to send 6 custom floats per instance to the shader but we only have 4, and all 4 are already taken by the roof parameters. It gets even worse. It would be visually really nice to have alternating window pattern between adjacent building sides. So in total that would be 16 parameters per instance. In utter desperation, I made a function that packs 4 floats into a single float. And, of course, its unpacking counterpart on the shader side. I'm putting it here as a comic relief:

        func pack4(a, b, c, d):
        	return float(int(d*100)*1000000 + int(c*100) * 10000 + int(b*100) * 100 + int(a*100))

        Don't show this to anyone with a CS degree. If you must show it, don't mention my name, just say GPT 2 beta wrote it.

        We can now send 16 normalized floats with 2 decimal places of precision. Possible precision glitches won't be noticeable because the window pattern is completely static.

        After some shenanigans with that irksome thing they call Math, the shader finally started doing its job. It accepts window parameters in world space and tries to nudge the desired window size to uniformly fill the available wall space.

        Since window parameters are specified in world space, the shader automatically adapts to any size/proportion of the box, keeping the window size as close as possible to input values.

        To use the immortal words of a well known contemporary prophet: It just works! [cue that Fleetwood Mac hit song from the 80s]

        A small vegetational intermezzo before I start putting it all together.
        I thought sprinkling some trees and bushes around buildings may look nice.
        So this is a hexagonal cylinder with 3 horizontal edge loops that can be multi instanced and formed into various tree forms. The reshaping again happens entirely in the vertex shader using 7 per-instance parameters.

          xyz I just thought of suggesting that last time, and don't forget the roads !
          Then trashcans, traffic lights, sidewalks, crosswalks, road signs, bridges, tunnels, ... you won't get any rest any time soon 😃

          So all of the above stuff is now put together. Intensity of windows mask is additionally randomized per window using building's world position as a seed. This nicely breaks the pattern uniformity and makes buildings look a bit more alive.



          The only thing that's now left to do is to generate a bunch of them at the same time to see if they work well together as a skyline.

          this is crazy good

          Then you just need to put a form on a website where user can put their request like "I want a building like AAA or BBB with plenty of windows and some trees around" and they get one in a few seconds ready to be use in any game/engine, you just have to pretend it's made by a so called AI, then charge a few bucks.
          Soon you'll get rich 🙂.

          I'm upset by the time I see this you're pretty much almost done with it! Similar to previously suggesting to start with wheels, in this experiment I would have suggested with starting with columns. x by x columns with a bool for whether columns also generate on the exterior. You could then procedurally generate that which inhabits or does not inhabit the structure. A cuboid could be an empty space, a room with n windows, some kind of entrance on level 1 or hold some kind of roof equipment on level max. If level n+1 is empty space, level n could hold some decoration on its top. A building with empty cuboids on level one should create some really interesting low-poly structures.

          I added the fire emoji for this thread specifically.

            The really impressive thing is how fast you did that. I'd probably have about 10 lines of code in that time. Looks really good for background kind of objects, but the trees limit it to kind of extreme low poly. They don't look like that even at a distance. I like low poly games, though.

            Guys, thanks for the kind comments.
            I'll see if I can make a decent looking skyline scene with this and then wrap it up for now, as planned.

            @DJM Thanks! Glad you like it.

            @JusTiCe8 Makes me think... are we suddenly moving from the era of human-wannabe robots to the era of robot-wannabe humans 😃

            @Erich_L That sounds interesting. It may lead to more sci-fi looking structures. I'll note it down for future experimentation.

            @cybereality I've noticed it. It's a cool emoji.

            @fire7side Thanks! Yeah the trees here are just an afterthought. The deadline was short and I focused mostly on buildings themselves.

            cybereality I love the emoji, and I'm going to do my best to use it in the most inappropriate places.

            • xyz replied to this.