Hi,

I've got a problem that normal mapping is dependent on view. It looks like this (sorry for the watermarks): http://www.youtube.com/watch?v=-V_2Pp4kiLM&feature=youtu.be

The normal mapping is calculated in the pixel shader as follows (it is actually taken from http://stackoverflow.com/questions/5255806/how-to-calculate-tangent-and-binormal):

- vertexPosition is a position in SV_POSITION semantic

- shared vertices on in the triangles

float3 computeNormalWithTBN(float3 vertexPosition, float2 texCoord, float3 normal ) { float3 p_dx = ddx(vertexPosition); float3 p_dy = ddy(vertexPosition); float2 tc_dx = ddx(texCoord); float2 tc_dy = ddy(texCoord); float3 t = normalize( tc_dy.y * p_dx - tc_dx.y * p_dy ); float3 b = normalize( tc_dy.x * p_dx - tc_dx.x * p_dy ); float3 n = normalize(normal); float3 x = cross(n, t); t = cross(x, n); t = normalize(t); x = cross(b, n); b = cross(n, x); b = normalize(b); float4 detail = normalMap.Sample( SampleType, texCoord ); detail = (detail * 2.0f) - 1.0f; detail *= 6.0f; return normalize( normal + detail.x * t + detail.y * b ); }

// in main function // ... input.normal = computeNormalWithTBN( input.position.xyz, input.tex.xy, input.normal; float light = saturate( dot( input.normal, float3( 0, 0.73, -0.69 ) ) ); float4 color = 0.3f; color += light; return color; }

Why this happens?

Thanks for help.