Hiding water surface inside a boat

Hi I am new to UE and I am trying to hide water inside a boat. In unity 3d there was a script Unity 5 Pro boat simulator - depth mask for water surface removal - YouTube . Is there something that can help in UE4 ?


You can enable custom depth rendering to render boad to a custom depth\stencil buffer. Enable it for your boat and set stencil value to 1 for example. In water material you have to set water alpha to 0 on any pixel which has stencil == 1

Can you please show to me a BP example ?

It is just material settings, not a blueprint. To create this effect you have enable render custom depth\stencil inside your project settings first.

Then you have to enable custom depth rendering for your mesh (inside mesh properties)


And create a material like that


This material compares current stencil buffer value with the given constant (I used 25, it doesn’t matter) and chooses the alpha for water between 0 and other value.

With this material as water and any static mesh you will get something like this


Until you enable custom stencil and specify stencil value greater than used in material.


To get best effect you have to separate your boat mesh to two parts: inner and outer. And enable custom depth stencil on both parts but set stencil value > 25 for inner part and < 25 for outer.

1 Like

Improved a bit. This shader utilizes not only custon stencil but the depth too. It does not require rendering boat’s exterior with enabled custom depth and will handle intersections with the world better.

That was very helpful and I want really to say a big thank you.
The problem is that this technique is can not be used by modifying the ue4 ocean water.
Is there a work around to make is work with opaque materials ?

Many thanks.

I tried to use your technique on the translucent water that come with UE4 but it is too complicated to use it. Can you help ?

Big thanks.

I packed this to the separate MaterialFunction [MaterialFunction][1]
Not sure that it possible to load directly from UE (you can try to copy this asset directly to your cintent folder)

It contains exactly this:

To insert this inside your material add CallCustomFunction node and connect it as shown on a picture


Stencil value input allow you to select working stencil value (less than boat interior and greater than boat exterior), by default it is 128

Unfortunately this can not be used with opaque and masked materials. On them depth buffers are inaccessible to read, Maybe it will be possible to pre-bake your boat depths picture each frame before rendering whole scene and use PixelDepthOffset to push water out from a boat. So, if your boat have near-square deeping it is possible to evaluate required PDO without any extra rendering, and both of these ways are bit complicated.

This works for ES5, anyone know of a solution that works for ES3.1/Mobile? cant use scene nodes.

ok so i followed all of your example… I am using Dev kit for CE which is v4.15.3 Annndddd I cannot get this to work

And i did test if 0 or 1 was working for visible but for some reason its not looking at the render stencil to determine what pixel it should be at >< anyone know why ?

I made a tutorial video for masking water out of the boat.


Thanks a lot Artefix, thats was very needed!

1 Like