Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

non-square matrices not supported error

Discussion in 'Shaders' started by MRKane, Nov 30, 2016.

  1. MRKane

    MRKane

    Joined:
    Oct 4, 2012
    Posts:
    54
    Hello all,

    I've been trying to build my project for both Android and iOS and have hit a very funny issue with my vert/frag shader that I've not run into until the last update. I'm getting the errors:
    • Shader error in 'Water/sphereProjectWater': '' : non-square matrices not supported (4x1) at line 185 (on gles)
    • Shader error in 'Water/sphereProjectWater': '' : unsupported matrix constructor requested (4x1) at line 185 (on metal)
    In relation to the code snippet that handles the lighting and object rotation within the shader. The normal is the mesh vertex normal so there's nothing fancy there:

    (68) uniform float4x4 _globeLightRotation;
    ...
    (185) o.lightnormal = mul(_globeLightRotation, o.normal.xyz);​

    Any help would be highly appreciated! I've tried pretty much everything I can think of, so it's time to ask for help!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,365
    You're attempting to apply a float4x4 to a float3, you have to do a float3x3 with a float3 or a float4x4 with a float4.

    Try:
    o.lightnormal = mul(_globeLightRotation, float4(o.normal.xyz, 0.0));

    Desktop drivers / compilers are smarter about this and automatically convert your line to something equivalent to the above, but stricter compilers just tell you you're doing it wrong (with a somewhat unhelpful error it seems).
     
    WereVarg and MRKane like this.
  3. MRKane

    MRKane

    Joined:
    Oct 4, 2012
    Posts:
    54
    You nailed it in one! Thank you so much!
    ...Now thinking about this, it's not what I'd call "square" lol
     
  4. CiCinka

    CiCinka

    Joined:
    Mar 21, 2018
    Posts:
    1
    Hello MRKane

    I have a similar issue, but I am using obi cloth.

    Shader error in 'Obi/Particles': '' : non-square matrices not supported (3x1) at line 63 (on gles)
    Shader error in 'Obi/Particles': '' : non-square matrices not supported (3x1) at line 160 (on gles)

    Do oyu have any idea how to solve it? I would really appreciate your help.

    Best
    C.
     
    Wuxh1234 likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,365