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 Shader Graph help with terrain shader

Discussion in 'Shader Graph' started by shakedlevy, May 11, 2023.

  1. shakedlevy

    shakedlevy

    Joined:
    Apr 18, 2015
    Posts:
    6
    I am new to shader graph currently using URP Lit shader.
    I have a procedural generated terrain and want to color it with a gradient based on each face Y position i cant figure it out please help me.
    thanks in a advance
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,456
    Take world position and lerp color based on it?
     
  3. shakedlevy

    shakedlevy

    Joined:
    Apr 18, 2015
    Posts:
    6
    its change all terrain color based on the object Y location not each vertex
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,456
    You can use the object node and take the position
     
  5. shakedlevy

    shakedlevy

    Joined:
    Apr 18, 2015
    Posts:
    6
    thanks but this way the value is clamped 0 1 and it is not relative to the highest and lowest point of the terrain
    beside entering the value manually i cant figure out how to do so
     
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,456
    Either make a custom node and add a vector array into the shader, or simply push the value you want to the shader via c# (might be easier than calculating the range every frame on the GPU if you can cache it on CPU)