Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    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. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    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:
    320
    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.