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. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    Dismiss Notice

Using dynamic mesh system from Tiny in Jobs, in hybrid unity

Discussion in 'Project Tiny' started by caladluin, May 15, 2020.

  1. caladluin

    caladluin

    Joined:
    Jan 29, 2014
    Posts:
    25
    Hello!

    I have a project where we need a low end client that can run within the browser along with a higher end one running on the HDRP. We have some procedurally generated meshes, and would ideally want to use a single codebase/process for both systems. Is it possible to use DynamicMeshData/DynamicLitVertex/DynamicIndex with the hybrid renderer? And if so - how?

    On a related question, can these constructs be used in jobs on the job system, or only in single threaded environments?

    Thanks!
     
  2. v_vuk

    v_vuk

    Unity Technologies

    Joined:
    Jul 11, 2017
    Posts:
    35
    The Hybrid Renderer still uses UnityEngine Mesh objects, so you have to get the data into a Mesh. However, DynamicLitVertex is ultimately just a DynamicBuffer<DynamicLitVertex> -- and DynamicLitVertex is a pretty basic vertex. Your code can generate into a DynamicLitVertex on all targets, and then for the hybrid use case, you can update a Mesh using SetVertexBufferParams + SetVertexBufferData (see https://docs.unity3d.com/2020.1/Documentation/ScriptReference/Mesh.SetVertexBufferParams.html + https://docs.unity3d.com/2020.1/Documentation/ScriptReference/Mesh.SetVertexBufferData.html ) to efficiently set & upload that same data into a UnityEngine Mesh.

    You can write into a DynamicBuffer from a job; there are constructs that let you split up work of populating part of the buffer to different jobs too.
     
    tonialatalo likes this.
  3. v_vuk

    v_vuk

    Unity Technologies

    Joined:
    Jul 11, 2017
    Posts:
    35
    Though one caveat that I haven't checked yet -- SetVertexBuffer* has a limitation that the vertex streams must be in the order specified in the docs (see https://docs.unity3d.com/2020.1/Doc...ence/Rendering.VertexAttributeDescriptor.html the paragraph starting "Within each stream..."). You can omit some, but the ones that are present have to be in that order. If you don't, it will just... silently not work. :/ I'm not sure if DynamicLitVertex follows that order unfortunately. (If it doesn't, we can fix that.)
     
    cultureulterior likes this.
  4. caladluin

    caladluin

    Joined:
    Jan 29, 2014
    Posts:
    25
    Thanks! That gives me plenty to work with.