Search Unity

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:
    352
    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.
     
  4. jalajshah

    jalajshah

    Joined:
    Mar 5, 2018
    Posts:
    62
    can you share your shader ?
     
    khos likes this.