v2f structure limit ???

Hello all !!

playing with shaders, my v2f structure gets bigger and bigger and… it appears it’s now too big and cannot compile anymore :shock:

here it is:
** struct v2f {**
** V2F_POS_FOG;**
** float3 ref;**
** float2 bumpuv[2];**
** float4 viewDirZ;**
** LIGHTING_COORDS**
** float3 uvK;**
** half2 uv2;**
** half3 ld;**
** half3 vd;**
** };**

Everything works fine till i want to access vd in
vertex module with someting like: o.vd = 10;

compiler says :
Cg in program ‘vert’: error C5041: cannot locate suitable resource to bind parameter “vd” at line 88

I tried to change some floats to halves but with no luck :frowning:
Finally it mostly appears that the compiler has reached his struct number of members limit instead of any max structure size limit.

On the other hand console message are almost unusefull, saying error comes frome here or there…
line numbers are totally erratic. is there a way to solve this bug ? In the present case, line 88 is a comment :lol:

Thnaks a lot for your answers and have a nice day
:slight_smile:

struct v2f {
V2F_POS_FOG;
float3 ref;
float2 bumpuv[2];
float4 viewDirZ;
LIGHTING_COORDS
float3 uvK;
half2 uv2;
half3 ld;
half3 vd;
};

Try packing your structure tighter. You have too many things to interpolate.

half2 uv2 half3 ld half3 vd = can be packed into two half4 variables. That might give you some more room.

Hi,

In shader model 2.0 there are 8 general purpose vertex->fragment interpolators available. This means that you can pass a maximum of 8 float4’s (+ 2 color semantics but they are of lower precision so ignore them for the time being).

In shader model 3.0 you can have 8. In SM4.0 you can have 16 (expanded to 32 via geometry shaders). If your v2f interpolators go over these limits given the shader model then you will receive these errors.

brianasu was right when suggesting that you should pack your structure tighter, it’s the only way. If you do end up going over the limit, and can’t pack any more you will have to try and do more calculation in the VS (if possible).