Mesh.Tangent errors

Okay I’m doing something a little tricky. I want to pass a second set of colors, so I was attempting to pass the colors thru the tangents.

I’m putting the Vector4 color into the Mesh.tangents.

In my vertex shader it outputs COLOR and COLOR1 which I’m copying the TANGENT to COLOR1.

At runtime, I get the following errors from Unity.

Unhandled vertex structure for strided buffers!
offset != stride + kDummyVBStartBytes

Any thoughts for trying to get another color into my fragment program?

The error occurs right here:

o.color1 = v.tangent;

In the context of a vertex program:

v2f vert (appdata v) {
    v2f o;
    o.pos = mul( glstate.matrix.mvp, v.vertex);
    o.texcoord = v.texcoord;
    o.texcoord1 = v.texcoord1;
    o.color = v.color;
    o.color1 = v.tangent;
    return o;
}

The result is the entire mesh disappears, I get errors in the console, and the fallback shader was not called. At that point I have to replay in the editor.

Are you sure you’re using latest Unity version (2.1 right now)? I remember fixing this bug in 2.1.

Oh, and color1 is probably a color interpolator (components in 0…1 range), whereas tangent data is usually in -1…1 range. Use texcoord interpolator or scale&bias the tangent if needed.

I’m using Unity 2.1.0f5. Thanks for the tip. I was using values from 0 to 1 in the tangent, so there must still be a bug there that prevented the fallback from kicking in.

Hmmm I’m getting this again. It’s pretty bad when it happens I have to restart Unity.

offset != stride + kDummyVBStartBytes

I’m trying to put the tangent (float4) in the texcoord2 (float4) so I can see what values that I’m using.

Like you said, if the tangent is outside the uv2 range is causing the issue.

v2f vert (appdata v) {
    v2f o;
    o.pos = mul( glstate.matrix.mvp, v.vertex);
    o.texcoord = v.texcoord;
    o.texcoord1 = v.texcoord1;
    o.texcoord2 = v.tangent;
    o.color = v.color;
    return o;
}

Ah well I’m working around the issue, just have to be careful not to break Unity.

File a bug with project that reproduces the issue.