Search Unity

Problem with Normals on Procedural Mesh

Discussion in 'General Graphics' started by onyx3910, Apr 3, 2020.

  1. onyx3910

    onyx3910

    Joined:
    Dec 12, 2019
    Posts:
    5
    Hey all,

    I'm working on a game that has procedural levels using metaballs and marching cubes. The normals are generated by a gradient function I sourced from here: https://blackpawn.com/texts/metanormals/default.html

    However, while it's close to being correct, there's still some things going wrong.

    1. The normals appear to still be biased towards the center of mass for all the metaballs
    2. The spotlight I'm using is only shining light on a certain angle
    I'm unsure if the normals are breaking the spotlight or not. I don't believe it's the Triplanar shader I'm using as swapping it out with a regular standard surface shader produces the same results with the spotlight.

    upload_2020-4-3_8-26-39.png

    Just in case I'm visualizing my normals wrong, here's the debug code:
    Code (CSharp):
    1. Gizmos.DrawLine(Mesh.vertices[i] + transform.position, Mesh.vertices[i] + transform.position + Mesh.normals[i]);
    Any thoughts? Any other code or information I should provide?

    Thanks,
    Onyx
     
  2. onyx3910

    onyx3910

    Joined:
    Dec 12, 2019
    Posts:
    5
    Found the issue. I wasn't weighting the normals coming from the gradient calculation. All normals from all metaballs had equal weight. Now I divide that normal by the distance from the metaball. The greater the distance, the less influence the metaball has on the normal.