Home  >  Article  >  Backend Development  >  How to Achieve Smooth Bump Mapping by Smoothing Tangent Space Normals?

How to Achieve Smooth Bump Mapping by Smoothing Tangent Space Normals?

Susan Sarandon
Susan SarandonOriginal
2024-10-28 05:59:30514browse

How to Achieve Smooth Bump Mapping by Smoothing Tangent Space Normals?

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:

  1. Create Space for Per-Vertex Values:

    double N[3]; //normal
    int cnt;
  2. Initialize Per Vertex:

    N={0.0,0.0,0.0}
    cnt=0;
  3. 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.

  4. 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).

  5. 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.

  6. 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn