- Home /
Cg Language incompatibility Desktop VS GLSL Android
Hi there,
today I came across a bug in one of my shaders. The following line caused the problem, but only on Android Mobile device:
float3 side = step(3.0f, foo.xyz) * 3.0f;
The fix for this was the following:
float3 side = step(float3(3,3,3), foo.xyz) * float3(3,3,3);
In the Unity3D Editor, even when GLES 2.0 emulation is enabled, the result is what I've expected. Each component of "side" contains 0 or 3 for each component of "foo" that is >= 3.
On mobile, each component of side contains 0 or 3 if foo.x is >= 3.
I do not get any "implicit truncation of vector type" warning in the log and also no warnings at all for any shader language in the shader properties.
I have searched the language specifications and found out that GLSL isn't capable to convert a single component float value to a vector type implicitly, or at least it isn't documented or I didn't find it.
But Cg is, which would mean that the generated code for HLSL/GLSL is wrong, but why only on mobile? According to the Cg spec, the first code portion should be okay, the first parameter of step() should be widened to be a float3 and the last multiplication should become a float3, too.
So who is wrong here? Did I misunderstand something, is there a bug in Cg or in Unity3D? Should I file a bug report with an example project?
Best,
Nils
Your answer
Follow this Question
Related Questions
Shader problem with alpha blend and zwrite iOS 1 Answer
How can I make my own shader include file (.cginc or .glslinc)? 2 Answers
Sizeof float in cg shader 1 Answer
shaderlab: Matrix-vector multiplication in fragment shader on iOS not working? 0 Answers
No acceptable conversion when converting cg shader to glsl 0 Answers