Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Tutorial] how to calculate vertex normals in shader graph

Discussion in 'Community Learning & Teaching' started by gamedevbill, Feb 22, 2020.

  1. gamedevbill

    gamedevbill

    Joined:
    May 25, 2018
    Posts:
    43
    Last edited: Jan 26, 2021
    Ciderhelm, lilacsky824 and shamsfk like this.
  2. gamedevbill

    gamedevbill

    Joined:
    May 25, 2018
    Posts:
    43
    shamsfk likes this.
  3. Zicore

    Zicore

    Joined:
    Jul 2, 2018
    Posts:
    10
    This is a really great tutorial! However I have a hard time to get it running in my experiment.
    Maybe you can give me some tips.

    I basically create a crater like shape with this sub graph:


    Using your Neighbors and NewNormal Subgraphs here.


    The resulting mesh looks like this:


    Calculating the normals doesn't work.

    I'm pretty sure it's because I'm using the World Position in my displacement part, and only add the Y part later, but I don't know how to incorporate your neighbor sub graph correctly.
     
  4. gamedevbill

    gamedevbill

    Joined:
    May 25, 2018
    Posts:
    43
    I just saw this question... Yeah, the world position is a good guess, but i would have thought it'd still work. I'll try to build a test project from your screenshot in a week or so. I'll update here once i have something.

    Thanks
    gdb
     
  5. gamedevbill

    gamedevbill

    Joined:
    May 25, 2018
    Posts:
    43
    Ok, I've looked into it. The issue is that your "DispalceSub" graph is not actually outputting a position. It outputs xyz=[0,offset,0]. You correctly calculate that offset for the neighbors, but are feeding in a value to the normal calculator that has x & z components both set to 0.

    What you need to do is change DisplaceSub to include both positions as an input. Take the PositionWorld at the front end (as you currently do), then at the end, take PositionObject as an additional input and add it in before returning.

    upload_2020-7-26_19-1-52.png

    This wraps your entire vertex displacement into one subgraph. Then to do the normal calculations, you'll have to have two "Neighbors" nodes. One that calculates neighbors in world space, and one in object space.

    Then it works. Hope this helps.
     
  6. Zicore

    Zicore

    Joined:
    Jul 2, 2018
    Posts:
    10
    Thanks! I'm sure this will help!
     
    gamedevbill likes this.
  7. gamedevbill

    gamedevbill

    Joined:
    May 25, 2018
    Posts:
    43
    I've made this tutorial into a video! Be sure to check it out in the start of the thread above!
     
  8. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    Hello how this possible to recalculate normals for blend shape?