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. How can we improve our URP documentation to cover your needs? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

unknown semantics "NORMAL" ???

Discussion in 'Shaders' started by jatobu, Sep 27, 2012.

  1. jatobu

    jatobu

    Joined:
    Nov 12, 2009
    Posts:
    21
    hi,

    does anyone know why this shader doesn't recognize NORMAL as a semantic?

    Code (csharp):
    1.  
    2. Shader "MyShaderTest/Read Vertex Normal" {
    3.     SubShader {
    4.         Pass{
    5.             CGPROGRAM
    6.             #pragma fragment frag
    7.             #include "UnityCG.cginc"
    8.        
    9.             struct v2f {
    10.                 float4 pos : SV_POSITION;
    11.                 float3 norm : NORMAL; // Error HERE!!...
    12.             };
    13.  
    14.             half4 frag( v2f i ) : COLOR
    15.             {
    16.                 return half4( 1,1,1,1 );
    17.             }
    18.             ENDCG
    19.         }
    20.     }
    21.     FallBack "VertexLit"
    22. }
    23.  
    the message I get is:

    "Program 'frag', unknown sematics "NORMAL" specified for "norm" at line 17"

    but according to the CG Tutorial a fragment shader CAN get the semantic NORMAL.

    so... I don't know what am I doing wrong here... =S

    Any help would be appreciated.
     
  2. Martin-Kraus

    Martin-Kraus

    Joined:
    Feb 18, 2011
    Posts:
    617
    I think you have to read it a bit more carefully. From the Cg Tutorial:
    Code (csharp):
    1.  
    2. void C5E2v_fragmentLighting(float4 position : POSITION,
    3.                             float3 normal   : NORMAL,
    4.                         out float4 oPosition : POSITION,
    5.                         out float3 objectPos : TEXCOORD0,
    6.                         out float3 oNormal   : TEXCOORD1,
    7.                     uniform float4x4 modelViewProj)
    8. {
    9.   oPosition = mul(modelViewProj, position);
    10.   objectPos = position.xyz;
    11.   oNormal = normal;
    12. }
    13.  
    14. void C5E3f_basicLight(float4 position  : TEXCOORD0,
    15.                       float3 normal    : TEXCOORD1,
    16.                   out float4 color     : COLOR,
    17.               uniform float3 globalAmbient,
    18.               uniform float3 lightColor,
    19.               uniform float3 lightPosition,
    20.               uniform float3 eyePosition,
    21.               uniform float3 Ke,
    22.               uniform float3 Ka,
    23.               uniform float3 Kd,
    24.               uniform float3 Ks,
    25.               uniform float  shininess)
    26. {
    27.    ...
    28. }
    29.  
    Apparently they use TEXCOORD1 for the normal. (I don't have the link at hand but as far as I remember the specification says that you cannot use the NORMAL semantics for fragment programs.)
     
  3. jatobu

    jatobu

    Joined:
    Nov 12, 2009
    Posts:
    21
    Thanks Martin,

    you're totally right!... I think I had the mistake of fast reading "fragmentLighting" and asume it was the fragment shader, but now that you point that out it certainly was the vertex shader, and was passing the normal through the TEXCOORD semantic.

    Apologies!
     
unityunity