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

Question Grass taking the color underneath it

Discussion in 'Shader Graph' started by ImperialDragon98, Jan 17, 2020.

  1. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
    I'm currently working on a grass shader and i'm wondering how to make the grass get the color underneath it. So if the ground is grey the grass will turn grey if its on top of it? I cant find much online about it except this video

     
  2. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
    Still need help on this
     
  3. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,446
    You can do this by grabbing the basemap generated for the terrain (or rendering out the albedo of the terrain yourself to a texture) and sampling that in the shader.
     
  4. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
    How would I go about grabbing the basemap generated for the terrain?, by terrain does this only work with unity terrain system or can any model of terrain work with this method? And what nodes would I use to sample it into the shader graph?
     
  5. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,446
    You'd have to do it via C# script (with mat.GetTexture("_MainTex")) and pass it to your material as a texture. There might be an api on terrainData for it in newer unity version, not sure. For non-unity terrains you'd have to generate this texture yourself.
     
  6. snowandball

    snowandball

    Joined:
    Apr 11, 2019
    Posts:
    22
    Did you found a solution? I am not a programmer and i am trying to achieve the same functionality.