How to Eliminate Faceted Appearance in Bump Mapping with Smooth Tangent Space Normals
In efforts to incorporate bump mapping, users may encounter faceted appearances in their models. This occurs due to the calculation of tangent, binormal, and normal values per face, disregarding the normals provided in the model file.
To address this, consider calculating these values per vertex instead. One approach is to utilize the normals provided with the model and smooth them out to eliminate the faceted appearance. Here's how:
Create Space for Per-Vertex Values:
double N[3]; //normal int cnt;
Initialize Per Vertex:
N={0.0,0.0,0.0} cnt=0;
Compute Per-Face Normal:
Calculate the normal for each face. Ensure the normal is normalized to a length of 1.0. Add this normal to all vertices used in the face and increment the cnt for each of those vertices.
Normalize Per Vertex:
N/=cnt; // N = average normal from all vertex - neighbour faces
Be wary of cnt being 0 for unused vertices (avoiding division by zero).
Compute Tangent and Binormal Vectors (TBN Matrix):
After normalizing the per-vertex values in N, compute the tangent (T) and binormal (B) vectors for the TBN matrix using existing methods.
Smooth Output:
Using this approach, each vertex now contains a smoothed normal. This ensures that the outputted image will appear smooth.
By following these steps, users can effectively eliminate the faceted appearance in their bump-mapped models and achieve smooth tangent space normals.
The above is the detailed content of How to Achieve Smooth Bump Mapping by Smoothing Tangent Space Normals?. For more information, please follow other related articles on the PHP Chinese website!