Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Water Transparency and Color based on distance from Island

Discussion in 'Shader Graph' started by ImperialDragon98, Dec 10, 2019.

  1. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
    Im new to unity shader graph and I have no clue how to make it so the water changes from light blue to dark blue depending on how far away it is from an island. I also want the water to change transparency based on deep the water is. I've looked online everywhere and cant find anything on it, It would be very appreciated if someone could help me or find me documentation.
     
  2. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    Try something like this as a start. Instead of 'how far away from the island' it's more based on depth but I assume the water is getting deeper further away from the island so this works.



    And here is some information about what I'm doing.







    Let me know if you need more information.

    There is an abundance of tutorials online on how to create water with a simple 2-color gradient.

    I recommend this one if you want more. https://roystan.net/articles/toon-water.html

    It is not specifically for shader graph but the logic stays the same.

    Edit: Be sure your shader master node is set to have a transparent surface. Also make sure that your renderer is generating a depth texture.
     
    Last edited: Dec 11, 2019
    florianhanke likes this.
  3. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
  4. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    What values are you using for your colors?

    I used alphaclip 0, light blue for color A with a bit of transparency, then dark blue for color B with 0 transparency.

    Also I use URP, I don't know what any differences might be with HDRP.
     
  5. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
    Do you think HDRP would be the problem or the fact my shader graph was out of date?
     
  6. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    No idea, I don't understand what issue you are having. What issue are you having and what values are you using for your material?
     
  7. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
    http://prntscr.com/q92ycz I managed to fix it by changing the alpha on the color itself didnt realise it was all the way down lol, Im still having a problem now only the deep water is showing up the shoreline water isnt there
     
  8. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    Play with the distance value. It will determine how much of the water is seen as 'shallow' or 'deep'.
     
  9. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
    It worked but Im having one more problem the shoreline render distance is terrible do you know to fix it? http://prntscr.com/q9302h
     
  10. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    Try to add this. Is that what you mean with render distance?



    And I mean yeah you're getting a depth difference using distance from camera. You can't come too close to the water. It's a limitation of the technique.
     
  11. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
    Thanks so much it works perfectly, may I ask a question what is the difference between unlit graph and lit graph?
     
  12. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    You can use lit if you want.

    Lit means the material will be influenced by the light in the scene.

    Unlit means the material will not be influenced by the light in the scene.

    I usually just use unlit first to focus on the shader itself.

    When you use lit you get extra properties like smoothness, metalicness etc which relate to how the material surface reacts to the light it receives.

    Do you understand the water shader btw? With the explanation I added.
     
  13. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
    I understand the explanation, For some odd reason the newest version of unity 2019.2.17f1 breaks this effect and it doesnt work anymore. No matter how much I play with the settings nothing works. http://prntscr.com/qnqznt
     
  14. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,816