Search Unity

Question calculate smooth vertice normal without flat normals

Discussion in 'Shaders' started by Isomania, Jul 30, 2022.

  1. Isomania

    Isomania

    Joined:
    Jan 28, 2021
    Posts:
    16
    My mesh is uniformed structured in the XZ plane like the image shows, with their Y values displaced at random. And I want to calculate each vertex 100% smoothed normal.

    What you would to to calculate the smoothed normals for each vertex is to first calculate each normal for each triangle using this or simmilar:
    Code (CSharp):
    1. triangleNormal = normalize(
    2.     cross(
    3.         vertice1 - vertice2,
    4.         vertice3 - vertice2
    5.     )
    6. );
    And then take the norm of each connected triangle for each vertex, in my case the eight triangles from the neighbouring four quads.

    My question is however, very case specific: In that; is there a way for me to calculate the 100% smoothed vertice normals given ONLY the (8+1) vertices around any given vertice in my gridded mesh? Using the fact that they are in a locked grid, and that I know which 9 vertices would change a vertices smooth normal, I should be able to create a really optimized calculation? no?

    Im coding it in a compute shader.