Prevent water from showing inside ship

How to prevent water from showing up in a hollow item which floats in water

Updated almost 2 years ago Edit Page Revisions

To prevent water from showing up inside an item which floats in the water (e.g. ship) you need to block it out with a 'Distance Field Replacement Mesh'

The water material will be able to use the distance field mesh to set an opacity mask on the material so the blocked out area won't be visible

HoleInWaterBeforeAfter.jpg

Material Setup

MaterialHoleInWater.jpg

Every pixel of a surface has a location in the world which you can retrieve with the 'Absolute World Position' node. The 'Distance To Nearest Surface' node calculates the distance from this point to the nearest mesh. If a point is inside a mesh the value will be negative. This value can be used to set the opacity mask, and this will make the material invisible when inside a distance field of a mesh. So in the setup above instead of using the actual mesh to create a distance field, a mesh which fills up to hole is used instead.

Mesh

Mesh with hole and blockout mesh: OriginalMeshAndBlockingMesh.jpg

In the settings of the mesh add the block-out mesh to the 'Distance Field Replacement Mesh':

BlockoutMeshSetting.jpg

Debug

You can visualise it in the editor via to show menu->Visualise->Mesh Distance Fields: DebugDistanceField.jpg

Note

In the project settings 'Generate Mesh Distance Fields' need to be enabled