I have a flat water surface with a dud and a normal map attached to it. The dudv card works correctly, and the normal card is also attached correctly (visualization of the normal card looks as it should). Mirror flares always appear in the wrong place, as if the direction of the light were in the wrong direction. Lighting works correctly without a normal display, so I do not believe that this is the direction of the light, but probably something with a tangent space. As I compute the tangent space from a static set of vectors, I am confused where this might go wrong.
Here, in the vertex shader, I create the TBN matrix, which I use to create the tangent space vectors that I send to the fragment shader:
const vec3 TANGENT = vec3(1.0, 0.0, 0.0);
const vec3 NORMAL = vec3(0.0, 1.0, 0.0);
const vec3 BITANGENT = vec3(0.0, 0.0, -1.0);
out vec3 FragPos;
out vec3 TangentFragPos;
out vec3 TangentLightDir;
out vec3 TangentPlayerPos;
void main()
{
FragPos = vec3(model * vec4(vertex, 1.0));
mat3 mod = transpose(inverse(mat3(model)));
[...]
vec3 n = normalize(mod * NORMAL);
vec3 t = normalize(mod * TANGENT);
vec3 b = normalize(mod * BITANGENT);
mat3 TBN = transpose(mat3(t, b, n));
TangentFragPos = TBN * FragPos;
TangentLightDir = TBN * sun.Position.xyz;
TangentPlayerPos = TBN * playerPos;
}
In the fragment shader, I then select the normal vector from the normal map and use the converted tangent space vectors to calculate the specular highlights:
in vec3 FragPos;
in vec3 TangentFragPos;
in vec3 TangentLightDir;
in vec3 TangentPlayerPos;
uniform sampler2D normalMap;
void main()
{
[...]
vec3 normal = texture(normalMap, vec2(TexCoords * TextureScale) + vec2(Time)).xyz;
normal = normalize(normal * 2.0 - 1.0);
// normal = vec3(0.0, 0.0, 1.0); // this gives proper specular highlights, but not mapped
// Specular lighting
vec3 lightDir = normalize(-TangentLightDir);
viewDir = normalize(TangentPlayerPos - TangentFragPos);
vec3 reflectDir = normalize(reflect(-lightDir, normal));
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 64);
vec3 lighting = sun.Specular * spec * fresnel;
color.xyz *= lighting;
}
Please note that I am engaged in lighting in the global space.
Lighting works fine without a normal display, but as soon as I introduce the TBN matrix into the equations, the specular highlights are not in the right direction on the water.
EDIT
I added an image to see how it looks at the moment and where the specular light should be. This may add additional information about the problem:

EDIT2
. vec3(0.0, 0.0, 1.0) ( ), ( ), , , , . , , , , :

, ( ), ?