Creating Bottled Liquid Physics for VR in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
approximating bottled liquid physics is something that i've been wanting to do for a while now because interacting with opaque or empty bottles especially in vr just isn't the same this project has some pretty humble beginnings initially it was just a shader to mask out a given texture below some number relative to the object's position creating a surface point to make this look less like a cylinder dipped in black printer ink and more like a cylinder containing actual liquid i made the cylinder's surface translucent before drawing the masked portion separately in the shader this allowed me to disable backface culling so you could see the masked bottom through the translucent top at this point though an issue i knew i would have to solve was due to the cylindrical shape of the liquid's bottle the masked liquid portion would phase in and out as the lowest point of the bottle changed with its rotation i realized that this could be solved by offsetting the liquid surface point by the angularity of the cylinder and after some experimentation i found a mostly reliable way of doing this from an external c-sharp script calculating this offset by getting the average of the dot products of the bottle's local axes and the world's axes mostly fixed the issue with only some tweaking to the calculations needed before continuing to refine the liquid's movement behavior i decided to enhance its appearance so that it appeared as real palpable liquid rather than just an unlit mask this consisted of two tasks adding lighting effects to the liquid and faking a surface above the mask portion for the former i decided on simple rim lighting using the dot product of the camera's view direction and the bottle surface normal to determine the rim of the liquid i also factored in the liquid's distance from its surface point to fake a surface to the liquid i rendered the bottle again masked the liquid portion drew only the back faces and set the vertex normals to the bottle's local up direction by now the liquid effect itself was pretty solid though it still lacked any approximation of inertia which resulted in quite an unnatural look to fix this i would need a vector that could shear the plane of the liquid surface based on the inverse direction of acceleration and a scalar that depended on the acceleration of the bottle's rigid body i calculated these values in our c-sharp script using information from our rigidbody component after implementing this i also offset the amount of surface shearing by the sine of the current time multiplied by some arbitrarily large number in order to add some extra liquid sloshing for the final step i quickly modeled a plastic bottle to put the liquid into rather than the primitive cylinder we've been using all along this worked well and it was complemented with the addition of carbonation though unfortunately the effect quickly broke down when viewed stereoscopically in vr so i had no choice but to leave it out for now you might also notice that i ended up cranking the rim lighting effect way up in order to add a glow this would draw more attention to the liquid and will come in handy later for gameplay reasons so after tentatively placing some of the soda around the scene you can clearly see the extra level of subtle interaction that the liquid physics adds to the experience [Music] thanks for watching this video and if you liked it then don't forget to subscribe if you want to see more of my content in the future [Music] you
Info
Channel: Lone Developer
Views: 15,433
Rating: undefined out of 5
Keywords:
Id: p9NeBW4pgGk
Channel Id: undefined
Length: 3min 41sec (221 seconds)
Published: Fri Dec 18 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.