I have been trying to apply normal maps to a rotating sphere with light shining directing from above the sphere (0,1,0). but lighting does not look correct under rotation as one side of the sphere appears darker and the top side of sphere does not seem lit as expected.
I have tried using a fake normal of (0,0,1) and multiplying that by my TBN matrix to ensure the T,B,N are correct and that all seems to work as expected so I have run of ideas of what the issue might be.
if(has_normal_map){
simd_float3 colour = flatMap.sample(textureSampler, in.tex).rgb;
simd_float3 tangent = normalize(in.tangent - dot(in.tangent, in.normal) * in.normal);
simd_float3 bitangent = normalize(cross(in.normal, tangent));
simd_float3x3 TBN = simd_float3x3(normalize(tangent),bitangent,normalize(in.normal));
float3 normal = (normalMap.sample(textureSampler, in.tex)).rgb;
normal = (normal * 2.0 - 1.0);
normal = normalize(normal);
//normal = simd_float3(0,0,1);
normal = normalize(TBN * normal);
float attenuation = saturate(dot(light_vector,normal));
return float4(attenuation*colour,1);
}
bitangent = normalize(cross(norm,tang))*sigma
Where sigma is computed at the same time as the tangent and bitangent. And is always either +1 or -1. I don't see this being applied anywhere in the posted code sample. $\endgroup$