Download

Rotating World Position Offset along mesh rotation - Liquid material

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.

I’m still stuck on this. There are other ways to accomplish this with blueprints and custom geometry, but I think this could be done with only one mesh and one material. Any ideas? Thanks.

This is pretty much the exact same issue I’m running in to now. I’ve been following the same breadcrumbs and ended up with the same surface plane problem you have. Block colour seems to mask the other approaches well but if you want any kind of texture the illusion falls apart since there’s no cap. After looking for various ways around this I’ve finally come across this post. I don’t suppose you ever managed to come up with a solution to this?

Or if you didn’t, I guess this is a good time to bump it and ask if anyone has any ideas how this problem can be solved either by vertex offsetting as shown here or any other approaches.