Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Help Wanted Intersection shader issue

Discussion in 'Shader Graph' started by joni-giuro, May 23, 2019.

  1. joni-giuro


    Nov 21, 2013
    Hi, I'm extending on one of Brackey's tutorials, specifically the one about the cartoon water. I have it working in my project and I'm trying to add a little white where the water plane meets any other object, to give the impression of a little foam forming there. The thing I get, instead, is that where the water meets other objects I can see the other objects through the water with a little white over them.

    I'll try to explain better with images.

    What I have (notice that you can see objects under water): have.jpg

    What I want (around the orange boat): bad.jpg
    Shader graph:
    Screenshot 2019-05-23 at 13.49.17.png

    Thanks a lot :)

  2. bgolus


    Dec 7, 2012
    That's precisely what that effect does. You're comparing the screen space depth between the water surface and the closest visible opaque object. For stuff like the beaches or other natural water edges, this works out great. For more man made objects like piers, posts, or boats, this fails quite badly as you clearly see that object is the only thing getting "foam".

    Some expensive solutions would be to do multiple samples of the "Scene Depth" node with offsets use the smallest difference from the water depth. But as this is a screen space thing, you'll have problems where some things that aren't actually intersecting the water may show "foam" if the distance test is too large, and quickly can get expensive or have noisy artifacts if you want to check against a large area. Plus it makes for a really painfully complex node graph (use a custom node can help there).

    The short version is you're seeing exactly the effect as you should expect it be. Making it look better is difficult and expensive. The better option, both visually and performance wise, is to not use this technique at all and instead use manually or dynamically placed meshes / particles around intersections.