Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

My realistic liquid shader

Discussion in 'Made With Unity' started by jackle1127, Nov 2, 2018.

  1. jackle1127

    jackle1127

    Joined:
    Aug 29, 2018
    Posts:
    2


    I wrote this liquid shader a while back when I was working on a liquid effect for my job. Basically the way it works is that it renders the liquid volume in 2 passes: a front face (back face culled) pass and a back face (front face culled) pass. There's a world space level where both the passes cut off at. On the back face pass, I tapped into the generated code for the surface shader and modify the normals of the pixels so that they face straight up the liquid's "up" direction. Then I modified the world space position of the pixel so that they lay right on top of the liquid surface. This also helped me calculate the custom depth for each of the pixel. I also applied a world space normal map on it to create the ripples. For the sloshing effect, I hung a weight on the center of the liquid volume using a spring joint. I hung 2 more weights with slightly different spring strengths to create the random ripple effect. The refraction uses a grab pass so it also "refracts" the objects in front of it. There's no way around this D:
     
    khos, Mauri, CrazyDud99 and 2 others like this.
  2. Shayke

    Shayke

    Joined:
    Dec 8, 2017
    Posts:
    326
    How did you do that?
    I dont even know how to do it in 2D.
    The liquid is an object?
     
  3. jackle1127

    jackle1127

    Joined:
    Aug 29, 2018
    Posts:
    2
    The liquid is a 3D Mesh. It has a shader on it that discards anything above the liquid surface.