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

Question Override RenderMesh mesh uvs

Discussion in 'Graphics for ECS' started by Zylkowski_a, Aug 17, 2020.

  1. Zylkowski_a

    Zylkowski_a

    Joined:
    Jul 27, 2019
    Posts:
    157
    Is it possible to override RenderMesh mesh uvs? I would like to do it in order to make dots animation system and other systems which operate on uvs.
     
  2. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    Nyanpas likes this.
  3. Zylkowski_a

    Zylkowski_a

    Joined:
    Jul 27, 2019
    Posts:
    157
    I know how to set mesh's uvs, the thing is how can I have per instance uv changes every few frames without big structural changes because of shared component changes.
     
  4. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    The mesh is just a reference. There are no structural changes on ECS side.
     
  5. Zylkowski_a

    Zylkowski_a

    Joined:
    Jul 27, 2019
    Posts:
    157
    Yes, that's the thing. I would like every entity to have component with just the uvs which override RenderMesh's mesh uvs for this particular entity. This way I can implement easy animation system which just changes uvs in the IComponentData
     
  6. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    What exactly are you trying to accomplish with this? It's almost certainly something that should be handled in a vertex shader not on the CPU. If it can't be done in a vertex shader, what about a compute shader?

    If it absolutely must be done on the CPU, one way would be 2 vertex streams, one of {position, normal} and another of {uv, tangent}. The meshes share the same first stream but have separate versions of the second stream. I'm not sure if this is even possible using the Mesh APIs, you might need to hack the render pipeline. It certainly supports multiple vertex streams, but I don't think the streams can be shared between meshes.

    Or, if there are only a few of these, copy the whole vertex data to each, with slight UV changes. However, you're still uploading data from the CPU to the GPU every frame, which can get slow.
     
    MNNoxMortem likes this.
  7. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    Do you need to change the UVs directly, or would changing an offset suffice? With an offset, you can submit a float2 per entity to the GPU rather than a float2 per vertex per entity. You can easily implement the texture offset in shader graph if you don't want to write shader code. And then you can specify a MaterialProperty IComponentData to have the HybridRenderer upload it per instance.
     
    bb8_1 likes this.
  8. Zylkowski_a

    Zylkowski_a

    Joined:
    Jul 27, 2019
    Posts:
    157
    I am using it in 2D game so I guess offset would suffice. You are sure it would work for changing uv in spritesheet texture?
     
  9. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    Depends on your implementation of your sprite sheet. But most likely, yes.