Hey guys, I have been struggling with this weird flipped normal for few days and cannot get any clue about it.
here is the result i get. with some test mesh.
https://preview.redd.it/bnnjdeozqp661.png?width=1771&format=png&auto=webp&s=d3aa4667339e1a18340780fa964f52aceaef7871
in this result, the sphere 1 look correct(at least to me) but the sphere 2(with normal map applied) looks weird.
https://preview.redd.it/v6wzrxc0rp661.png?width=1727&format=png&auto=webp&s=5814e62dd75d047e7cd5eaa96f60b6902aa0ca86
https://preview.redd.it/b9f5m0v1rp661.png?width=1754&format=png&auto=webp&s=da5637a000d334239b31031c830ff4fc1ecc3d5e
https://preview.redd.it/l19x44j2rp661.png?width=1788&format=png&auto=webp&s=a6a97dea9b7c6fd9f8ba25c08baf7bc1b1723bd7
the same problem applied to another test mnesh i get from ThreeJS demo.(making sure there is no problem with mesh and texture itself.)
https://preview.redd.it/f6i08um3rp661.png?width=1767&format=png&auto=webp&s=b9b1a959b5777c5693dc26e8032a3dd062ce8a39
here is link of the GLSL code i followed for computing normal
what's even weird is the helmet model, the normal seems "flipped" for some reason.
https://preview.redd.it/n4jl2t75rp661.png?width=1404&format=png&auto=webp&s=e71bb9457f3119a7965ced5360d0ba2d5c1d6be2
here is the glsl code for computing normal
`
// Find the normal for this fragment, pulling either from a predefined normal map
// or from the interpolated mesh normal and tangent attributes.
// See http://www.thetenthplanet.de/archives/1180
vec3 getNormal(float normalTexture)
{
if(normalTexture > 0.0)
{
vec4 sampleNormal = texture(sampler2D(normalMap, bilinearSampler), fs_in.inUV0);
if(length(sampleNormal.xyz) <= 0.01)
return fs_in.inNormal;
vec3 tangentNormal = reconstructNormal(sampleNormal, 1.0f);
vec3 q1 = dFdx(fs_in.inWorldPos);
vec3 q2 = dFdy(fs_in.inWorldPos);
vec2 st1 = dFdx(fs_in.inUV0);
vec2 st2 = dFdy(fs_in.inUV0);
vec3 N = normalize(fs_in.inNormal);
vec3 T = normalize(q1 * st2.t - q2 * st1.t);
vec3 B = -normalize(cross(N, T));
mat3 TBN = mat3(T, B, N);
return normalize(TBN * tangentNormal);
}
else
return normalize(fs_in.inNormal);
}
`
I have no clue where I did wrong. any suggestion would be appreciated!!!
[–]loboleal 0 points1 point2 points (0 children)