struct v2f -> declaration order

Hey hey,

I just stumbled across a problem I had some time ago, but there I managed to make it work without really understanding why…

It’s about the order of variable declaration in v2f struct.

struct v2f {
	V2F_POS_FOG;
	LIGHTING_COORDS
	float2  uv;
	float3	viewDir;
	float3	lightDir;
	float3  normal;
	float3  tangent;
	float4  vertexColor;
};

With this order I get the following error:

When I change the order I don’t get an error message:

struct v2f {
	V2F_POS_FOG;
	LIGHTING_COORDS
	float4  vertexColor;
	float2  uv;
	float3	viewDir;
	float3	lightDir;
	float3  normal;
	float3  tangent;
};

Is there a rule in which order I have to declare my variables?
Thanks in advance…

Jan

I think Cg is just getting confused by too many values to interpolate between vertex fragment programs. Light/shadow stuff (LIGHTING_COORDS) uses 0 to 3 texture interpolators. And you want to use 6 more, which does not fit into 8 texture interpolators.

Maybe you can pack some things into float4’s? Or interpolate something in the color interpolator (e.g. float4 vertexColor : COLOR0)?

Thanks… I solved the problem by moving the LIGHT_COORDS all the way down. Now I don’t get error messages when using TEXCOORD0 or COLOR0 anymore. But packing some things into float4s might be a good solution too… I’ll try that next time. :wink:

struct v2f {
   V2F_POS_FOG;
   float2  uv : TEXCOORD0;
   float4  vertexColor : COLOR0;
   float3  view;
   float3  light;
   float3  tangent;
   LIGHTING_COORDS
};