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 ?

Thanks

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)

130531-enablestencilformesh.png

And create a material like that

130534-mat_psw.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

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

130536-with_cds.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.

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

130651-mf_usage.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.

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.

3 Likes

Thanks a lot Artefix, thats was very needed!

1 Like

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?

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 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

  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.

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

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.

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

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