For smooth surfaces (no edges) I do it like this:
-
create space for per vertex
double N[3]; //normal int cnt;
-
per vertex init
N={0.0,0.0,0.0} cnt=0;
-
compute per face normal
normal must be normalized length=1.0 !!! add this
Normal
to all vertexes used in face and incrementcnt
to all vertexes used in face -
per vertex normalize
N/=cnt; // N = average normal from all vertex - neighbour faces
be aware of
cnt=0
for unused vertexes (division by zero) -
per vertex
N
contains the Normal you wantnow compute
T,B
vectors for TBN matrix (per vertex) as you do now -
output image is smooth
My earth preview (with atmospheric scattering, bump mapping and more…) is here
hope it helps