Search Unity

Would dots improve speed of mesh modification?

Discussion in 'Entity Component System' started by MCrafterzz, May 5, 2019.

  1. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    I'm totally new to DOTS and want to know when and can be used. So to start is mesh modification even possible with jobs? Secondly would it give a performance boost? I have only a few, sometimes just one object that should be modified. It loops through every vertex and moves them. As some meshes use contain quite many vertices, this step becomes a performance bottleneck. Thanks.
     
  2. james_unity988

    james_unity988

    Joined:
    Aug 10, 2018
    Posts:
    71
    It really depends on what exactly you're doing. Overall, the best way to manipulate meshes is via Compute Shaders. This enables you to make minor adjustments to meshes without re-uploading the whole thing each time. In this context, the Job system could be used to calculate what the changes are, and come up with a nice format of those changes and store them into a Compute Buffer, which is then passed to a Compute Shader.
     
  3. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    It's for this. It's used for the bridges. Every time the road is updated by for example the points are moved a bridge mesh is placed that is changed to match the road segment. If it starts with a width of 2 and ends with 3 then the bridge has to follow that. That's why I change all the vertices. So most of the time it won't update. The problem is that it's hard to work with it, moving points around etc when it lags a second behind. If the job system isn't right for this situation then it's totally fine. I just want to make it as optimized as possible to give people the best tool possible.
     
  4. james_unity988

    james_unity988

    Joined:
    Aug 10, 2018
    Posts:
    71
    All mesh modifications require data to be passed from the CPU to the GPU. The only way to reduce this is with a custom Compute Shader that knows how to take a small amount of data and make the modifications you need, otherwise you'll be re-uploading the whole mesh to the GPU each time. If calculating the mesh update is very intensive and you don't want to write the whole thing in a Compute Shader (because that could be really difficult to do, depending on the algorithm), then putting that logic into a Job is a good way to prevent hiccups in your frame rate.

    But then again, the Job system is notorious for constantly changing its API and having incompatible APIs from one version to the next. It could greatly increase the maintenance cost of your software over time if you plan on making it compatible with new releases.