Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

World Building [RELEASED] CityGen3D | Procedural city generation from map data

Discussion in 'Tools In Progress' started by CityGen3D, Jan 28, 2018.

  1. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    111
    One small QoL feature I'd like to suggest would be an exposed field (a button would be better, if there's a Unity function to allow for focus selecting a different object in the hierarchy from a custom editor; I've not looked into that before) on the Plot script (perhaps grouped with the Rebuild options) which will link back to the associated MapBuilding object in the hierarchy. Potentially the same feature could be handy for other MapX types as well, such as Roads, Features, Trees, Entities etc.

    This would allow users to identify a building in the 3D scene that needs changing, and then be able to select focus back to the original MapBuilding to tweak the height or polygon nodes before rebuilding. Currently it's visually difficult to start with your 3D building and then try to identify the corresponding 2D polygon back in Map view, because you need to mentally translate the 3D appearance of the scene back to 2D while trying to remember the position, and then when trying to focus select you can end up pixel-hunt clicking all manner of other objects.
     
    CityGen3D likes this.
  2. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Great, I'm glad to hear it!

    In most cases we just want the Clear to be run automatically, so I'll probably add in an Auto Clear toggle which is on by default and just runs the Clear function when you click Process.
    This should help with usability, as the onus won't be on you to do it.

    Then if you don't want to Clear it automatically (eg because you want to Process buildings for same location having previously processed everything else), you would just uncheck this Auto Clear checkbox and set the Filter accordingly before clicking Process.

    So this will make the default workflow work as intended without the need to Clear, but give people flexibility incase they specifically don't want to Clear.

    I will look into this a bit more and perhaps drop this in for v1.01 if it makes sense when I try it out.
     
  3. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Yes, I think having an easy way to jump between 2D object and the corresponding 3D object (and vice-versa) makes a lot of sense.
    I think it's been requested at least once before, but I never got round to it before v1.0 submission. But this is high on my list to look at now, so hopefully won't have to wait too long for that :)
     
  4. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    111
    By the way I've been mucking about with some shader experiments recently. You may have noticed the Facade shader occasionally has some jagged edge artifacts in places where the displacement gets pushed in or out:

    2020-07-26 16_30_00.png

    These can be reduced somewhat without adjusting the shader by passing the height map texture through a "Field Blur" or similar in Photoshop:

    2020-07-26 16_30_17.png

    To fix the stretching would probably take some mucking about with UVs and is in the too-hard basket, but the jaggies were the worst offenders and good to get rid of.

    Here's the same spot with an Amplify version of the facade shader. Amplify recently added HDRP/URP support for their Tessellation function, which was the main reason I was looking into it, since as far as I'm aware, Shader Graph doesn't support tessellation yet. Wireframes are on to show the tessellation:

    2020-07-26 16_38_51.png

    I'm pretty sure they're using the exact same code for edge cull from the Unity docs that you're using in the Facade shader, and the wireframe on yours looked almost identical, so no apparent differences there. But hopefully that node in Amplify would allow for HDRP versions of the shader with minimal work.

    Finally, I did a bit of tinkering in regular shader code with a copy of your Facade shader with the goal of adding a mask texture (basically black areas to turn off tessellation, white to keep it on) and got it to this point:

    2020-07-26 16_46_37.png

    The windows were masked white, so it has attempted to only tessellate those chunks of the larger tris, and you can see where the walls with just brick are largely left alone. No idea if it actually saves any performance or not, and obviously the finer detail such as brick grout heights would get ignored, but I thought it was cool.
     
    CityGen3D likes this.
  5. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    I'm getting nervous. I started processing sixth group of 4X4 terrains at about 7:30 this morning and Unity3D appeared to stop responding at about 12:30 this afternoon. I thought that clearing old data before processing new data worked.
     
  6. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    This is brilliant! It was on my todo list to try and improve the materials to reduce the jagged triangles, and it looks like this could be a really good fix.

    I’m revisiting the custom shaders anyway at the moment to provide HDRP versions, so this is something I can look at in more detail too.

    Thanks so much for the info!
     
    chmodseven likes this.
  7. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    I suspect you aren’t unloading scenes from memory after they have been created, before going on to create another group of terrains.

    Once your first group of terrains have been fully created and saved. You can safely unload them before moving onto an adjacent location.

    If you don’t do this you will inevitably run out of memory eventually, which is why I think you are seeing degrading performance over time (until Unity falls over).

    The next video tutorial will show the intended workflow for creating very large multi-terrain environments in a bit more detail, so hopefully that will help clear up any confusion.
     
    Last edited: Jul 26, 2020
  8. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    Can you lower the "Landscape xxx" text so that it doesn't block the "yyy FPS" text? Can you create splatmap materials for water?
     
  9. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Sure I'll take a look at that.
    In the meantime you can remove the FPS display by disabling the component on the Camera child object of the FreeCam.


    There's a known issue with water generation in v1.0 which results in the water planes not being created in some instances. This should be fixed for v1.01.

    But when it's working correctly (as it does in West Hendon demo location in current release), you can see water is basically done in two stages.
    You can decide the river/sea bed texture on Generator-SplatMap panel, just as you can with any other terrain surface type.
    By default, ocean surfaces are textured as sand, and river/lake surfaces are textured as mud.

    The actual water is a generated mesh plane in the shape of the body of water.
    You can have different configs for different water types (see Generator-Water panel) and you manage the settings in more detail through the prefab's Inspector.
    So you have complete control over what shader/textures are used, through the prefab.

    Therefore, if you want to use a third party water shader you can do that either by setting up the prefab in advance before generation, or just dragging an appropriate material onto the water mesh afterwards. I've used Aquas before without issue.

    I'm also looking at integration with River Auto Material (RAM) for improved river/stream rendering.
     
  10. overthrowrobotics

    overthrowrobotics

    Joined:
    Jun 19, 2015
    Posts:
    47
    I have Road Architect partially working. It's reading the data from CityGen API and creating the roads. I am not doing intersections yet. I'll work on that over the next few days. Road Architect can be downloaded from https://github.com/embeddedt/RoadArchitect

    My script is at:
    https://github.com/cjonesy20/Unity_CityGenerator/blob/master/InsertRoad2.cs

    This adds two new menu items in Unity Editor to Road Architect. Add CityGen Roads adds the roads. Some roads are a little below the terrain, maybe smoothing terrain for the roads further would help? The other menu item is called OSM Tags. It just prints the Key:Value pairs for the OSM tags. That should be able to be used to further refine the roads for getting the lane makers correct (which lanes are right turn, left turn, etc). Feel free to do whatever you want with the code. I'll continue to update it as I make progress.
     
    CityGen3D, chmodseven and hopeful like this.
  11. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Great work! Thanks for sharing :)

    Note to everyone that this script will only work after next update of CityGen3D is released (v1.01), which includes an improved GetPositions function for roads.
    This should be available early next month.
     
    Last edited: Jul 30, 2020
  12. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    111
    Hi Richard,

    I found this parallax/self-occlusion shader online today and plugged it in in place of Facade, and it gives pretty comparable results visually, adds a semblance of rudimentary AO, and manages to avoid the heavy tessellation cost (my FPS increased by about 3x, and that was just from changing one mat, not even all of the ones using Facade). There's a few funky issues such as when you get too close or when it's in shadow, but you can see the potential there at least in terms of performance if those issues can be tweaked out somehow.

    https://github.com/amsXYZ/POM

    2020-07-31 00_22_21.png

    It'd probably take me a day to puzzle through the shader code to understand what it's doing, so there's not much I can tell you about how it works, but I thought I'd pass it on as it might be worth a squiz. Maybe someone with a bit of shader skill can figure out how to convert the frag into a more modern PBR surf shader and get the rest of the maps in. Anyway, there you go.
     
    overthrowrobotics and CityGen3D like this.
  13. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Thanks for the heads up. I’ll take a look at this.

    I did play around with parallax shaders, but had problems with the heightmapping directions with the atlased materials, so ended up going the way of tessellation.

    But at first glance this does look good and doesn’t seem to have this problem, so worth further investigation for sure.
     
  14. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    111
    I've finally worked out some of the kinks I had left regarding one of my end goals with all that StreetView stuff:

    2020-08-01 17_38_28.png

    I can now push a button after grabbing the panorama, and the viewer will raycast to every visible vertex on the building and attempt to assess the real world color at that point using the panorama image for reference. You can see on the right where there's a kind of histogram of colors (there are counts too, just not serialized in the list).

    I'm not entirely sure what I'll be doing with this data just yet. Most likely I'll just end up using it to automate choosing from a selection of facade materials based on closest fuzzy match to colors, to override the ones the blueprint height logic chooses and get closer to real world visuals. But depending on how fine-grained of a point cloud I can derive, there may even be potential for feature derivation of window positions and the like. It's a bit of a stretch but I can even see potential for machine learning using ML agents to drive things further.

    Anyway, just thought I'd share my latest tinker.
     
  15. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Loving your work! Thanks for sharing :)
     
  16. overthrowrobotics

    overthrowrobotics

    Joined:
    Jun 19, 2015
    Posts:
    47
    One idea I've thought about is to semantically segment the image to identify pixels that are building vs sky vs road, etc. Then take those segmented pixels for the building and run it through a classifier which returns brick, glass, siding, wood, concrete, etc. Maybe you could do a two stage segmentation where you segment first for building and then sub-segment for door, window, sign, etc. Then detect the type of door, type of window, etc. Then you drop in that facade for that piece from multiple door or window options.

    I played with using the Google StreetView API to extract images. I was thinking of classifying Stop signs and then dropping in prefabs of their location. One challenge is to make sure you're properly localizing yourself between the CityGen Map and Street View. How can we automatically match up the buildings?
     
  17. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    This has been implemented for buildings in v1.01, which will be out later this month.
    If feedback is good I’ll roll out similar behaviour for other map objects.
     
  18. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    111
    Yeah that's sort of where I was trying to go with it, although the more I look into it, the more too-hard-basket it becomes. The main issue, as you suggested, is lining up the position and rotation (and I suspect also the panorama fisheye stitching and maybe even the lat/long conversion formula) so that the 3D view in Unity can localize closely enough to the panorama view on a pixel by pixel basis.

    So far in my prototypes, I can have the building models align approximately enough to the StreetView that you can look at it visually and say "yeah that's the same place", but with nowhere near sufficient accuracy to be able to extract a decent outline hull from the image to pass through an ML or other type of image segmenting pass. Some panoramas seem to align reasonably closely while others can have offset errors of up to a quarter of the image out of alignment. So I'm starting to come to the conclusion that this StreetView syncing may only be useful for manual eyeballing of scene-to-real-world, to allow for manual scene enhancement after generation or perhaps some low-grained facade selection automation (with allowance for high likelihood of error - see example "per-vertex color estimation" image below, with a distinct lack of expected orangey-brown color balls). At this point I don't see a way for the alignment accuracy issues to be overcome to the point where detailed segmenting of the sort you've described could be automated.

    2020-08-02 09_43_35.png

    That said, I suppose there's some potential for coming at it from the other direction more along the lines of what you suggested, of starting with the image, breaking that down into segments, and then figuring out the mapping back to the model at the end. Rather than what I was trying to do, in mapping the model verts to the image first, which in theory would allow for a copy-paste of the image slapped right onto the UVs, as wasteful as that would be. I've only got a little ML and no computer vision experience at all, so I'm probably not going to go much further with these experiments, but if you do decide to take it on and make any progress along those lines then I'd love to see the results.

    You'd think Google with all their billions and hundreds of people in the Maps department would have nailed this stuff for us by now. :D
     
  19. GamePyro-com

    GamePyro-com

    Joined:
    Jul 28, 2018
    Posts:
    195


    How you done this?

    upload_2020-8-29_2-16-15.png


    It looks like Google Earth / Maps in Unity


    Can edit the buildings?
    Etc
     
  20. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    111
    That’s a reference 3D textured model I was using that I got from the City of Melbourne open government data. They generated it from a LiDAR point cloud and it looks good from a distance but terrible up close - uneven mesh polys and grainy low def texture. So yes, quite similar to Google Earth rips that can be done with render doc. They’re FBX so could be edited in Unity via PolyBuilder but it wouldn’t be worth it.

    I was using these reference models mostly to compare to the placement and visual output of CityGen3D, as a way of finding ways of refining the latter. It’s the same approach to why I made that StreetView extension, looking for ways to automate just a bit closer to real world matching.
     
  21. atul20032006

    atul20032006

    Joined:
    Jan 6, 2019
    Posts:
    4
    Great
     
    CityGen3D likes this.
  22. SimonStojanovski

    SimonStojanovski

    Joined:
    Aug 24, 2017
    Posts:
    11
    We are using Citygen3d for our open world game, works great for now but we have one little problem that it's kinda hard not to notice and that is the way the road sidewalk connects to the terrain.
    Is it possible to use a custom road/sidewalk profile or model to fix this issue?
    I have attached a picture with the problem and possible solution to our problem.
     

    Attached Files:

    CityGen3D likes this.
  23. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Hi,

    Thanks, I'm happy to hear it's working well for you :)

    One of the things on my (very long!) list of things to do is to experiment a bit with different sidewalks & curbs, and perhaps expose some more settings for this on the Generator interface.
    For example, I want to look at trying different curb design more suitable for a racing track and things like that.

    For now it should be possible to switch out the sidewalk meshes for slightly different ones via the Inspector.

    Locate the Highways child object of the Generator in your Hierarchy and locate the existing sidewalk prefabs in the project. If you take a look at how they are setup it should be possible to replace them.

    Then when you Generate Highways it will just reference whatever is assigned to the Sidewalk Prefabs and extrude them.
    (There should always be two prefabs in the array to handle both orientations).

    An obvious limitation at the moment is that you can only have one pair of sidewalks for all instances. It would naturally be better to have more flexibility so you could automatically use different meshes and sidewalk heights in different situations.

    I'd be interested to hear how you get on so I can address any issues you may face in future updates.

    sidewalk_edit.png
     
    SimonStojanovski likes this.
  24. SimonStojanovski

    SimonStojanovski

    Joined:
    Aug 24, 2017
    Posts:
    11
    Thank you for the fast reply, I will try it and see how it goes. We are currently using Citygen3D for road networks and terrain generation based on our city and because it's a FPS we needed this little details working, super glad you have a solution for it :)

     
    DJ_Design, StevenPicard and CityGen3D like this.
  25. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Love the screenshot, thanks for sharing! I will follow the project with interest :)
     
    Xiperius likes this.
  26. jouany

    jouany

    Joined:
    Aug 4, 2018
    Posts:
    19
    Hello,
    I was trying to get racing track from Nurburgring and despite all details seems to appear on the 2D then on the 3D level generated, the main race road that is pink "highway" that is missing. See Screenshot.
    I have checked a second race track close from highway and I notice this is not the same pink color. But none of the highway or the racing track appear in 2D view either
    Do you see any Reason ? This is a new level with Nothing else loaded.
    Thank you
     

    Attached Files:

    Last edited: Oct 2, 2020
  27. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Hi,

    This is most likely because the key/value XML tag used to describe the OSM way is not being looked for by default.
    You can easily add your own via the different tabs on Data Window.

    When something appears to be missing, just query it on OSM website to find an appropriate tag and include it on the relevant tab in Data window.
    Then when you Process map again, it should appear as an object on 2D map.

    nurburgring.png

    race_track.png

    Please let me know how you get on.
     
  28. jouany

    jouany

    Joined:
    Aug 4, 2018
    Posts:
    19
    Thank you for your super fast answer. That was the reason why.
     

    Attached Files:

    CityGen3D likes this.
  29. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Great stuff. That's another chapter I need to write in the manual one day! :)

    You may want to play around with the road width, see what feels right for your project.
    (I think in reality it's about 15 metre width on average, so the default of 3.5 will feel very narrow once generated in 3D).
     
  30. theonerm2_unity

    theonerm2_unity

    Joined:
    Sep 7, 2018
    Posts:
    130
    upload_2020-10-24_3-4-59.png

    My scene looks decent so far I think. Once I get some high quality roadside assets added in it'll look a lot better.
     
    StevenPicard and CityGen3D like this.
  31. SimonStojanovski

    SimonStojanovski

    Joined:
    Aug 24, 2017
    Posts:
    11
    Hello again with a question :)
    I am trying to add additional Parking shapes on the generated map and when I generate Highways it only generates the sidewalk around the old parking shapes. On the new ones it just changes the texture of the terrain and adds the imprint.
    But if I take an old Parking shape and duplicate it and change it's location it will work as intended. Any idea why it won't generate sidewalk mesh for the custom placed Parking shapes?
     
    CityGen3D likes this.
  32. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Thanks for reporting this. I have managed to reproduce the problem, so will aim to get a fix in shortly.

    I think this issue is it thinks the origin of your custom shape is at Unity world origin and not the transform position, so you may see unwanted sidewalk meshes around [0,0,0] world space as a result of this.
     
    SimonStojanovski likes this.
  33. ycq2012

    ycq2012

    Joined:
    Sep 25, 2020
    Posts:
    3
    Hello, we try to develop a real-world system for very huge terrain, hoping the detailed result as possible. It should need support from the terrain streaming. Could you please tell me if the CityGen3D can meet our requirement?
     
    CityGen3D likes this.
  34. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Thanks for your interest in the tool.

    Yes, you can create large environments in the Editor and load them on demand at run-time.
    This video tutorial explains some of the considerations and workflow:



    Feel free to drop me an email if you want to talk about the specifics of your project in more detail.
     
  35. ycq2012

    ycq2012

    Joined:
    Sep 25, 2020
    Posts:
    3
  36. unity_ndata

    unity_ndata

    Joined:
    Nov 5, 2020
    Posts:
    1
    hello, can we use geojson data to draw map in unity3d?
    does CityGen3D support geojson file?
    anyone has idea about to read geojson file and draw 2d and 3d map.
     
  37. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    111
    We had some discussion about this on the Discord. I've shared a script I wrote, that you can have a play with, which can be used to construct polys for building footprints:

    https://pastebin.com/caSkw63U

    Please use at own risk and only if you're confident, as I can't provide any sort of support for this script. You'll need to install the GeoJSON.Net nuget package in your Plugins to make it work, of course, and Newtonsoft.Json if it's not already there.
     
    CityGen3D likes this.
  38. kintovt

    kintovt

    Joined:
    Jan 5, 2017
    Posts:
    13
    Hi! Can I somehow get the camera lat and long coordinates in runtime?
     
  39. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680