Hi,
I recently switched to from Unity4.6 to Unity5.0.
I now have errors relative to the matrices I use in the vertex output structure.
-
Error message: “‘float2x4’ : not supported in pre-GLSL1.20”
I did not have this error message in Unity 4.6.
It disappears when I add a “#version 120” as the first line of the CG program.
-
But then the compiled shader is empty, and there are no error messages.
I commented all the code to keep the minimum and noticed that the problem comes from the vertexOutput structure in which a 4x4 matrix is defined:
struct vertexOutput
{
float4 pos : SV_POSITION;
float4x4 matrix_near : TEXCOORD2;
};
I am totally in the fog right now: I don’t understand why I’ve got so dramatic issues only by switching from 4.6 to 5.0.
Any help would be very much appreciated.
What’s the intended target?
As far as I remember, GL ES 2 only require a version 100 of glsl, so using version 120 could produce shader that fail on ES2. And non square matrix aren’t supported on version 100. But your example show a float4x4. Is there any float2x3 in your code?
Second, you shouldn’t use version directive. That’s pure glsl, and since you’re using float4x4 (and not mat4) I’m guessing your writing your shader in Cg/HLSL. Unity usually use Cg/HLSL and translate that to glsl for platform that need glsl.
Try “#pragma version 3.0” (note, this will make the shader fallback on some mobile platform, as they only support SM 2.0)
Also, careful. Binding a matrix to an interpolator (TEXCOORD) will eat up multiple slot. Interpolator are only float4, so here in your example, it will eat up TEXCOORD2, TEXCOORD3, TEXCOORD4 and TEXCOORD5
If you can post your full shader, will be easier to help you! =)
Hi,
Thank you for all the tips.
Basically there are float2x4 in my code but I temporarily removed them to debug the rest of the shader.
Problem is that even float4x4 does not seem fully supported as the compiled shader is empty when I have a float4x4 in the vertexOutput structure.
“#pragma version 3.0” does not work: “Unrecognized pragma directive”.
See the minimum shader I struggle with attached.
Thanks for you help.
2062546–134409–example.shader (1.25 KB)
Damn sorry, it was “#pragma target 3.0” not version, I got confused between all those name! =D
But your shader already have that pragma so that’s ok.
So I can see 3 error :
-
Missing TEXCOORD semantic for the float4x4, which I guess is just a mistake in the “minimum” shader (since it is in your original post), but fon’t forget to replace “float4x4 m” by “float4x4 m :TEXCOORD2”
-
As the “Errors” pannel in the inspector tell you in unity (when the shader file is selected), your fragment main function (frag) need to tell WHERE it will put it’s output (semantic binding). So just replace
float4 frag(vertexOutput i)
by
float4 frag(vertexOutput i) : SV_Target
- you don’t initialize fully o! So in your vertex shader add : o.m = AMatrix; (e.g, to test, “o.m = UNITY_MATRIX_MVP;”)
If still a problem, what is your plateform ?
Thanks for your answer.
The TEXCOORD2 and the matrix initialisation were indeed mistakes I made only in the minimum shader.
Interestingly, I don’t have any “Errors” pannel in the inspector (see screenshot attached).
So, on my machine, I see no errors at all (except that the compiled shaders are empty).
I run OS X 10.10.3 with Unity 5.0.0f4 (on a MacBook Air with Intel HD Graphics 4000 1024 MB)
.
I got the same error:
“GpuProgram creation error: empty shader string”