Search Unity

Shader compile errror: "Fragment program 'frag_surf': non-4 sized matrix"?

Discussion in 'Shaders' started by orb_9, Sep 14, 2011.

  1. orb_9

    orb_9

    Joined:
    Feb 10, 2010
    Posts:
    47
    I'm currently trying to find a bug in a shader. The error message is:
    Code (csharp):
    1.  
    2. Shader error in 'Hidden/TestBug': Fragment program 'frag_surf': non-4 sized matrix M at line 10
    3.  
    As this error occurs in a larger shader, I tried to extract the problem and wrote a dummy shader which demonstrates the problem. Note that this shader does not do anything useful, it's just here to demonstrate the error.

    The code below results in the error above. If I comment out the line producing the error and uncomment the other lines, the shader compiles. In both cases i'm using a float scalar - so the problem is definitively produced by the matrix operation.
    Code (csharp):
    1.  
    2. Shader "Hidden/TestBug" {
    3.     Properties {
    4.         _MainTex ("Texture", 2D) = "white" {}
    5.     }
    6.  
    7.     SubShader {
    8.         Tags { "RenderType" = "Transparent"  "Queue"="Transparent"}
    9.  
    10.         CGPROGRAM
    11.         #pragma surface surf Lambert
    12.         #pragma target 3.0
    13.  
    14.         struct Input { float2 uv_MainTex; };
    15.         sampler2D _MainTex;
    16.         const float3x3 M = { 1,2,3,   4,5,6,   7,8,9  };
    17.      
    18.         void surf (Input IN, inout SurfaceOutput o)
    19.         {
    20.             float3x3 I;
    21.             float r = dot(M[0], I[0]);
    22.  
    23.             // the scalar resulting from the matrix dot product throws an error... why?
    24.             // "Fragment program 'frag_surf': non-4 sized matrix M"
    25.             o.Albedo = float4(r,0,0,0);
    26.  
    27.             // using another scalar (which does not result from a matrix operation) works
    28.                         // uncommenting the following two lines and commenting out the above one,
    29.                         // makes the shader compile
    30.             // float s = 0.4;
    31.             // o.Albedo = float4(s,0,0,0);
    32.          }
    33.          ENDCG
    34.     }
    35.  
    36.     Fallback "Diffuse"
    37. }
    38.  
    Does anybody know what's wrong here?
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Matrixes need to be 4x4, as far as I know.

    If you need to multiply something as if it were a 3x3 you'd use
    Code (csharp):
    1. mul((float3x3)matrix, value).xyz;
    So you can just fill the other entries in the matrix with 0 and it'll work the same.
     
  3. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yeah, I think for the moment we don't support float3x3 as uniform shader variables. Make it float4x4 and use only the upper 3x3 part.
     
  4. rocifier

    rocifier

    Joined:
    Apr 22, 2013
    Posts:
    3
    Hi, when are you going to support float3x3 as a uniform variable? I use these each day in my work for image processing constants, it would keep my code much tidier and less work to maintain.