Search Unity

Shader Error: Invalid input semantic 'POSITION'

Discussion in 'Shaders' started by FlaflaTwo, Mar 27, 2015.

  1. FlaflaTwo

    FlaflaTwo

    Joined:
    Apr 5, 2014
    Posts:
    15
    Hello all,

    I am currently writing a basic vertex/fragment shader in Unity and for some reason the shader compiler is throwing this error at me:

    Supposedly this is because I have a variable inside my v2f struct that has the SV_POSITION semantic - yet, many of the examples that I have seen do this and it works fine. Does anyone have any pointers as to how I can fix this? Here is my code (I hate to straight up dump what I have, but I have no idea what random thing may be causing this problem):

    Code (CSharp):
    1. Shader "Blink/Blink Controller" {
    2.     SubShader {      
    3.         Tags { "RenderType"="Transparent" "Queue"="Geometry"}
    4.         // PASS 1: Write to stencil buffer, frontface culling.
    5.         // Handled in CommandBuffer before Geometry Pass
    6.         Pass {
    7.             Cull Front
    8.             ZWrite Off
    9.             Stencil {
    10.                 Ref 1
    11.                 Comp Always
    12.                 Pass Replace
    13.             }
    14.  
    15.             CGPROGRAM
    16.             #pragma vertex vert
    17.             #pragma fragment frag
    18.             struct appdata {
    19.                 float4 vertex : SV_POSITION;
    20.             };
    21.             struct v2f {
    22.                 float4 pos : SV_POSITION;
    23.             };
    24.             v2f vert(appdata v) {
    25.                 v2f o;
    26.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    27.                 return o;
    28.             }
    29.             half4 frag(v2f i) : SV_Target {
    30.                 return half4(1,0,0,1);
    31.             }
    32.             ENDCG
    33.         }
    34.  
    35.         // PASS 2: Draw Border
    36.         // Handled In Command Buffer before Transparency Pass
    37.         Pass {
    38.             Cull Off
    39.             ZWrite Off
    40.             Blend SrcAlpha OneMinusSrcAlpha
    41.             Stencil {
    42.                 Comp Always
    43.                 Pass Keep
    44.             }
    45.             CGPROGRAM
    46.             #pragma vertex vert
    47.             #pragma fragment frag
    48.             #pragma target 3.0
    49.  
    50.             #include "UnityCG.cginc"
    51.  
    52.             struct v2f {
    53.                 float4 pos : SV_POSITION;
    54.                 float4 projPos : TEXCOORD0;
    55.             };
    56.  
    57.             // Camera's depth texture
    58.             uniform sampler2D _CameraDepthTexture;
    59.             half4 _Color;
    60.             float _Fade;
    61.  
    62.             v2f vert(appdata_base v) {
    63.                 v2f o;
    64.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    65.                 o.projPos = ComputeScreenPos(o.pos);
    66.                 return o;
    67.             }
    68.  
    69.             fixed4 frag(v2f i) : SV_Target  {
    70.                 float2 wcoord = i.projPos.xy / i.projPos.w;
    71.                 float depth = LinearEyeDepth(UNITY_SAMPLE_DEPTH(tex2D(_CameraDepthTexture, wcoord)));
    72.                 float border = 1.0f - saturate((depth - i.pos.z) * _Fade);
    73.                 return fixed4(_Color.rgb, border);
    74.             }
    75.             ENDCG
    76.         }
    77.     }
    78.     FallBack "Diffuse"
    79. }
    80.  
     
  2. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    SV_POSITION is only a semantic for vertex to fragment, not vertex input.
    You use it in your struct appdata.

    Try to replace SV_POSITION by POSITION there.
     
  3. FlaflaTwo

    FlaflaTwo

    Joined:
    Apr 5, 2014
    Posts:
    15
    Hi Guilllaume,

    I tried this and got the same error. This is not entirely unexpected as the compiler complains about line 53, which is inside the second pass. Any other ideas? Thank you so much.
     
  4. FlaflaTwo

    FlaflaTwo

    Joined:
    Apr 5, 2014
    Posts:
    15
    Update: It seems that this error only appears when I click the "compile and show source" button when viewing the shader in the inspector. At first, I thought this was because the shader wasn't compiling until i clicked said button. However, it seems that this is simply a Unity bug as my shader works fine.
     
  5. lazer

    lazer

    Joined:
    Aug 15, 2012
    Posts:
    23
    Sorry to bump an old thread, but I'm having the exact same problem, except the error originates from inside unity's standard includes. When creating a windows build locally, the error is reported but the build still works. In cloud build however this error aborts the build.

    In the shader inspector I can disable d3d9 variants to suppress the error but UCB doesnt seem to respect this.

    (The same occurs on 5.6.0f1 which is what the project is actually created in)

    full build log for UT folks:

    https://developer.cloud.unity3d.com.../default-windows-desktop-64-bit/builds/4/log/

    Would appreciate some help here. We would really like to use cloud build.
     
  6. VLukianenko

    VLukianenko

    Joined:
    Mar 27, 2017
    Posts:
    30
    Having absolutely same issue. There are also some more shader errors popping up (after upgrade to Unity 5.5.1), but all the shaders in local build work fine. It only prevents cloud build.

    #pragma target 3.5 - eliminates errors, but isn't the best solution, because it also eliminates many older devices...
     
    Last edited: May 18, 2017
  7. marianpekar

    marianpekar

    Joined:
    Dec 4, 2017
    Posts:
    1
    Go to Build Setting -> Player Setting... and under Resolution and Presentation set D3D9 Fullscreen Mode to Exclusive Mode.

    That fixed this issue for me with in Unity 2017.2.0f3