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. Dismiss Notice

Question Is it possible to get the normal of the vertex of the terrain in the shader?

Discussion in 'Shaders' started by Zimaell, Sep 7, 2023.

  1. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    341
    I'm interested in the age-old question about stretching the texture on the tops of the terrain, which have a big difference, that is, on steep descents and ascents.

    Of course, the simplest way is a triplanar, but although it is easy to add it (for example, to a shader graph), it has big drawbacks, for example, there are a lot of stripes at the junctions.

    so I want to use the right textures on the right surfaces, if I'm not mistaken, if you know the normal of the vertex, you can understand what kind of stretch it has, that is, what kind of slope, in accordance with this, you can apply the desired texture.

    I know how to get the vertex itself, I was told - the world position and then only the Y height is cut off by the mask. but is it possible to get normal?

    to thus understand what slope.
    Or what is the best way to calculate how much the texture should stretch for normal display?

    I'm already doing the calculations for texture selection in the custom node, so I just need to get the normal right.
     
  2. POOKSHANK

    POOKSHANK

    Joined:
    Feb 8, 2022
    Posts:
    73
    you should be able to get the normal just by passing it in the vert stage of the shader
     
    Zimaell likes this.
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238
    The normal is usually passed along with the other data to the fragment shader, as it's needed for shading.