- Home /
shaderlab: Matrix-vector multiplication in fragment shader on iOS not working?
I want to calculate screenspace normals and therefore try to performa a matrix-vector multiplication in the fragment shader. It works in the editor, but outputs pink on iOS.
this is my test fragment shader:
half4 frag( v2f i ) : COLOR
{
return float4(0,1,0,0);
//return mul(UNITY_MATRIX_MVP, float4(0,1,0,0));
}
outputs as expected green. but when comment the first line and uncomment the second line instead, the shader fails. Xcode shows me the following output:
Fragment Shader:
precision mediump float;
#define SHADER_API_GLES 1
#define tex2D texture2D
#define gl_ModelViewProjectionMatrix glstate_matrix_mvp
uniform mat4 glstate_matrix_mvp;
void main ()
{
mediump vec4 tmpvar_1;
tmpvar_1 = (gl_ModelViewProjectionMatrix * vec4(0.00000, 1.00000, 0.00000, 0.00000));
gl_FragData[0] = tmpvar_1;
}
Unsupported: MyShader
is this line the problem?
#define SHADER_API_GLES 1
http://http.developer.nvidia.com/Cg/mul.html states that
mul is supported in all profiles except the fp20, ps_1_1, ps_1_2, and ps_1_3 fragment profiles.
I'm not sure how that translates to GLES profiles, but I assume this could be the problem? how do I target GLES2 instead?
You should probably be doing that multiplication in the vertex shader and then interpolating it into the fragment (at least that's what I normally do).
if i could move it to the vertex shader of course I would. But that's not always possible. This question is targeted at problems that explicitely require a matrix vector multiplication in the fragment shader.
yes I tried this and the result is the same, also it still results in #define SHADER_API_GLES 1. The same for #pragma target 3.0. This pragma doesn't seem to affect GLES
Damn, that's annoying :S Hmmm - from threads I've read it looks like you can set GLES 2.0 - now I look I can't work out how...