Search Unity

d3d11 shader warning

Discussion in 'Shaders' started by jesta, Dec 21, 2012.

  1. jesta

    jesta

    Joined:
    Jun 19, 2010
    Posts:
    294
    "Program 'vert', incorrect number of arguments to numeric-type constructor (compiling for d3d11)"

    I tried UNITY_INITIALIZE_OUTPUT, #pragma target 5.0, initializing each output variable... nothing works.

    Anyone found a solution to this annoying warning? Shader works fine in dx9.

    Thanks.
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Can you provide the listing of vert()? Have you been able to find a numeric-type constructor that the compiler might be complaining about?
     
  3. jesta

    jesta

    Joined:
    Jun 19, 2010
    Posts:
    294
    Here:

    Code (csharp):
    1.  
    2.             struct v2f
    3.             {
    4.                 float4 position : POSITION;
    5.                 float4 worldPos : TEXCOORD1;
    6.                 float2 texcoord : TEXCOORD0;
    7.             };
    8.  
    9.             v2f vert (appdata_base v)
    10.             {
    11.                 v2f o;
    12.                 o.worldPos = mul(_Object2World, v.vertex);
    13.                 o.position = mul(UNITY_MATRIX_MVP, v.vertex);
    14.                 o.texcoord = v.texcoord.xy;
    15.                 return o;
    16.             }
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    That's weird: unless I'm missing something, there are no numeric-type constructors in that function. I wish Unity's shader compilation errors were more helpful.
     
  5. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    I fixed the warning just changed the float4(0) to float4(0,0,0,0), and warning is gone.

    or can fix it from

    fixed3 c = fixed3(Luminance(c));

    to

    fixed3 c = fixed(Luminance(c)).xxx; // or just fixed3 c = Luminance(c);

    and the d3d11 warning should be gone.

    I'm using mac and don't know is it doing the same thing in pc.
     
    Last edited: Apr 16, 2013
  6. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    float4(0) does not appear anywhere in the posted code.
     
  7. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Yeah, I get a lot of this stuff. DX11 seems very picky when assigning things compared to other platforms.
     
  8. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    yes, the posted code from jesta didn't not have that float4(0), but he didn't post a completed code, so it may be in the fragment code somewhere.
    Anyway, it is just a general idea how i fixed that d3d11 warning issue. hope it helps for others.
     
  9. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Did you also get the error attributed to Program 'vert', like Jesta?
     
  10. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    Something if you get the problem in fragment or other function codes, then you will get the error message for Program vert from unity editor.
    The vert code from jesta has no problem at all, so the error is from other code.

    just don't trust all the error message from unity editor, need to try to test which code get the errors.
     
  11. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Ugh, you're right.

    I had the pass
    Code (csharp):
    1.  
    2. Pass {
    3.             Name "Zprime"
    4.             Tags {"LightMode" = "Always"}
    5.             ColorMask 0
    6.  
    7.             CGPROGRAM
    8.                 #pragma vertex vert
    9.                 #pragma fragment frag
    10.                 #pragma fragmentoption ARB_precision_hint_fastest
    11.  
    12.                 #include "UnityCG.cginc"
    13.  
    14.                 struct appdata {
    15.                     float4 vertex : POSITION;
    16.                     float4 texcoord : TEXCOORD0;
    17.                 };
    18.  
    19.                 struct v2f
    20.                 {
    21.                     float4  pos : SV_POSITION;
    22.                     float2  uv : TEXCOORD0;
    23.                 };
    24.  
    25.                 float4 _MainTex_ST;
    26.  
    27.                 v2f vert (appdata v)
    28.                 {
    29.                     v2f o;
    30.                     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    31.                     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    32.                     return o;
    33.                 }
    34.  
    35.                 sampler2D _MainTex;
    36.                 float _Cutoff;
    37.  
    38.                 float4 frag(v2f IN) : COLOR
    39.                 {
    40.                     // Textures.
    41.                     fixed alpha = tex2D(_MainTex, IN.uv).a;
    42.                     clip(alpha - _Cutoff);
    43.                     return fixed4(0.0);
    44.                 }
    45.             ENDCG
    46.         }
    47.  
    Which complained about d3d11 issues with the vert program. So I changed around a ton of stuff to try and sort it to no avail.

    Turns out it was the last line of the fragment shader. Changing it from
    return fixed4(0.0);
    to
    return fixed4(0.0,0.0,0.0,0.0);
    resolved the issue.
     
    Last edited: Apr 18, 2013
  12. BMadrid

    BMadrid

    Joined:
    Nov 26, 2013
    Posts:
    26
    i have the same problem but with float3

    Code (csharp):
    1.  
    2. float3 ContrastSaturationBrightness(float3 color, float brt, float sat, float con)
    3. {
    4.   float3 LumCoeff = float3(0.2125, 0.7154, 0.0721);
    5.   float3 AvgLumin = float3(0.5, 0.5, 0.5);
    6.   float3 brtColor = color * brt;
    7.   float3 intensity = float3(dot(brtColor, LumCoeff));
    8.   float3 satColor = lerp(intensity, brtColor, sat);
    9.   float3 conColor = lerp(AvgLumin, satColor, con);
    10.   return conColor;
    11. }
    12.  
     
  13. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Yeah that's the offending line:

    Code (csharp):
    1.  
    2. float3 intensity = float3(dot(brtColor, LumCoeff));
    3.  
    Would have to split it like so:

    Code (csharp):
    1.  
    2. float tmp = dot(brtColor, LumCoeff);
    3. float3 intensity = float3(tmp, tmp, tmp);
    4.  
    I recognize this function from the "photoshop-maths shaders" blog page. Like all their shaders -- while it works, it's a little on the bloated side (which is better for clarity and understanding though). Here's my slightly leaner version:

    Code (csharp):
    1.  
    2. void colorAdjust(inout half3 col) {
    3.     col = lerp(0.5, col * _ContrastSaturationBrightness.z, _ContrastSaturationBrightness.x);
    4.     col = lerp(Luminance(col), col, _ContrastSaturationBrightness.y);
    5. }
    6.  
    The call to Luminance() assumes/requires that UnityCG.cginc is #included though --- which I need for other things in my post shader anyway..
     
  14. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    This is why DX11 programming can be a pain... ;)