Search Unity

How to Retain All UV1 Data in a Mesh When Using It in ParticleSystem?

Discussion in 'General Graphics' started by AhSai, Jan 20, 2022.

  1. AhSai

    AhSai

    Joined:
    Jun 25, 2017
    Posts:
    129
    Is there way to retain the data in mesh's UV1 when using ParticleSystem with "Mesh" Render Mode?

    My vertex shader struct looks like this:

    float4 vertex : POSITION;
    float3 normal : NORMAL;
    float2 uv : TEXCOORD0;
    float3 data : TEXCOORD1;


    The shader works fine when using with MeshRenderer, it only doesn't work when using it in a particle system.
    Does anyone know any solution to this?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    There are two options for this:

    You can use an instanced mesh particle system shader, in which case you have access to the original mesh data unmodified and get all of the per-particle data via instance data. Note that GPU instancing for particles is different than GPU instancing for "regular" shaders and requires a very custom setup.
    https://docs.unity3d.com/Manual/PartSysInstancing.html

    You can use custom vertex streams to get the
    xy
    values from
    TEXCOORD1
    , but I don't think you can get access to the
    z
    or
    w
    value, so you'd need to pack the data across
    TEXCOORD1
    and
    TEXCOORD2
    .
    upload_2022-1-21_14-8-52.png
    The above example takes the
    xy
    values from the original mesh's
    TEXCOORD1
    and packs it into the
    zw
    of
    TEXCOORD0
    of the mesh generated by the particle system. This does mean the shader used on a non-instanced mesh particle and used on a non-particle mesh cannot be the same.
     
    richardkettlewell and AhSai like this.
  3. AhSai

    AhSai

    Joined:
    Jun 25, 2017
    Posts:
    129
    Looks like there is no way to pack another float3 or float4 into a non-GPU instanced mesh particle without giving up normal, tangent, etc. :(
    upload_2022-1-24_1-44-37.png
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I think we presume float2 for uv’s here. You could submit a bug report and I could see if we can relax that restriction.
     
    bgolus likes this.
  5. AhSai

    AhSai

    Joined:
    Jun 25, 2017
    Posts:
    129
    A bug report was submitted.
    CASE 1397475
     
    richardkettlewell likes this.
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I think I partially misunderstood your forum post here. I thought you wanted to access float3 and float4 UV data, whereas we presume UVs are float2's in this particle code.

    However, your bug report seems to also report that you can only access the first 2 uv streams:
    As far as I'm aware, we expose 4 UV streams - you should be able to choose UV3 and UV4 in the Custom Vertex Streams Inspector UI?
     
  7. AhSai

    AhSai

    Joined:
    Jun 25, 2017
    Posts:
    129
    Yes, all 4 UV streams are exposed, but in Mesh render mode you can only choose a maximum of 2 UV streams at a time, so with UV1 already in use for texture coord, you cannot access any other data more than a float2 through the remainning UVs.
     
    richardkettlewell likes this.
  8. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Thanks for the clarification .. I’m not sure why that is. Hopefully an easy fix! Thanks again for the bug report!
     
  9. AhSai

    AhSai

    Joined:
    Jun 25, 2017
    Posts:
    129
    Thanks for the reply. It would also be nice if all UV streams can be selected as either .x .xy .xyz or .xyzw just like the one in Custom =D.
     
    richardkettlewell likes this.
  10. vickycl

    vickycl

    Unity Technologies

    Joined:
    Aug 23, 2018
    Posts:
    9
    Hi! We've looked at the bug in question and it seems that actually the error message is obsolete. We actually now support 4 input streams from meshes, so we'll update the message to reflect that. Thanks for reporting!
     
    richardkettlewell likes this.