What objects are set to stencil layer 1 andlayer 2. I understand that you have set two quads as stencil layer1 and 2. But what about the objects that are to be seen through those quads??What layer are they set to??
FOR NEWER VERSIONS turn off "Depth Priming Mode" under "Rendering Path" in the URP Renderer Settings. Otherwise your shader is required to have a depth-normals pass to function which will make Daniels shader non-functioning.
Thank you! I did this but unfortunately my objects are now transparent. I've seen a couple other people say to turn on "After Opaque" under SSAO, but that has not worked for me. Did you ever find a solution to this?
If you wanted to do it without any shader code or extra materials, you could give each quad its own layer, and put a renderer feature in for its layer, before the one for the corresponding object's layer, where the comp function is never, the value is the id, and the fail operation is replace.
Can you describe what she meant? I want to achieve this result but I can't use shaders. I CAN use a shader graph, but I don't know how to do this in shader graph. If I could avoid shaders all together, that might be best. Thanks!@@danielilett
Great tutorial! For anybody who's having issues with Occlusion being rendered above opaque items of the stencil just turn on the toggle "After Opaque" inside the SSAO render feature panel of the render settings.
Been trying to do this for masking out water in a volume mesh it's giving headaches because I also have transparent windows in volume like subnautica bases, and I cannot get it working correctly because I'm masking a transparent layer of water and so if I'm in the volume looking through a window I am still masking the water because the camera is inside the volume mask looking out. Haven't been able to solve this issue in urp.
Very cool, I just have a small problem and don't know how to fix it :(. In Unity 2022.1.16f, ambient occlusion of objects behind is projected in front of objects that are in the stencil layer. Is there a way to fix it? Thanks in advance
Hi, I just found your channel and I love it. I am amazed of the simplicity in the solutions. Not that they are simple! Great work. I have a small question - Is there an easy way to exclude all layers but the stencil layer. So only the stencil 1 layer object are displayed in the box!?
Edit: I just noticed you have source code available, I will look into the source code, will find my answer :) First thanks for the tutorial.. I find this really interesting and trying to experiment with this right now, I have a question regarding the demo scene.. for each "impossible cube" did you have to create 4 stencil faces and layers for each cube and then added a renderer feature in the pipeline for each stencil layer? I am missing around with this concept to create cards with full assets/models inside them... but don't want to do this for each card
Thanks for your awesome tutorial. I was able to have my gameobject showing throw the stencil. However, the particle systems didn't show through the stencil. Is there other modification needed for particle system, other than layer name? Thanks!
Thanks, works fine. Is it possible to use this as a red dot? As soon as I drag the object with the stencil layer into the red dot PFB, it is always visible, even if the gun and the red dot have the stencil layer, can you help me further?
I'm confused, i'm trying to get this to work with my rabbit hole, it's like a dirt hole that digs into the ground, but i want to put a mask on top and if, say, the ground is intersecting in the hole, it will only render the rabbit hole and ignore that ground... I couldn't get it working with my forward renderer for some reason, so i tried just straight up importing yours. It works in that it shows the object only through the mask, but it doesn't ignore the ground...so i end up with only being able to see the hole through the mask, and still not being able to mask out the land...
How do you read the value in the fragment shader to use to display what you like? You're comparing but not getting the value to use say to set a colour in fragment which is what I can't figure out
hi can someone help me .ı have issues about shadder ı write a shadder it makes object invisible but dont render behind objects .the issue is when ı add unity terrain shadder dont work right it makes object invisible but if behind object is unity terrain it still render unity terrain. ı thinks its about unity terrains mesh renderer .btw sorry my english
Could someone teach me how to cut out a mesh with another mesh ? I have a simple plane, and I want to place a cube that creates a hole in the plane as it intersects it, I also want to resize the cube by picking on of its vertices, kind of resizing a panel but in 3d. I'm new on unity so I would really appreciate if someone can help my out with that
I believe that might be Unity's default SSAO acting up. You can go to the forward renderer > Renderer features and uncheck SSAO. Or if you want to keep the SSAO effect then check the "After Opaque" box inside the SSAO renderer feature.
Honestly, knowing almost nothing about shaders, this tutorial helped a lot. There was never a point in which I didn't know why you were writing something because of your excellent explanations. Two thumbs up from me!
Potentially? Interior mapping is one of those subjects I keep meaning to look into in more detail, because I think there are some interesting nuances if you want to keep the effect performant. I do remember seeing people talking about it a while back - here's one of the articles I remember reading which serves as a decent overview of techniques: www.alanzucconi.com/2018/09/10/shader-showcase-9/
Assuming both 'versions' of the room need collision that matches the objects you can see, I'd detect when the player crosses one of the boundaries into the room, and at that point, turn on the colliders for only that 'version'. As for rendering properly, if your game is third-person (and assuming the room is small enough that the camera can always stay outside the room), you can move the player model into the correct layer for that room version so they render properly too. Then put them back into the default layer when they exit. If your game is first-person, then I suppose that's trickier. When you approach really close to one of the boundaries, assuming by that point you can only actually see one of the sides of the room and therefore technically don't need the 'impossible' effect to be active, I would move all of that version's objects into a regular layer so it gets rendered normally. Then, when you exit, I'd swap the objects back into the special layer for that room version. Mind you, I haven't tried this out or tested it, so this is just me guessing.
@@danielilett I made a version for VR, where there is a model of a person and I applied that stencil shader to it and made it double sided. When player triggers collision I just scale up that model so it makes cool transition into the other space when you walk through the person shape portal... and as its double sided, you see the correct models from the inside :) Thanks so much for the video by the way
Any idea why this no longer works on PC? In Unity 2021.3.16 (probably just 2021.3..?) and URP 12.1.8 the stencil no longer works when the platfor is set to Windows/ PC/ Mac. Swap to Android or iOS and it works again.
nice! would you consider making a tutorial for a virtual door / stencil the player can step thru in VR in passthrough on Quest3 ? eg. a door appears in your lounge that leads from your real lounge to a virtual space beyond.. and when you are inside the VR space - you can see back through the door to your real lounge again
Hi this video has helped out alot, but I was wondering if theres a way to also include shadows into this?
Great tutorial! I always find the stencil buffer a bit tricky to reason about, but it's so useful and you explain it really well here.
Great content. Is it possible to use this technique for making a portal for vr & ar ? thank you
What objects are set to stencil layer 1 andlayer 2. I understand that you have set two quads as stencil layer1 and 2. But what about the objects that are to be seen through those quads??What layer are they set to??
I really like how easy you have made this, but I cannot grasp what is the scene setup, or how objects are placed
FOR NEWER VERSIONS turn off "Depth Priming Mode" under "Rendering Path" in the URP Renderer Settings.
Otherwise your shader is required to have a depth-normals pass to function which will make Daniels shader non-functioning.
Thank you! I did this but unfortunately my objects are now transparent. I've seen a couple other people say to turn on "After Opaque" under SSAO, but that has not worked for me. Did you ever find a solution to this?
Actually funnily enough it seems to only be an issue in the scene view. Runtime looks fin, but if you have any tips let me know!
If you wanted to do it without any shader code or extra materials, you could give each quad its own layer, and put a renderer feature in for its layer, before the one for the corresponding object's layer, where the comp function is never, the value is the id, and the fail operation is replace.
Yeah, that's a really good way of doing it!
Can you describe in more detail what you mean? Thanks
Can you describe what she meant? I want to achieve this result but I can't use shaders. I CAN use a shader graph, but I don't know how to do this in shader graph. If I could avoid shaders all together, that might be best. Thanks!@@danielilett
Great tutorial!
For anybody who's having issues with Occlusion being rendered above opaque items of the stencil just turn on the toggle "After Opaque" inside the SSAO render feature panel of the render settings.
Problem: what if you see from the back-side, your shader still write to stencil buffer -> you still see the object, which is not expected.
Been trying to do this for masking out water in a volume mesh it's giving headaches because I also have transparent windows in volume like subnautica bases, and I cannot get it working correctly because I'm masking a transparent layer of water and so if I'm in the volume looking through a window I am still masking the water because the camera is inside the volume mask looking out. Haven't been able to solve this issue in urp.
I keep sharing this guide to so many game devs, especially for AR
Very cool, I just have a small problem and don't know how to fix it :(. In Unity 2022.1.16f, ambient occlusion of objects behind is projected in front of objects that are in the stencil layer. Is there a way to fix it? Thanks in advance
nevermind, fixed it by setting ambient occlusion in UPR Renderer Settings to After Opaque
@@sammraz1990 thanks! you saved my time
Hi, I just found your channel and I love it. I am amazed of the simplicity in the solutions. Not that they are simple! Great work. I have a small question - Is there an easy way to exclude all layers but the stencil layer. So only the stencil 1 layer object are displayed in the box!?
Sorry to budge in, if you ever get an answer I'd love to know too.
Make sure you have your Quads facing the right direction! Or else the stenciled objects won't show at all
You mean Correct normals facing outside ?
Hi dude ! amazing tutorial, ty for this. But I have a question, how can I use Transparent shader with your stencil method ? 🤔
Edit: I just noticed you have source code available, I will look into the source code, will find my answer :)
First thanks for the tutorial.. I find this really interesting and trying to experiment with this right now, I have a question regarding the demo scene.. for each "impossible cube" did you have to create 4 stencil faces and layers for each cube and then added a renderer feature in the pipeline for each stencil layer? I am missing around with this concept to create cards with full assets/models inside them... but don't want to do this for each card
Holy shit. Fucking brilliant. Give us more LSD type impossible shader things in the future pls
Thank you Daniel, still helping great after 2 years
Would like to know if this works on HDRP too?
OMG U just saved my life i was looking FOR this IN the URP pipeline God bless you OMG!!!!
Thanks for your awesome tutorial. I was able to have my gameobject showing throw the stencil. However, the particle systems didn't show through the stencil. Is there other modification needed for particle system, other than layer name? Thanks!
That, my friend, was a superb tutorial! 🚀♥
I really enjoyed watching it and using it for my character selection in foil trading card style! :)
That's a really good application of the effect for sure!
A whole week of trying, crying and chatgpt-ing and you solved my problem in 7 minutes T_T Thank you!
This is such a cool effect!! I was wondering do stencil buffers work in 2D renderers too?
Thanks, works fine.
Is it possible to use this as a red dot? As soon as I drag the object with the stencil layer into the red dot PFB, it is always visible, even if the gun and the red dot have the stencil layer, can you help me further?
Thanks Daniel
I'm confused, i'm trying to get this to work with my rabbit hole, it's like a dirt hole that digs into the ground, but i want to put a mask on top and if, say, the ground is intersecting in the hole, it will only render the rabbit hole and ignore that ground... I couldn't get it working with my forward renderer for some reason, so i tried just straight up importing yours. It works in that it shows the object only through the mask, but it doesn't ignore the ground...so i end up with only being able to see the hole through the mask, and still not being able to mask out the land...
How do you read the value in the fragment shader to use to display what you like? You're comparing but not getting the value to use say to set a colour in fragment which is what I can't figure out
hi can someone help me .ı have issues about shadder ı write a shadder it makes object invisible but dont render behind objects .the issue is when ı add unity terrain shadder dont work right it makes object invisible but if behind object is unity terrain it still render unity terrain. ı thinks its about unity terrains mesh renderer .btw sorry my english
Great video.
Could someone teach me how to cut out a mesh with another mesh ? I have a simple plane, and I want to place a cube that creates a hole in the plane as it intersects it, I also want to resize the cube by picking on of its vertices, kind of resizing a panel but in 3d. I'm new on unity so I would really appreciate if someone can help my out with that
It may not be your area of expertise, but do you know how to make this work in altpsace?
Very good!
This was incredible.
It's very hard to find high quality content that are not especially for begginers.
Im glad i found you. Thanks for sharing !
Thanks for the short and clear tutorial!
has anyone gotten this to work with Water shaders?
My objects become slightly transparent after setting the layer to a stencil layer. Any advice? Thanks!
I believe that might be Unity's default SSAO acting up. You can go to the forward renderer > Renderer features and uncheck SSAO. Or if you want to keep the SSAO effect then check the "After Opaque" box inside the SSAO renderer feature.
This tutorial was a life saver, if only I had found it sooner instead of spending hours trying to solve one problem. Thanks!
Absolute lovely tut.
Thanks! Glad it helped you :D
Honestly, knowing almost nothing about shaders, this tutorial helped a lot. There was never a point in which I didn't know why you were writing something because of your excellent explanations. Two thumbs up from me!
You're amazing
Very cool, could this be used to create an interior mapping / fake interior shader to use for an apartment building for example?
Potentially? Interior mapping is one of those subjects I keep meaning to look into in more detail, because I think there are some interesting nuances if you want to keep the effect performant. I do remember seeing people talking about it a while back - here's one of the articles I remember reading which serves as a decent overview of techniques: www.alanzucconi.com/2018/09/10/shader-showcase-9/
好厉害啊!这比我看到的其他的效果更好!
How would you make walking into it?
Assuming both 'versions' of the room need collision that matches the objects you can see, I'd detect when the player crosses one of the boundaries into the room, and at that point, turn on the colliders for only that 'version'.
As for rendering properly, if your game is third-person (and assuming the room is small enough that the camera can always stay outside the room), you can move the player model into the correct layer for that room version so they render properly too. Then put them back into the default layer when they exit.
If your game is first-person, then I suppose that's trickier. When you approach really close to one of the boundaries, assuming by that point you can only actually see one of the sides of the room and therefore technically don't need the 'impossible' effect to be active, I would move all of that version's objects into a regular layer so it gets rendered normally. Then, when you exit, I'd swap the objects back into the special layer for that room version.
Mind you, I haven't tried this out or tested it, so this is just me guessing.
@@danielilett I made a version for VR, where there is a model of a person and I applied that stencil shader to it and made it double sided. When player triggers collision I just scale up that model so it makes cool transition into the other space when you walk through the person shape portal... and as its double sided, you see the correct models from the inside :) Thanks so much for the video by the way
This is it in VR for curiosity ua-cam.com/users/shorts6K48MqFuCIw
Why the hell is this still not implemented in Shader Graph or am I bad at searching for info
Stencils are still not in Shader Graph, no. I would love for them to be added, but I don't know if it's planned?
@@danielilett Unreal has all this stuff with their blueprints from so many years it's funny how unity is still lacking behind
Nice
Good tutorial, thx a lot ;)
op sir I liked it
Any idea why this no longer works on PC?
In Unity 2021.3.16 (probably just 2021.3..?) and URP 12.1.8 the stencil no longer works when the platfor is set to Windows/ PC/ Mac. Swap to Android or iOS and it works again.
Updating to 2021.3.22 sorted it, must have been a bug in the version I was using.
nice! would you consider making a tutorial for a virtual door / stencil the player can step thru in VR in passthrough on Quest3 ?
eg. a door appears in your lounge that leads from your real lounge to a virtual space beyond.. and when you are inside the VR space - you can see back through the door to your real lounge again