in a CG shader with 4.6 the following methods for declaring arrays work, but in Unity 5.0 I am now getting either errors, or a black shader, and “upgrades” preventing compilation on various platforms. All the following variations previously worked, but now produce bad results.
float2[2] array;
float2[] array;
float2[2] array =
{
float2(1, 0),
float2(0, 1),
};
float2[] array =
{
float2(1, 0),
float2(0, 1),
};
It appears that array syntax is slightly different now. This is likely because D3D9 shader compiler was switched from Cg 2.2 to HLSL.
After a brief look at HLSL Syntax arrays are declared and initialised slightly differently. In CG in 4.6 you would declare an array in this format.
float[2] array;
float2[] array;
float2[2] array =
{
float2(1, 0),
float2(0, 1),
};
float2[] array =
{
float2(1, 0),
float2(0, 1),
};
in Unity 5.0 it now has to be declared like so.
float array[2];
// NOT ALLOWED! Array needs a length
float2 array[];
float2 array[2] =
{
float2(1, 0),
float2(0, 1),
};
float2 array[] =
{
float2(1, 0),
float2(0, 1),
};