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

TRANSFER_VERTEX_TO_FRAGMENT mobile problem

Discussion in 'Shaders' started by DC_Rich, Feb 4, 2015.

  1. DC_Rich

    DC_Rich

    Joined:
    Feb 4, 2015
    Posts:
    2
    I have a custom lighting shader written. Everything works fine in the editor, but when I build to device, I get the following error, and the shader doesn't work.

    'v' : undeclared identifier; 'vertex' : illegal vector field selection

    Tracing through the code, I see this is happening inside of TRANSFER_VERTEX_TO_FRAGMENT, and the call to TRANSFER_SHADOW. I am only using 1 directional light, and no others.

    Any help would be greatly appreciated.

    Thanks.
     
  2. DC_Rich

    DC_Rich

    Joined:
    Feb 4, 2015
    Posts:
    2
    For anyone else, I found a workaround for the issue. Would still like to know why this is happening in the first place.

    Code (CG):
    1. struct v2f
    2. {
    3.     float4 pos : SV_POSITION;
    4.     fixed4 color : COLOR0;
    5.     float3 lightDir : TEXCOORD0;
    6.     float3 normal : TEXCOORD1;
    7.     #if (defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)) && defined(SHADER_API_MOBILE)
    8.     float4 _ShadowCoord : TEXCOORD2;
    9.     #else
    10.     LIGHTING_COORDS( 2, 3 )
    11.     #endif
    12. };
    13.          
    14. struct vertInput
    15. {
    16.     float4 vertex : POSITION;
    17.     float3 normal : NORMAL;
    18.     fixed4 color : COLOR;
    19. };
    20.  
    21.          
    22. v2f vert( vertInput i )
    23. {
    24.     v2f o;
    25.  
    26.     #if (defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)) && defined(SHADER_API_MOBILE)
    27.     o._ShadowCoord = mul( unity_World2Shadow[0], mul( _Object2World, i.vertex ) );
    28.     #else
    29.     TRANSFER_VERTEX_TO_FRAGMENT(o);
    30.     #endif          
    31.     return o;
    32. }
    I left out the guts of the shader, but you get the idea. I hope this helps someone.
     
    kaiyum likes this.
  3. george_vasilchenko

    george_vasilchenko

    Joined:
    Sep 20, 2014
    Posts:
    14
    Hey buddy, but is _ShadowCoord doing for you the rest? Just simple declaration is enough? Do u use LIGHT_ATTENUATION(o) with no changes in your fragment shader? Could you show the fragment shader code as well?
     
  4. LaurynasLubys

    LaurynasLubys

    Joined:
    Mar 7, 2012
    Posts:
    80
    Same problem, When Unity crashed on mobile build I started getting this error in my custom shader.
     
  5. Tortuap

    Tortuap

    Joined:
    Dec 4, 2013
    Posts:
    124
    This is because the macro has a hardcoded parameter :

    #define TRANSFER_SHADOW(a) a._ShadowCoord = mul( unity_WorldToShadow[0], mul( unity_ObjectToWorld, v.vertex ) );

    => v.vertex
     
    kaiyum likes this.
  6. kaiyum

    kaiyum

    Joined:
    Nov 25, 2012
    Posts:
    686
    This is pretty pathetic and thanks to this thread, shadow is working for me now.