Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback Job System/Hybrid Renderer v2 showcase: Parametric Object Creation

Discussion in 'Graphics for ECS' started by Nyanpas, Dec 31, 2020.

  1. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    Greetings,
    For over one and a half year now in my time of spare, have I been, and am still, working on Parametric Object Creation. The goal is to be able to create or recreate everything possible in 3D with as little input parameters as possible based on domain knowledge and physical constraints. The reasons behind are many, but the most significant are ease of use, flexibility, and space saving. I want to have a greater creative output with less of the hassle. No prefabs involved.

    Since this has been happening over such a long period of time, I started it originally as a Monobehaviour-project just so I could get some results. However, as I started learning more about using the Job System for mesh generation, as well as all the new mesh data types etc. for this purpose, I decided to to try to upgrade from singlethreaded to multithreaded. So for the past few months I have been trying to get a hybrid DOTS/ECs-approximation to this, by at least leveraging the few functionalities I could understand and make use of to make it work (and render, lol).

    There's still a lot left to be done, but I had enough foresight to start using the math-library and Collections when I first started it, so it wasn't that conversionary difficult to start "translating" it into the Job System. The biggest challenge was (and still is, though) to handle the extreme variation of vertices and triangles being generated per object. However, I found that NativeLists inside the job provided me with a decent shortcut, even though I am sure there are infinite ways to do it a lot better. At least the performance is unprecedented. It generates 2-3 million vertices within a few frames (Jobs are spaced out as not to kill the CPU on lower-end hardware), compared to 30 seconds for much less on Monobehaviour (to be able to keep it within the frametime budget of 16.667ms).

    The video shows a little of what I have been able to do with it so far:
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,223
    Inside-out procedural generation where the generation conforms to an input in a realistic way is extremely challenging to do as well as it seems to be done here. This is impressive!
     
    charleshendry likes this.
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    Indeed, really nice work. And multiple wheels in cars did not dissapointed me :)
    Building staircases also very interesting feature. And well done.

    What about lift? Or at least lift shaft? Fly through was rather fast, so was unable to notice, if there is any.

    Does buildings use colliers too?
     
  4. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    Thank you for your feedbacc so far. Hopefully this is something that can be used by more than myself once I get to work a little more with it.

    There are no lifts or shafts yet, however they are easy to construct as they all follow a rather strict formula. The buildings have colliders too.
     
    Antypodish likes this.
  5. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    Here's another update to this. It now has multithreaded city generation, as well as a few more improvements overall:

     
    Sarkahn and Antypodish like this.
  6. jasons-novaleaf

    jasons-novaleaf

    Joined:
    Sep 13, 2012
    Posts:
    181
    @Nyanpas looks awesome. Do you have any links you could share to a newbie looking to get into DOTS based procedural mesh generation? The generating and efficient batched rendering of meshes is I think the first step I need to take.

    Also I was reading a bit on SharedComponents, so like they could share a bounding box. Any ideas on how to use that for culling/querying those entities? I bet it's not so hard to find out, but still, any pointers on where to start would be awesome.
     
  7. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    I am really not an expert on the subject here. This is still really early, and there are a lot of issues to solve with regards to data management and getting them to work efficiently in parallel. The DOTS-parts are simply copypasted from Unity's example projects online, but the generation code is my own custom made that I translated from a Coroutine into a parallel job (which isn't actually parallel yet, but runs on a separate worker thread at least).

    All culling etc. happens as part of what is built into Unity. I haven't done anything with that. It runs URP with custom shaders.

    The batching is something I am working on solving. It needs a load balance to be efficiently scaling across lower end systems, however the priority is lower. My main focus right now is to solve the data issues and make better generation.
     
  8. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    I'm currently working on turning this into a 3D-object generator for creative use. (This does not use the HybridRenderer, though.)

    Here's an example of a chair being generated:
    chairity.gif

    It's so fast that it generates a new mesh every time you edit it, (which still somehow was surprising to me).

    And here's the city again, generating 1661 buildings with a total of ~1 million vertices at under 16.667ms thanks to Burst and a few new lessons learned on how to use NativeStream with the new mesh-API:
    testenings9.gif
    This uses a custom mesh generation algorithm I created over the course of half a year last year because of self-isolating and not having to commute for 2 hours every day to work.