OpenGLES2 and fixed1 mul(fixed4 v, fixed4x1 M)

Hi

I want to multiply two vectors (one transposed) and get scalar value.
Function fixed1 mul(fixed4 v, fixed4x1 M) is described here: http://http.developer.nvidia.com/Cg/mul.html
It works fine on Android phone with OpenGLES3 API, but when I switch to OpenGLES2 (in PlayerSettings/Other Settings/Graphics API) my shader doesn’t work on Android device.

I made very simple shader, to prove this is the problem:

Shader "my/test" {

  Properties {
  }
  SubShader{
    Tags {
      "LightMode" = "ForwardBase"
    }
    Pass {
      Cull Off
       
      CGPROGRAM
     
      #pragma vertex   vert
      #pragma fragment frag
     
      struct VertIn {
        fixed4 posM : POSITION;
        fixed3 norm : NORMAL;
        fixed4 uv   : TEXCOORD0;
      };
     
      struct FragIn {
        fixed4 posP   : SV_POSITION;
      };
     
      FragIn vert ( VertIn i ) {
        FragIn o;
        o.posP       = mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorld, i.posM));
        fixed test   = mul(fixed4(0,1,2,3),fixed4(1,0,2,1));
        return o;
      }
     
      float4 frag (FragIn i) : COLOR {
        return fixed4(1,1,1,1);
      }
     
      ENDCG
    }
  }
  //Fallback "Diffuse"
}

As you can see, it’s super simple and returns white (fixed4(1,1,1,1)) for all fragments.
For some reason on Android device with OpenGLES2 it’s pink.
It’s white, when I comment line

fixed test   = mul(fixed4(0,1,2,3),fixed4(1,0,2,1));

What am I doing wrong?

Maybe I shouldn’t use fixed4 like fixed1x4, but, to be honest, I don’t know how to declare fixed1x4 value.
I tried fixed1x4(1,2,3,4) and transpose(fixed4(1,2,3,4)) and both do not compile.

OpenGLES 2.0 doesn’t support non-square, non-power of 2 matrices. However it sounds like what you actually want is a dot product.

dot(fixed4(1,2,3,4),fixed4(1,2,3,4));

Thank you

I’m struggling to find link for this, so I’m going by memory, but:

While for most devices fixed and half are the same thing, some (older) devices, treat fixed (lowp) differently and it’s generally clamped to -2 and 2, so you may get unpredictable results if you use values higher than that.

1 Like