Hello,
I’m having a noticeable sharp edges when appying normal map shading effect over a mesh, as it can be seen below:
This effect get stronger the more deformed the mesh is, for a plane mesh this is not visible at all, the more deformation (height variation in this case) the more this is noticeable.
But when not appying the normal map, those edges are smoothed out as it should be, as the normals are averaging well)
this is my code to perform the normal mapping:
varying vec3 vNormal;
varying vec3 vPos;
varying vec3 uvs;
if(object.normal_map){
vec3 map = normal.rgb * 2.0 - 1.0;
mat3 TBN = computeTBN(vNormal, vPos, uvs);
vNormal = normalize(TBN * map);
}
and the method computeTBN is calculating the tangent and bitangent on the Frag Shader
mat3 computeTBN(vec3 N, vec3 p, vec2 uv){
// get edge vectors of the pixel triangle
vec3 dp1 = dFdx(p);
vec3 dp2 = dFdy(p);
vec2 duv1 = dFdx(uv);
vec2 duv2 = dFdy(uv);
// solve the linear system
vec3 dp2perp = cross(dp2, N);
vec3 dp1perp = cross(N, dp1);
vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;
vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;
// construct a scale-invariant frame
float invmax = inversesqrt(max(dot(T,T), dot(B,B)));
return mat3(T * invmax, B * invmax, N);
}
I’ve trying to search fro this issue on the web to no avail so far. Is there any known name for these artifacts I can look up for and read? Or is there any solution I am missing out?
In my point of view this seems linke some tansformation I must be missing and not applying correctly to the mesh in order to recognize the correct direction of the primitive, but so far haven’t got any good result.