I’ve been trying to emulate a glass of liquid that can be filled to any percent, in only two materials (glass container + liquid interior).
For the liquid, I’ve followed the techniques created by Tyler in this Polycount post: http://polycount.com/discussion/134716/faking-fluid-in-a-container-ue4 and NormalVector in this one over Reddit: https://www.reddit.com/r/unrealengine/comments/5vo5gi/helpquestion_how_would_i_create_a_liquid_plane_in/
Original material, for reference: Milky milky.. - Album on Imgur
The previous techniques rendered it as hollow, and used a hack with extra geometry and another material so the hole at the top is not visible. Based on those materials, I’ve tried to add vertex offsets to the top part of the material, where it isn’t rendered because of the fill mask. The idea was to collapse all the vertices over the fill height so instead of appearing as a hollow mesh, it has a cap.
It worked for basic shapes and rotations along the z axis, but my current material has a major flaw: It’s estimating the offset along the z axis, and that doesn’t work when the mesh is rotated on X or Y. The current result is projecting the vertices on a horizontal plane and looks weird.
Material graph:
Material function (this is the important part):
Some animated examples:
The vertices get dragged down on the global z axis, deviating from the mesh shape.
I think what I want is to offset the vertices along the object’s z axis before plugging that into (local coordinates), but I don’t know how to transform the coordinates so the vector follows the right orientation.
P.S: I know this material won’t work on meshes with wider caps than their bases, because the top vertices make a wider shape than the bottom ones. That is expected, and solving that problem, while possible, would make the material too complex. It might be better to simulate the liquid or make some approximations on a blueprint.