It happened because Because I calculate the tangent on each face, normal and normal, and completely ignore the normals I get from the model file.
Calculate the two sides of the current triangle and texture space vector to get the tangent sum The secondary normal is then used to calculate the normal through the cross product. Once the model is loaded, this is all done on the CPU, and then the value is stored as part of the model’s geometry.
vector1 = vertex2.coords-vertex1.coords;
vector2 = vertex3.coords-vertex1.coords;
tuVector = vertex2.texcoords-vertex1.texcoords;
tvVector = vertex3. texcoords-vertex1.texcoords;
float den = 1.0f / (tuVector.x * tvVector.y-tuVector.y * tvVector.x);
tangent.x = (tvVector.y * vector1.x-tvVector.x * vector2.x) * den;
tangent.y = (tvVector.y * vector1.y-tvVector.x * vector2.y) * den;
tangent.z = (tvVector.y * vector1.z-tvVector.x * vector2.z) * den;
binormal.x = (tuVector.x * vector2.x-tuVector.y * vector1.x) * den;
binormal.y = (tuVector.x * vector2.y-tuVector.y * vector1.y) * den;
binormal.z = (tuVector.x * vector2 .z-tuVecto ry * vector1.z) * den;
D3DXVec3Normalize(&tangent, &tangent);
D3DXVec3Normalize(&binormal, &binormal);
D3DXVec3Cross(&normal, &tangent, &binormal );
D3DXVec3Normalize(&normal, &normal);
Is there a way to calculate these values on a per-vertex basis, maybe use the normals provided by the model or smooth them in some way so Does the model have facets?
>Create space for each vertex
double N[3]; //normal
int cnt;
>each Vertex init
N={0.0,0.0,0.0}
cnt=0;
>Calculated by face is normal
< p>normal must be normalized length = 1.0!!! Add this Normal to all vertices used in the face, and add cnt to all vertices used in the face
>Standardize each vertex
< /p>
N/=cnt; // N = average normal from all vertex-neighbour faces
Note the cnt of unused vertices = 0 (divide by zero)
>each vertex N contains the normals you want
Now, calculate the T, B vectors of the TBN matrix (each vertex) like now.
>The output image is smooth
My Earth The preview (atmospheric scattering, bump map, etc.) is here
I hope to help you
I am trying to add the bump map function to mine Application, but I am getting a very multi-faceted model:
It happened because I calculated the tangent on each face, normal and normal, and completely ignored me from the model file The obtained normal.
Calculate the current two sides of the triangle and the texture space vector to obtain the tangent and the subnormal, and then use it to calculate the normal through the cross product. Once the model is loaded, all this is in It is done on the CPU, and then the value is stored as part of the model geometry.
vector1 = vertex2.coords-vertex1.coords;
vector2 = vertex3.coords-vertex1. coords;
tuVector = vertex2.texcoords-vertex1.texcoords;
tvVector = vertex3.texcoords-vertex1.texc oords;
float den = 1.0f / (tuVector.x * tvVector.y-tuVector.y * tvVector.x);
tangent.x = (tvVector.y * vector1.x-tvVector.x * vector2.x) * den;
tangent.y = (tvVector.y * vector1.y-tvVector.x * vector2.y) * den;
tangent. z = (tvVector.y * vector1.z-tvVector.x * vector2.z) * den;
binormal.x = (tuVector.x * vector2.x-tuVector.y * vector1.x ) * den;
binormal.y = (tuVector.x * vector2.y-tuVector.y * vector1.y) * den;
binormal.z = (tuVector.x * vector2.z-tuVector .y * vector1.z) * den;
D3DXVec3Normalize(&tangent, &tangent);
D3DXVec3Normalize(&binormal, &binormal);
D3DXVec3Cross(&normal, &tangent, &binormal);
D3DXVec3Normalize(&normal, &normal);
Is there a way to calculate these values on a per-vertex basis, maybe use the normals provided by the model or smooth them in some way, So that the model will not be faceted?
For smooth surfaces (no edges), I do this:
>Create space for each vertex
p>
double N[3]; //normal
int cnt;
>each vertex init
N={0.0,0.0,0.0}
cnt=0;
>Calculate normal by face
Normal must be standardized length = 1.0 !!! This Normal is added to all vertices used in the face, and cnt is added to all vertices used in the face
>Every vertex is normalized
N/=cnt; / / N = average normal from all vertex-neighbour faces
Note the cnt of unused vertices = 0 (divide by zero)
>Each vertex N contains the normal you want
Now, calculate the T and B vectors of the TBN matrix (each vertex) like now.
>The output image is smooth
My earth preview (atmospheric scattering, bump mapping, etc.) is here
I hope I can help you