I am currently experiencing a very obvious artifact that only occur when I use normal maps. However it only occurs when looking at surfaces on very grazing angles.

Here is a picture of the artifact: normal artifact

And here is an image of the normals: normals

I will also post the vertex and fragment shader code for unpacking normals maps:

Vertex Shader Snippet:

vec3 T = normalize(normalMatrix * tangent);
vec3 B = normalize(normalMatrix * bitangent);
vec3 N = normalize(normalMatrix * normal);
TBN = mat3(T, B, N);

Fragment Shader Snippet:

vec3 normal = texture(material.texture_normal, TexCoords).rgb;
normal = normalize(normal * 2.0f - 1.0f);
normal = normalize(TBN * normal);

I would really appreciate if anyone has ever experiences this kind of artifact. Is it my BRDF, is it my normal calculations? I am not sure.. I would appreciate any insight people have!

If you want to see my fragment shader and my BRDF you can find the code here:

https://github.com/Ershany/Arcane-Engine/blob/WIP_PBR/Arcane%20Engine%20Core/src/shaders/pbr_model.frag

Thank you!

  • 1
    Have you tried calculating the TBN in the fragment shader? When calculating it in the vertex shader, OpenGL will linearly interpolate the matrix for use in the fragment shader and that might cause the artifacts. Do make sure that you normalize the tangent, bitangent and normal in the fragment shader before using them (again because of the linear interpolation). – bram0101 Oct 9 at 6:36
  • Yes I tried to do this in the fragment shader and normalized the vectors before, and I still get these strange artifacts – Brady Jessup Oct 9 at 13:55
  • Tangents are multiplied by the model matrix, as they dont suffer from non-uniform scale disortion as normal vector do. Also, you do need a vertex normal and a normal vector extracted from the normal map, however, I see you are applying the normalization (normalize(normal * 2.0f - 1.0f)) to the same vector you used to create the TBN matrix – Nadir Oct 10 at 14:34
  • I thought the tangents and bitangents would also suffer from possibly being non-orthogonal to each other if scaled non-uniformly. Also I edited my fragment shader code above to showcase that I am actually sampling the normal from the normal map. My bad! – Brady Jessup Oct 10 at 16:51
  • 1
    Have you identified which part of the code generates the color of the artifact? Have you tried to reduce your shader to a minimal reproduce case? I wouldn't be surprised if it was due to either a normal facing away from light, or a nearly 0 but negative parameter to a pow() function. – Julien Guertault Oct 11 at 4:35

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.