Make Shader Ignore Layers?

8189418--1067379--upload_2022-6-8_19-3-8.png
I have this hole in the game I’m making, if anyone has any alternate ideas, please let me know, but i want the hole to be dug down even if the geometry is intersecting it. I wonder if i could just make a quad in the middle of the hole with a shader that ignores all layers except the hole?

The hole is dug down a bit. The reason I don’t want to just push down the terrain is this hole will not only be used on terrain(in fact, we’re thinking of just using geometry for the entire level and doing away with the terrain)

Thanks in advance!

You can use shader, to create hole effect. You could use shader even, to extrude hole, like extruding a tube.

Or find shader which creates hole and place game object under the terrain, which has shape of the hole and the tunnel.

I suggest to avoid doing anything procedural, if you never done anything similar.

The model already has a sufficient hole. I just want a shader that masks the hole, so even if there’s geometry from other objects(ie, the ground) in the hole, it only displays the hole.

Can you please alla borate a bit more on the desired effect?
I am unsure I do understand what you require.
Maybe if you can sketch what you need?

I just want to make a shader that masks out the terrain.
Like how right here you can see the terrain where there’s supposed to be a hole
8189556--1067415--upload_2022-6-8_20-13-54.png
It must be possible to put a quad over that hole that makes it so it only renders the hole model, right? So i just want to put an invisible quad in the hole that masks out ANY object that isn’t hole, maybe i could make it so any rays that pass through the quad only render one layer, the layer the hole is on?

8189577--1067418--upload_2022-6-8_20-21-43.png
Btw, this is what it looks like without any obstructions.

Well, in theory you could make shader that does not write to color or writes with alpha 0, but also writes to Z buffer and if you queued all objects properly it would do what you want (I guess?)

Sorry for the late response. I’m not sure how to go about that. I’m not an expert in shader graph haha. How do i queue the objects?If i could make a quad that just always queues the hole’s model first for anything that passes through it that would work? I wonder if I would have to put the hole on a layer and set that layer to render first? But I have no idea how to go about this haha

The method I mean’t was about putting some opaque quad on top of the hole with shader that writes only to depth, then set material queue somewhere early to render it before terrain. You can do something similar as in this thread: Hollow Boat Effect

2 Likes

Thanks. I’m kinda confused, I tried doing it the way he did, the only thing is my terrain is an opaque, There’s several things I need to change to make it work and I’m not really able to get it working…


This is what I got, the Mask is the quad I have inside of the hole(using an invisible shader), and the ground is on the terrain layer which is on the “masked objects” render feature. I imagine there’s a few things I need to change to get it working despite the terrain being an opaque?

Thanks

Bump?

allah borate

What you’re looking for is called a Stencil (Mask) Shader:
Impossible Geometry with Stencils in Unity URP (danielilett.com)
See Through Objects with Stencil Buffers using Unity URP - SLIDEFACTORY | Solutions for mobile, web, and the Metaverse. (VR, AR, Web3) (theslidefactory.com)

1 Like

Thank you for your response, i believe this is what i need, but i’m having difficulties getting it working. So,
8790136--1194340--upload_2023-2-8_18-46-28.jpg
On this hole, i gave the mask a stencil material assigned to 1(i just moved it up for testing), but i’m a bit confused, for one, i’m supposed to set this mask to only render the hole, right? But if i uncheck the hole’s layer, the entire hole turns invisible… and for another, the stencil mask isn’t even displaying the hole through it, even though i have it assigned and have the stencil render feature assigned to hole, whether through the mask or otherwise, i cant see the hole…
8790136--1194343--upload_2023-2-8_18-49-10.png
Would you be able to help me figure out what im doing wrong?

Thank you!

Edit: I tried importing the forward renderer he used in that first video, and it has strange results…
https://imgur.com/a/fkg4kg6
I changed the layers to correspond with the hole, so it’s only rendering the hole through the mask, so the stencil mask is working, more or less… but it’s still rendering the ground even through the stencil lol

8790136--1194337--upload_2023-2-8_18-45-27.jpg

A stencil mask is simply:

  • Write to a buffer from your shader
  • Read this buffer when rendering another object

From the Docs: https://docs.unity3d.com/Manual/SL-Stencil.html

In this case, you want your hole to write to the Stencil Buffer. Then, your floor can read from the stencil buffer, and clip (not render) when it finds that the hole has written to it.

The 2 shaders at the bottom of the Docs-page show how one will write a value of 2 to the buffer, where the other will read from the buffer and Clip https://developer.download.nvidia.com/cg/clip.html if it finds a value >= 2

Oh okay, shaders aren’t my specialty so forgive me, but… How do I have to do this? So I need to make the mask on the hole a stencil shader that only writes if it gets a certain value, and the hole should be a separate stencil that’s assigned to 1 and the ground could be 2? Does that mean I need to make another custom shader for the ground, though? I’m a bit confused as to how i can assign these values.

Edit: Sorry, just realized after posting this, oh okay, so, i need a stencil shader that only writes if the number is, say less than 2, and i need to use renderer features to assign these numbers to different layers?