Texture shift in normalmap shader

I have been using ARB vp&fp to do normalmap bump, the shader file looks like this:

!!ARBvp1.0 OPTION ARB_position_invariant;

ATTRIB iTex0 = vertex.texcoord[0];
ATTRIB tangent = vertex.texcoord[1];
ATTRIB bitangent = vertex.texcoord[2];
ATTRIB normal = vertex.normal;

PARAM mvi[4] = { state.matrix.modelview.inverse };

TEMP lightpos, lightvec,temp;

DP4 lightpos.x, mvi[0], state.light[0].position;
DP4 lightpos.y, mvi[1], state.light[0].position;
DP4 lightpos.z, mvi[2], state.light[0].position;

SUB lightvec.xyz, lightpos, vertex.position;

DP3 result.texcoord[1].x, lightvec, tangent;
DP3 result.texcoord[1].y, lightvec, bitangent;
DP3 result.texcoord[1].z, lightvec, normal;
MOV result.texcoord[0], iTex0;

PARAM lightcolor = state.light[0].diffuse;
PARAM ambient = state.light[0].ambient;
TEMP normal, temp, lightvec, texel;
TEX texel, fragment.texcoord[0], texture[0], 2D;
TEX normal, fragment.texcoord[0], texture[1], 2D;
MAD normal, normal, 2.0, -1.0;

DP3 temp, normal, normal;
RSQ temp, temp.x;
MUL normal.xyz, normal, temp;

DP3 temp, fragment.texcoord[1], fragment.texcoord[1];
RSQ temp, temp.x;
MUL lightvec, fragment.texcoord[1], temp;

DP3_SAT temp, normal, lightvec;
MAD_SAT result.color, lightcolor, temp, ambient;
MUL_SAT result.color, texel, temp;

It works well on a static model, but when I apply it to a model which is deformed by bones, I notice the texture(maybe as well as the normal map) on some polygons is shifted sometimes, which looks like the texture coordinate is modified. It only shows up for a few frames from time to time, so it is quite hard for me to track it down. But as far as I know, I am not doing anything to change the texture coord, I’m confused here. Does anyone know things like that?

Are you sure your tangent basis constructor is working correctly? A switch in handedness or transformation devilry can send the whole thing south.

You will have to update your tangent space whenever your vertex data changes, otherwise you will get lighting artifacts.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.