Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Feedback Wanted: Mesh scripting API improvements

Discussion in 'Graphics Experimental Previews' started by Aras, May 26, 2019.

  1. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    486
    Just send single float32 value and then extract bytes from that. This should be fairly simple on the shader side.
    new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 1)
     
  2. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    706
    Then I need to inform you that this is because you don't understand what you are talking about.

    Please don't reply to topics you don't fully understand, it just wastes everyone's times
     
  3. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    706
    I think I did try an equivalent of this but maybe I messed something up. Actually I probably need to send as you say and then interpret it with asuint... I'll give that a go.

    I feel like I'm missing something obvious since Color32 is basically 4 bytes and I was assuming that UInt8, 4 would be the same as sending a Color32 but I wasn't coming across examples showing using a Color32 directly in the mesh/shader
     
  4. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,237
    What I want to inform you is your information is very lagging. Your description is too hard to follow. And I suggest that the most descriptive and simplest is just post the whole code of the file you are doing so we can understand of what you are really trying to do

    I would suggest you should try to test your assumption about your vertex byte value. You might send just 4 vertex with only position and UV. And use UV as position to draw a quad, then use the position to output color instead

    If you input 64,64,64,64 and it give you a dark gray, its mean it was converted into 0.0-1.0
    But if it white, it mean it was a raw value, something like that
     
  5. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    706
    This got me on the right track thanks. I think something is still not quite right with uInt8 under the hood but sending data as UInt32, 1 instead got things going.

    I might have also just been tired and messed up the bit shifting shader side. This is what I did in the end for anyone else that might try something similar:


    Code (CSharp):
    1. uint texcoord        : TEXCOORD1;// << vertex struct              
    2.  
    3. uint value = v.texcoord;// << vertex shader
    4. o.vuv.x = value & 255;
    5. o.vuv.y = (value >> 8) & 255;
    6. o.vuv.z = (value >> 16) & 255;// I'm working with texture arrays and need 3 values
    It would be nicer to send it as 4 values instead of one though to avoid the bit shifting per vert but ah well
     
  6. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    267
    As far as I know, you have to do it this way. HLSL doesn't have any integer types smaller than 32 bits (unless you're on SM6.2, where you have access to 16-bit integers as well), so you need to provide smaller data types in 32-bit chunks that you mask out.
     
  7. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    706
    See this is where it confused me because that logic makes sense when you look at fixed vs half.

    But then why give us an option for bytes at all?

    I'm guessing that Unity is supposed to be interpreting it for us but something isn't working as expected (or I'm missing something obvious).

    I'm thinking the use case for this is the same as what I'm trying to achieve. You store the mesh as bytes, it transfers to the GPU as bytes so its a smaller/faster transfer, then the GPU expands to half etc to render.

    This is where if Unity provided more code samples/better documentation it would really help save time... ah well.
     
  8. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    Is there still no way to set bindPoses for skinned mesh via MeshData?
    Am I missing something?
    Sorry for the necro.
     
  9. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    267
    There is still currently no API for setting them without allocations. There is a no-alloc API for accessing the bind poses through a NativeArray, but the set API still requires a managed array.

    ...Or so I thought, but it looks like Unity 2023 does finally have an API for it: https://docs.unity3d.com/2023.1/Documentation/ScriptReference/Mesh.SetBindposes.html

    It is not part of MeshData though.
     
    Thaina and MaxEden like this.
  10. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    I'm not sure how Mesh class works internally in Unity, but I suppose both the MeshData approach and the Mesh.Set* methods just copy data from one buffer to another and the overhead is comparable.
    I hope it will be backported to LTS
    Thanks
     
  11. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,558
    Some platforms support lower precision, like when targeting mobile, the end shader code is not HLSL anymore and will map to GLSL lower precision values. So platform preprocessor conditions can become really important in these cases too.
     
    LaireonGames likes this.