# Hiding water surface inside a boat

**URL:** <https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851>\
**Category:** World Creation\
**Tags:** Water, hide, unreal-engine, question\
**Created:** [March 14, 2017, 12:19am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851 "2017-03-14T00:19:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_6157d2ee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6157d2ee](https://forums.unrealengine.com/u/anonymous_user_6157d2ee)\
**Post date:** [March 14, 2017, 12:19am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/1 "2017-03-14T00:19:23Z")

</div>

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](https://www.youtube.com/watch?v=-KNevBGhpxI) . Is there something that can help in UE4 ?

Thanks

---

<div class="post-metadata">

**Author:** ![c4tnt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@c4tnt](https://forums.unrealengine.com/u/c4tnt)\
**Post date:** [March 14, 2017, 3:24am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/2 "2017-03-14T03:24:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6157d2ee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6157d2ee](https://forums.unrealengine.com/u/anonymous_user_6157d2ee)\
**Post date:** [March 16, 2017, 7:13pm UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/3 "2017-03-16T19:13:43Z")

</div>

Can you please show to me a BP example ?

---

<div class="post-metadata">

**Author:** ![c4tnt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@c4tnt](https://forums.unrealengine.com/u/c4tnt)\
**Post date:** [March 17, 2017, 4:37pm UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/4 "2017-03-17T16:37:10Z")

</div>

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

 ![130530-enablecds.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/a/c/bacf2afc57f15da1a2bb4e6fbf983d7ea077bb7b.png)

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

![130531-enablestencilformesh.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/f/d/3fdc97e2b839a1bdd5f86454c4a07303b55d630e.png)

And create a material like that

![130534-mat_psw.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/0/f/f0f51d3b9cd5dba7dcdaaa314738cfec69e184aa.png)

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

![130535-wo_cds.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/2/2/322f6d951954cd9353b722d1e9e7ccb63e4dbaae.png)

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

![130536-with_cds.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/d/2/ed2662c2f1785a3a538ebdcc7acfa0bf500543ee.png)

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.

---

<div class="post-metadata">

**Author:** ![c4tnt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@c4tnt](https://forums.unrealengine.com/u/c4tnt)\
**Post date:** [March 17, 2017, 4:48pm UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/5 "2017-03-17T16:48:55Z")

</div>

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.

 ![130540-mat_psw.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/c/0/9c0e925be965c26175cfccab5e5c54a1884a6dc5.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6157d2ee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6157d2ee](https://forums.unrealengine.com/u/anonymous_user_6157d2ee)\
**Post date:** [March 17, 2017, 11:22pm UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/6 "2017-03-17T23:22:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6157d2ee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6157d2ee](https://forums.unrealengine.com/u/anonymous_user_6157d2ee)\
**Post date:** [March 17, 2017, 11:28pm UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/7 "2017-03-17T23:28:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![c4tnt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@c4tnt](https://forums.unrealengine.com/u/c4tnt)\
**Post date:** [March 18, 2017, 4:06am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/8 "2017-03-18T04:06:28Z")

</div>

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:

 ![130620-mf_shader.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/0/9/309c5fb920c7966dcc12291d8657840239fc968e.png)

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

![130651-mf_usage.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/3/5/235c5c3d6fdf149915bcfe75d361e38e3c4205d0.png)

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_38e5aa46](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_38e5aa46](https://forums.unrealengine.com/u/anonymous_user_38e5aa46)\
**Post date:** [January 1, 2019, 1:22am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/9 "2019-01-01T01:22:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dragoonsanddune](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dragoonsanddune](https://forums.unrealengine.com/u/Dragoonsanddune)\
**Post date:** [July 6, 2019, 1:11pm UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/10 "2019-07-06T13:11:39Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Artefix\_3D1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/artefix_3d1/32/558508_2.png) [@Artefix\_3D1](https://forums.unrealengine.com/u/Artefix_3D1)\
**Post date:** [August 6, 2022, 10:34am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/11 "2022-08-06T10:34:49Z")

</div>

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

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/7/7/277c4fdf172e2418fa1cdceec16a8cb7d775ed99.jpeg "Unreal Engine 5 (works in UE4) Mask water out of boat/ship hull") ](https://www.youtube.com/watch?v=mEyU18wwMcM)

---

<div class="post-metadata">

**Author:** ![Grot13](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/grot13/32/1008648_2.png) [@Grot13](https://forums.unrealengine.com/u/Grot13)\
**Post date:** [September 8, 2022, 4:54am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/12 "2022-09-08T04:54:51Z")

</div>

Thanks a lot Artefix, thats was very needed!

---

<div class="post-metadata">

**Author:** ![PersianLord19901](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PersianLord19901](https://forums.unrealengine.com/u/PersianLord19901)\
**Post date:** [April 26, 2023, 4:10pm UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/13 "2023-04-26T16:10:54Z")

</div>

I follow this video step by step but it doesn’t work for me, I don’t know what I’m doing wrong. I double checked everything many times with no profit. Any idea where the problem might be?

---

<div class="post-metadata">

**Author:** ![Agenaios](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Agenaios](https://forums.unrealengine.com/u/Agenaios)\
**Post date:** [July 30, 2023, 1:41am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/14 "2023-07-30T01:41:02Z")

</div>

_ **on UE 5.2.1** _

Hi,  
I’m totally new to UE5 (and UE in general), I’ve been googling and trying methods for two days now…

Eventually got [Artefix\_3D1](https://forums.unrealengine.com/u/Artefix_3D1) method (the youtube video linked a few posts above) to exhibit signs of working, but not quite…

“New users cannot post attachments”… srsl?

Ok, here goes verbal description:

1. (unchecked “affects terrain”, enabling this weird thing where moving the splines does not affect the “island” size, but instead a weird unsimulated water surface area)  
**the mask only works in the area between the splines (where waves and buoyancy is not simulated, so this is not usable)**  
also, making the area large enough will make whole masked-out squares

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/6/0f6a4e196dd350692b6776a72b62ca3b71e2b7c2.jpeg)

1. (video needed, but I am not allowed to post one, so…) the mask does actually work in the out-of-splined-properly-simulated area, but only fleetingly, and only in the editor, and only when you are moving the main “waterbodyocean” water level UP… as you are moving it up and down, while passing object in the down direction, nothing, and when you are moving up, the mask will show up as you are moving past the objects (fast enough), but will disappear again when you stop moving the water level…  
Beats me…

I’ve only started learning UE5 a 3 days ago, and I have already encountered 3 full-on bugs… What is this?

Any advice on how to successfully mask out water from the inside of a boat (in this case a hollowed-out submarine) would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![laggyluk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@laggyluk](https://forums.unrealengine.com/u/laggyluk)\
**Post date:** [August 5, 2023, 8:14am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/15 "2023-08-05T08:14:18Z")

</div>

> [@Agenaios](#):
>
> I’ve only started learning UE5 a 3 days ago, and I have already encountered 3 full-on bugs… What is this?

Get used to that, there’s a lot of bugs and weird behaviors with this water.  
For masking water out of submarine I’m using both distance field test and cutting out a hole in water surface where the boat is… neither seems reliable enough on it’s own.  
I’ve made a snippet a while ago for the hole thing

> **[Water hole mask | Unreal engine Code Snippet](https://dev.epicgames.com/community/snippets/NP4/water-hole-mask)**
>
> Adding a hole to WaterBodyOcean material copy

just make sure you are not editing original water materials, copy them or they will be reset to default if you upgrade engine version or reinstall.

---

<div class="post-metadata">

**Author:** ![M.S.M.A.S](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@M.S.M.A.S](https://forums.unrealengine.com/u/M.S.M.A.S)\
**Post date:** [December 12, 2024, 11:36pm UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/16 "2024-12-12T23:36:34Z")

</div>

the first image you posted is kinda broken, I cannot make sense of what i am seeing here!!  
I dont use blueprints but I think the lines should be connected

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/8/0/38022e6aacb8d4799876c87752bf4f5766e61efe.png)

---

<div class="post-metadata">

**Author:** ![laggyluk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@laggyluk](https://forums.unrealengine.com/u/laggyluk)\
**Post date:** [December 15, 2024, 9:09am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/17 "2024-12-15T09:09:38Z")

</div>

those are not images I posted, it’s bp code in text format that some script tries to render. looks fine here. you can try and copy paste the snippet into your bp with ‘copy full snippet’ button

---

<div class="post-metadata">

**Author:** ![M.S.M.A.S](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@M.S.M.A.S](https://forums.unrealengine.com/u/M.S.M.A.S)\
**Post date:** [December 19, 2024, 2:54am UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/18 "2024-12-19T02:54:43Z")

</div>

I have a question for you, if you are looking at a sunken boat from outside the water will the water outside the boat render in this solution??

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [December 19, 2024, 12:56pm UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/19 "2024-12-19T12:56:54Z")

</div>

I believe that regardless of what you are doing, if the boat sinks you just change the shell stencil value to something else or flat out replace it to a different mesh, which is not set to the special stencil value…

---

<div class="post-metadata">

**Author:** ![laggyluk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@laggyluk](https://forums.unrealengine.com/u/laggyluk)\
**Post date:** [December 21, 2024, 12:30pm UTC](https://forums.unrealengine.com/t/hiding-water-surface-inside-a-boat/387851/20 "2024-12-21T12:30:47Z")

</div>

if you look at the sunken boat from outside it’s enough to use distance field test only and it should work fine.
