Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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:
    11,766
    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.
     
    DevilWxh likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    11,766
unityunity