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

Multiple vertex streams

Discussion in 'Shaders' started by BearishSun, Nov 16, 2009.

  1. BearishSun

    BearishSun

    Joined:
    Dec 1, 2008
    Posts:
    175
    Hi,

    is it possible to have one shader receive two vertex position channels?

    Basically:
    Code (csharp):
    1. // vertex input: position, position
    2. struct appdata {
    3.     float4 position1;
    4.     float4 position2;
    5. };
    How would i send those positions from mesh to the shader?

    I need this because I'd like to try to implement morphing animation on the shader. I have very little experience with Unitys shaders so please help ;)

    Thanks
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you can send two float4 thats no problem.
    But there is no future vertex position only the current one as provided by the animation shader

    Your main work will be providing the target position etc to the shader towards which it interpolates in the near future
     
  3. BearishSun

    BearishSun

    Joined:
    Dec 1, 2008
    Posts:
    175
    That is my main concern yes.

    The position1 would be from the source mesh, and position2 would be the target mesh.

    In DirectX I could just set up a vertex declaration like this:
    Code (csharp):
    1. D3DVERTEXELEMENT9 MorphMeshDecl[] =
    2. {
    3. // 1st stream is for source mesh
    4. { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
    5. { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
    6. { 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
    7. // 2nd stream is for target mesh
    8. { 1, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 1 },
    9. { 1, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 1 },
    10. { 1, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
    11. D3DDECL_END()
    12. };
    and then just do SetStreamSource(0, &VBSource, ...), SetStreamSource(1, &VBTarget, ...).

    And render the scene, and the shader would get both the source and target position and then I could easily interpolate between the two.

    What i'm asking. Is there a way to duplicate this functionality in Unity?
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    You have no access to the engine source code unless you source license unity.

    Also, I'm unsure this would help that much even if it worked.
    The vertex interpolation of the target frame would have to be done first if you don't provide multiple static meshes (which most users likely would like to avoid), so your morph animation would actually be a multi pass vertex shader to first generate the target frame transformations (regular skin animation) and then do the morphing.
    Not sure if just using CPU won't be faster for quite some users and the cpu solution is already present as far as I'm aware.


    The easiest solution would be if the animation shader were changeable but I don't think its source is available
     
  5. BearishSun

    BearishSun

    Joined:
    Dec 1, 2008
    Posts:
    175
    The entire point would be to provide multiple static meshes. No skeletal animation would be used AT ALL. Sorry for not being clear on this.

    CPU solutions are extremely slow because I need to send the interpolated mesh to the video memory every frame. The vertex shader way would be many times faster, and that's why I need it.
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    I fear you either have to source license unity or wait until UT implements morphing then. No way for you to alter it.