How to Use Depth Mask to Hide Water in Boats in Unity

  Рет қаралды 33,386

Philip Herlitz

Philip Herlitz

Күн бұрын

How to Use Depth Mask to Hide Water in Boats in Unity
1:06 to skip Intro
5:14 to jump to Blender Instructions
Have you been trying to figure out how to put your boats in the water, but not let the water seep in? Then this tutorial is for you!
Here is the Unity Wiki on the depth mask:
wiki.unity3d.co...
Last I checked, the above link didn't work, so here is the page from webarchive.org
web.archive.or...

Пікірлер: 95
@LowLevelLemmy
@LowLevelLemmy Жыл бұрын
You're persdonality is great for this. I watched this tutorial even though I didn't give af about boats or water. but i watched it cause u entertained me.
@PhilipHerlitz
@PhilipHerlitz Жыл бұрын
LOL Thanks for the view!
@DanielKierkegaardAndersen
@DanielKierkegaardAndersen 2 жыл бұрын
To those curious, the reason this works is because when drawing pixels a shader does what's called ZTesting. Where it checks how deep a pixel is. Additionally opaque objects are rendered first in the 'geometry' queue(nr. 2000). Then later transparency (nr. 3000) happens (your water in this case) So when you draw the hull, all opaque objects are already drawn, because it uses the geometry queue (nr. 2000) + 10, so imagine a picture with only opaque objects. Now the hull comes in and draws on top of that. However since ColorMask is zero it doesn't actually draw a color. It does however still draw the depth value (which is why you need zwriting on) Now when a transparent pixel comes in (since transparent objects are drawn in the transparency queue (nr.3000), aka, higher queue than 2010 from our hull) The pixel will read from the Zbuffer(buffer containg depth of a pixel), if the transparent pixel is in front or behind the current location. So in summary, this effect works on queues over 2010, e.g. transparent objects
@PhilipHerlitz
@PhilipHerlitz 2 жыл бұрын
"Magic."
@haachamachama7
@haachamachama7 2 жыл бұрын
Hey, I wonder if you have any idea on how i could do the same thing with an opaque texture(maybe a specific layer?)? I have a hole that digs into the ground, i want to make it so i can see the ground even if it's intersecting with the hole, it works if i set the ground to transparent, but that creates all kinds of weirdness with objects appearing in front of the land and whatnot...
@Aereton
@Aereton Жыл бұрын
I'm wondering if this could be solved in a simpler way within the newer Render Pipelines
@viva-la-baz1458
@viva-la-baz1458 9 ай бұрын
same@@Aereton
@emeraldgalleon9725
@emeraldgalleon9725 5 ай бұрын
@@haachamachama7 Hey, sorry for necro comment, just saw it, but maybe it'll be helpful for someone later. Render Queue is the solution for your question. You can set queue directly in material, or in shader. For example - 2010 for mask and 2011 for your geometry (not higher than alpha).
@UnityDevJOY
@UnityDevJOY 2 жыл бұрын
Shader "Masked/Mask" { SubShader { // Render the mask after regular geometry, but before masked geometry and // transparent things. Tags {"Queue" = "Geometry+10" } // Don't draw in the RGBA channels; just the depth buffer ColorMask 0 ZWrite On // Do nothing specific in the pass: Pass {} } }
@CyberStudios
@CyberStudios 3 жыл бұрын
I've been battling for years to get this right, thank you so much. And u got a sub!
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
Thanks so much! Glad I could help!
@DageLV
@DageLV 3 жыл бұрын
Convex hull can also be a square plane, it'll be less polygons and won't block water at side of ur boat
@patrevizani
@patrevizani 2 жыл бұрын
thanks a lot, I love specially how you don't pretend to be an expert at things that you are not, cheers
@GilbertGames
@GilbertGames 7 ай бұрын
Thank you so much!!! Great tutorial and I enjoyed my stay. I like that you admit you aren't familiar with shaders which is very related. Where as everyone else try's to sound super smart.
@PhilipHerlitz
@PhilipHerlitz 7 ай бұрын
3 years later, and I still don't know how shader code works. But, I've recently learned some shader graph. So that's been fun! Thanks for stopping by and commenting!
@shuraanlz
@shuraanlz 8 ай бұрын
thanks a lot mate, stopped the leaks in my boat without too much hassle :)
@AmbientMelancholyGames
@AmbientMelancholyGames 3 жыл бұрын
That was awesome! Got here for the depth mask but stayed for the personality ^^
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
LOL. Thanks so much!
@Community-Compute
@Community-Compute 3 жыл бұрын
Such a great video!!! Thank you. My ship has a bit of a curved shape, so I think I will have to split the convex hull into separate FBXs.
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
Glad it was helpful!
@anhquantrannguyen20
@anhquantrannguyen20 2 жыл бұрын
I have been recomended to this video by NatureManufacturer mods. Thank you for the instant trick!
@PhilipHerlitz
@PhilipHerlitz 2 жыл бұрын
Glad it was helpful!
@LustraGaming
@LustraGaming 3 жыл бұрын
I'm going to have some fun with this method to hide a ball going into a hole in my game. If it works you, my good sir, will have saved me hours of trial and error.
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
That is how I learned this trick! I watched a tutorial on how to hide a ball going into a hole!
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
kzbin.info/www/bejne/mXnLqaZnZ7-ZibM
@LustraGaming
@LustraGaming 3 жыл бұрын
@@PhilipHerlitz I found that same video after I knew where to look. My game is 2D but is using a 3D object as a ball so I bet I can just make a plane behind my 2D object so my ball sinks in. But I'll have to try it first.
@MrMaffia41
@MrMaffia41 3 жыл бұрын
holy shit this is exactly what i was looking for. thank you so much for researching the thing that i didnt think of
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
I'm so happy I was able to help you out!
@alpernatif35
@alpernatif35 3 жыл бұрын
But this mesh object masks everything on the boat (characters, game assets etc. )I think using inner meshs of boat solves the problem.
@SewerShark
@SewerShark 3 жыл бұрын
You need to change the object Order in Layer, under the Mesh Renderer. Objects with a higher value than your Depth Mask will be occluded.
@Ugeen-Huge-Jeans
@Ugeen-Huge-Jeans 2 жыл бұрын
@@SewerShark But then everything that should be rendered on top of the boat, will be rendered on top of water. Or you switch layers dynamicly
@SewerShark
@SewerShark 2 жыл бұрын
@@Ugeen-Huge-Jeans just trust me, it works.
@nimzsakrajz6101
@nimzsakrajz6101 2 жыл бұрын
Subbed you for a gem. And now gems keep spawning on my feed❤
@lpenn
@lpenn 3 жыл бұрын
This was perfect and with probuilder you can do it all in unity :)
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
Awesome! I'm glad you found this video helpful!
@lpenn
@lpenn 3 жыл бұрын
@@PhilipHerlitz it honestly was the perfect video aha
@RedFi6h
@RedFi6h Жыл бұрын
Thank you, it's was really interesting for me
@Coldsteak
@Coldsteak 2 жыл бұрын
The problem with this method is if you have a larger ship and the camera clips inside the mask mesh, the effect falls apart
@natsuexp_channel
@natsuexp_channel 3 жыл бұрын
Excellent tutorial
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
Thank you! Cheers!
@richardbajuzik2445
@richardbajuzik2445 3 жыл бұрын
Thank you so much!
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
Happy I could be of help!
@danielcraft15
@danielcraft15 2 жыл бұрын
When inside the shape with the material, I can see what im trying to prevent, when outside of the shape however, it works. how do i make it work when inside aswell?
@jayengel9012
@jayengel9012 8 ай бұрын
im late, but did you find a solution?
@danielcraft15
@danielcraft15 8 ай бұрын
@@jayengel9012 No sorry, I only made it so that my camera is high enough to be just above the collider
@leoverload7685
@leoverload7685 3 жыл бұрын
Thank you so much! That's what I was searching for, nice tutorial
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
Wow! Someone actually watched this! I was hoping it would help someone. Glad to know youtube search is letting people find it.
@leoverload7685
@leoverload7685 3 жыл бұрын
@@PhilipHerlitz I actually used a Capsule instead of a copy of the boat because if I use a copy I need to put it a bit upper than the original one so it causes the mask to "mask" other things . But absolutely something I couldn't have done without this tutorial :)
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
@@leoverload7685 Oooh. A simple capsule is a great idea. I should have thought of that. LOL. At least I learned something new in Blender.
@jakobwitsch5756
@jakobwitsch5756 2 жыл бұрын
Why does it not mask out your other boat when pulling it up upside-down?
@professor_stevens6784
@professor_stevens6784 3 жыл бұрын
Good video. This won't work unless the material on the water is set to use a render queue above 2010, which is where the shader sets the mask material. Could you add a follow-up that shows the details of the water and, in particular, its material? Thanks!
@kadirozyldrm1246
@kadirozyldrm1246 3 жыл бұрын
Yeah my water's queue is 3000 so It doesn't work for me. Do you have any solutions pls.
@DanielKierkegaardAndersen
@DanielKierkegaardAndersen 2 жыл бұрын
@@kadirozyldrm1246 if your water is queue 3k then the effect should work (get hidden) anything under 2010 will still be drawn
@williamst-amour5140
@williamst-amour5140 3 жыл бұрын
Thank you sir!
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
You are welcome!
@twonkykong
@twonkykong 3 жыл бұрын
Thank you mr. know_everything!
@thelumberjack8838
@thelumberjack8838 3 жыл бұрын
Great video and great personality. I don’t even use Unity, I use Godot but it was very entertaining to watch.
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
Wow thanks for the kind words!
@Joshimite
@Joshimite 3 жыл бұрын
Great vid thank you :)
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
Glad you liked it!
@Dealtloft
@Dealtloft 2 жыл бұрын
Thank you!!!
@PhilipHerlitz
@PhilipHerlitz 2 жыл бұрын
You're welcome!
@wurstautomat832
@wurstautomat832 Жыл бұрын
Thanks for this! I'm using this for a virtual reality projekt but the depth shader only works on the left eye. What can I do? I can't use the multi pass rendering in open xr settings so I have to tweak the shader itself.
@icarodlima
@icarodlima 3 жыл бұрын
Perfect!
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
I'm glad it helped you!
@watercat1248
@watercat1248 3 жыл бұрын
is working but not in the i want this system to work in my game because this mask work's hide all the transparent matirals the don't have any way to hide specific layer that means if want to add stuff liak galass bottles or other transparent objects is just hide this object as wll not only the water if ther is any way to hide specific layer please answer in this comment
@banious2806
@banious2806 3 жыл бұрын
Set the Render Queue for the Mask to like 3001 and the water to 3002. The mask only hides things in a higher render queue and Opaque objects are 2000 and Transparent are 3000
@watercat1248
@watercat1248 3 жыл бұрын
@@banious2806 okay
@polyhall1
@polyhall1 3 жыл бұрын
i love this video. simple, efficient, fun
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
Glad you liked it!
@trentstoute5359
@trentstoute5359 3 жыл бұрын
If you want, you can use the probuilder tools to keep the depth mask in the right shape.
@us420vrgamers
@us420vrgamers Жыл бұрын
That is the route I went with my use of this... and worked great. ProBuilder and made a PolyShape.
@taptopgamer
@taptopgamer 3 жыл бұрын
If you deploy this on an android device the mask will display as black pixels. I don't know why
@banious2806
@banious2806 3 жыл бұрын
I think your water may have cast shadows On
@taptopgamer
@taptopgamer 3 жыл бұрын
@@banious2806 It's the original project I didn't make any modification. Anyway I found the reason, It's due to Vulkan API bugs of Unity. Just turnoff Vulkan API or drag it after OpenGL ES APIs in building settings and the shadows are gone
@banious2806
@banious2806 3 жыл бұрын
@@taptopgamer Great, glad you figured it out :D and thanks for the heads up.
@Maxime66410
@Maxime66410 2 жыл бұрын
Thanks you so mush
@arc5015
@arc5015 3 жыл бұрын
Nice tutorial, thanks :) Any idea how you'd invert this at all (like water in a bucket)? Did some searching but couldn't find anything that didn't seem to need a long course in Shaders, lol.
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
You and me both. But, with the new versions of unity, they have shader graph, which is suppose to make it so much easier to do shaders, you don't have to code them anymore. I haven't messed with it yet though.
@arc5015
@arc5015 3 жыл бұрын
@@PhilipHerlitz Interesting, have seen shader graph tutorials floating around, maybe time to finally try it. Cheers man
@kitws
@kitws 2 жыл бұрын
Can I use it in VR?
@PhilipHerlitz
@PhilipHerlitz 2 жыл бұрын
I haven't tried it. Give it a shot and see what happens. I imagine it would still work.
@starplatinum3305
@starplatinum3305 Жыл бұрын
Instead of a convex'd hull boat, i think u should fill the top (with the same position as the top of the convexed hull thing) of the boat, so it will be masked perfectly, aw hell nah my English sucks
@lucasbastosrodrigues140
@lucasbastosrodrigues140 Жыл бұрын
cool
@MetaversoJuliXR
@MetaversoJuliXR 2 жыл бұрын
DepthMask Shader Wiki Page is no avariable.
@PhilipHerlitz
@PhilipHerlitz 2 жыл бұрын
Did you check the web archive link? web.archive.org/web/20210831213650/wiki.unity3d.com:80/index.php/DepthMask
@dudemanguy8099
@dudemanguy8099 3 жыл бұрын
how can I make this in URP?
@PhilipHerlitz
@PhilipHerlitz 3 жыл бұрын
I have stayed very far away from URP. I know one day I need to dive into it, but so far, I haven't touched it really.
@dudemanguy8099
@dudemanguy8099 3 жыл бұрын
@@PhilipHerlitz not the answer I was expecting xD, searching for depth masks urp and can't find anything
@banious2806
@banious2806 3 жыл бұрын
@@dudemanguy8099 Did this with URP same steps and works for me
@Contatoalienigena
@Contatoalienigena 2 жыл бұрын
You are normal like all
@batnikelam-mavzer443
@batnikelam-mavzer443 2 жыл бұрын
gj
@rexin_z5966
@rexin_z5966 21 күн бұрын
thank you sooooo much!!!!!!
@PhilipHerlitz
@PhilipHerlitz 19 күн бұрын
You're welcome!
Buoyancy with Unity Rigidbodies - Part 1 / Planar Buoyancy
13:19
V.A. - Indie Dev
Рет қаралды 47 М.
Stencil buffer в unity за 5 минут. Как сделать маску в 3Д?
5:57
Зу-зу Күлпаш 2. Бригадир.
43:03
ASTANATV Movie
Рет қаралды 733 М.
Бенчик, пора купаться! 🛁 #бенчик #арти #симбочка
00:34
Симбочка Пимпочка
Рет қаралды 3 МЛН
Don't look down on anyone#devil  #lilith  #funny  #shorts
00:12
Devil Lilith
Рет қаралды 46 МЛН
When Your Game Is Bad But Your Optimisation Is Genius
8:52
Vercidium
Рет қаралды 1,5 МЛН
Why Do Video Game Studios Avoid Blender?
6:49
The Cantina
Рет қаралды 643 М.
Do Video Games Fake Buoyancy?
17:08
Acerola
Рет қаралды 233 М.
Writing Unity Shaders Using Depth Textures
16:13
Benjamin Swee - Custom Unity Shaders
Рет қаралды 11 М.
Unity Performance Tips: Draw Calls
4:24
Lofi Dev
Рет қаралды 193 М.
Use Depth Mask to Hide Objects in Unity - URP & Built-in
2:30
Game Dev Box
Рет қаралды 3,7 М.
Создаем остров в океане Unity
17:30
IT tuts
Рет қаралды 6 М.
Coding Adventure: Ocean Simulation and Buoyancy
5:48
Shan Memon
Рет қаралды 31 М.