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 Foam AROUND objects

Discussion in 'Shader Graph' started by ZerinLabs, Jun 18, 2020.

  1. ZerinLabs

    ZerinLabs

    Joined:
    Mar 8, 2019
    Posts:
    32
    Hi guys!

    I'm working on new cartoon water shader and I'm facing a problem:

    I would like to create a "foam edge" around the objects that are in contact with the water. But the problem is that, du I'm using "the depth" in order to find the cross-edge of the objects... I cannot "expand" the edge the way foam should appear "around" the object.

    It's a bit tricky to explain but I hope this images will help:

    this is what I have:
    upload_2020-6-18_9-32-9.png
    upload_2020-6-18_9-34-43.png
    Note that the depth-based foam edge on the cube follows the cube topology...

    Instad I would like something like this:
    upload_2020-6-18_9-43-18.png
    upload_2020-6-18_9-43-35.png
    Note that the edge is "around" the object, instead that "along" it's surface...

    Any ideas?

    Thanks in advance!
     
  2. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Yes, this is exactly the kind of information the depth gives you. There is no surrounding. Any advanced technique of doing this requires way more than Shadergraph is capable of. If you would use a texture, the foam won't look that bad. Most games do it exactly the same way. Nobody cares of exact foam.

    The other solution would be to manually place textures for each shore line: https://www.gamasutra.com/blogs/Mat...ate_a_semi_procedural_cartoon_foam_shader.php
     
  3. ZerinLabs

    ZerinLabs

    Joined:
    Mar 8, 2019
    Posts:
    32
    Thanks for the response.

    Yeah, it's what I was expecting... shader graph is ok for basic material shaders but it's clear that (at least for my understanding) it lacks from certain features to cover stuff like this (render-targets etc)
     
  4. makamekm

    makamekm

    Joined:
    Oct 21, 2020
    Posts:
    6
    Thank you! I followed the tutorial and achieved this nice looking view. You can autogenerate it by baking a render texture and generate the outline mesh.

    If you need to project it to the water, then just render the layer to a texture and pass it to the water shader.
     

    Attached Files:

    • 123.png
      123.png
      File size:
      267.1 KB
      Views:
      960
    • 124.png
      124.png
      File size:
      66 KB
      Views:
      897
    • 125.png
      125.png
      File size:
      345.1 KB
      Views:
      945
    • 126.png
      126.png
      File size:
      291.1 KB
      Views:
      816
    Last edited: Nov 9, 2020
    florianhanke likes this.
  5. KoolGamez

    KoolGamez

    Joined:
    Apr 11, 2020
    Posts:
    29
    Hi, I am looking to get the same effect. I tried to follow the shader graph you provided in your reply but I am not getting the same effect. Could you explain how I can achieve the foam around an object (I am relatively new to this, sorry)?
     
  6. makamekm

    makamekm

    Joined:
    Oct 21, 2020
    Posts:
    6
    1) Make a foam mesh in Blender.
    2) Make UV in Blender with only one axis Y to be valuable for all the polygons (Y = 0 then foam begins, Y = 1 then foam ends).
    3) Import it in Unity and then just use my shader.

    You can automate the process of generation that mesh by generating the tris and the uv, but this is for additional study.
     
  7. KoolGamez

    KoolGamez

    Joined:
    Apr 11, 2020
    Posts:
    29
    Hi, this is a really late reply but could you make the scene you created above open source? I am really struggling to understand how to get this effect. It would help if I can open the project and look at how it all works