Search code examples
unity-game-engineshader

Invalid output semantic 'SV_POSITION': Legal indices are in [0,0]


I just start to learn Unity3d Shader, I followed the tutorial of a book, all my code is the same as the tutorial, however, there is an error I can't figure out.

Here is the code:

    Shader "Unity Shaders Book/Chapter5/Simple Shader"{
        SubShader{
            Pass{
            CGPROGRAM

    #pragma vertex vert
    #pragma fragment frag

    struct a2v {
    float4 vertex:POSITION;
    float3 normal:NORMAL;
    float4 texcoord:TEXCOORD0;
    };

    struct v2f {
        float4 pos: SV_POSITION;
        fixed3 color : COLOR0;

    };

    v2f vert(a2v v) : SV_POSITION {
        v2f o;
        o.pos = UnityObjectToClipPos(v.vertex);
        o.color = v.normal *0.5 + fixed3(0.5, 0.5, 0.5);
        return o;
    }
    fixed4 frag(v2f i) : SV_Target{
    return fixed4(i.color,1.0);
    }
    ENDCG
    }
}

}

The error


Solution

  • Change this line:

    v2f vert(a2v v) : SV_POSITION {
    

    Into this:

    v2f vert(a2v v) {