GL material shader, normal maps, issues

hi,

I use a code in several shaders about normal mapping, that I get and adapted from the GLSL wiki :

http://en.wikibooks.org/wiki/GLSL_Programming/Blender/Lighting_of_Bumpy_Surfaces

It seems I have an issue with the tangent attribute :
provided the object does not rotate, or rotates slowly it’s ok, the bump effect looks nice and reacts to lights transformations.
but if I rotate the object of 90° in one tic, there’s a glitch at this tic, I have an error about world/view/something matrices I suppose.

example of case where I can observe the glitch :
characted oriented towards north, order given to rotate towards east
> RIG animation that goes from idle towards -Y to idle oriented towards +X
> when RIG animation ends, rotate the OBJECT rig 90°, replace rig animation frame idle +X by idle -Y
-> normals ‘jump’ at this tic, light reflection is a bit different, but still looks ok…

at shader creation time, among all the necessary stuff and uniforms for normal map etc, I :

shader.setAttrib(g.SHD_TANGENT)

in the vertex code :


VertexShader = """
	attribute vec4 tangent;
	varying mat3 localSurface2View;
	varying vec4 uvmap
[...]
		localSurface2View[0] = normalize(vec3(gl_ModelViewMatrix * vec4(vec3(tangent), 0.0)));
		localSurface2View[2] = normalize(gl_NormalMatrix * gl_Normal);
		localSurface2View[1] = normalize(cross(localSurface2View[2], localSurface2View[0]));
		uvmap = gl_MultiTexCoord0 ;
[...]
"""

in the fragment code :

FragmentShader = """
	varying mat3 localSurface2View;
	varying vec4 uvmap ;
	uniform sampler2D normalid; // 'normalMap' could it be relevant ?
	// uniform float normalInt;
	// uniform	float normalScale ; I removed these to simplify the thread, seem to be out of cause.

	[...]
	vec3 bump(vec4 texNormal) //, mat3 localSurface2View, float normalInt)
	{   
		vec3 localCoords = normalize(vec3(2.0, 2.0, 1.0) * vec3(texNormal) - vec3(1.0, 1.0, 0.0));
		return normalize(localSurface2View * localCoords) ;
	}
	void main()
	{
	[...]
		vec4 texNormal = texture2D(normalid,vec2(uvmap) ) ;
		vec3 N = bump(texNormal) ;
	[...]
	}


lamps coordinates/directions/other light props are given by uniforms and I 90% sure they are, now… finally… after huge battles against matrices and BGE docs, working right.

interesting potential of information in the BGE docs :
http://www.blender.org/documentation/blender_python_api_2_68_2/bge.types.BL_Shader.html?highlight=setattrib#bge.types.BL_Shader.setAttrib
http://www.blender.org/documentation/blender_python_api_2_68_2/bge.logic.html?highlight=shd_tangent

I believe it comes from the tangent calculation.

how do you perform this ? what should I know or test ?

thanks,
jerome