Search Unity

Townscaper

Discussion in 'General Discussion' started by HonoraryBob, Sep 4, 2020.

  1. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,214
    Anyone have any idea how "Townscaper" conforms building models to a random cell grid (see video below if you've never seen the game). At first I thought the walls were just being generated at runtime along cell boundaries; but the buildings and other objects are too detailed for that - some even have tiny benches, lights hanging from the bottoms of bridges, etc. Is it using a vertex shader to reshape each building section so it aligns with cell boundaries? Would that work?

     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    First thing I notice is that all the cells have four corners, regardless of their shape. There are distorted cells, sure, but it seems to be always four corners.

    With a four-corner cell you have a distorted square and then if you have a building model created in a straight square, you can convert its point coordinates into point coordinates within square. Meaning, a point will be marked as "it should be 0.25 between left and right wall, 0.6 between front and back wall, and 0.7 between cell top and bottom.Normals can be converted to the "cube space" as well, by being stored as a "point at small offset from the original one"

    Basically, an equivalent of a barycentric coordinates, only within the cube.

    Then you create a formula to distort the cube, and based on cube coordinates (say, U,V,W), compute world space position for any given point.

    And then after converting model into "cube space", you can distort it to match the shape of the cell it takes.

    This doesn't need to be done in a shader, by the way, it can be a dynamically generated mesh. Shader is only necessary if grid ochangges its shape over time.

    Does this make sense?

    Here's an example (I need a better program for drawing this stuff...)
    upload_2020-9-4_22-11-12.png
     
  3. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    611
    You can look through the twitter of the creator, Oskar Stålberg (@OskSta ). He's documented much of the development and I remember him talking about how he deformed the buildings (which is just as neginfinity said above btw)
     
    HonoraryBob likes this.
  4. MMatt

    MMatt

    Joined:
    Jul 18, 2012
    Posts:
    6
    xjjon likes this.