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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

custom vertex format

Discussion in 'Shaders' started by Artial, Mar 17, 2009.

  1. Artial

    Artial

    Joined:
    Dec 27, 2008
    Posts:
    22
    Hello,

    I'm trying to use a custom vertex format with a secondary UV set.

    That's working fine with the fixed function passes. But when I define a new vertex format like this :

    Code (csharp):
    1. struct v2f {
    2.     V2F_POS_FOG;
    3.     LIGHTING_COORDS
    4.     float2  uv;
    5.     float2  uv2;
    6.     float3  normal;
    7.     float3  lightDir;
    8. };
    9. struct appdata_base2uvs {
    10.     float4 vertex : POSITION;
    11.     float3 normal : NORMAL;
    12.     float4 texcoord : TEXCOORD0;
    13.     float4 texcoordsec : TEXCOORD1;
    14. };
    15.  
    16. v2f vert (appdata_base2uvs v)
    17. {
    18.     v2f o;
    19.     PositionFog( v.vertex, o.pos, o.fog );
    20.     o.normal = v.normal;
    21.     o.uv = v.texcoord.xy;
    22.     o.uv2 = v.texcoordsec.xy;
    23.     o.lightDir = ObjSpaceLightDir( v.vertex );
    24.     TRANSFER_VERTEX_TO_FRAGMENT(o);
    25.     return o;
    26. }
    27.  
    CG complains about the vertex program : Vertex program 'vert': unknown input channel 'texcoordsec'.

    I'm pretty sure the vertex program is OK, it simply passes the secondary UV set to the output strcture.

    Is it possible that Unity produces shader programs for shadow rendering using the vertex program, and uses a different vertex delcaration that doesn't have a secondary TEXCOORD set ?
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Unity expects vertex inputs to be named like documented. Basically, name 2nd UV "texcoord1". You don't have to use semantics for vertex input structure (you can, but it's not necessary).

    Shadow rendering? If you mean shadow mapping, then they do not use 2nd UV set from the models (they don't need it). If you mean lightmapping, then yes, they do use 2nd UV set, but it's named like above. See built-in shaders for source code of lightmapped shaders.
     
  3. Artial

    Artial

    Joined:
    Dec 27, 2008
    Posts:
    22
    Thanks a lot, I didn't saw this part of the doc.

    (I meant the depth texture filling of the shadow mapping algo. )
     
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    This does not need 2nd UV set from the mesh. Yes, vertex shader generates more than one texture coordinate for the pixel shader, but it's computed from vertex position and some matrices -- it does not come from the mesh data.