Maybe this was answered somewhere already, but I was wondering if it is possible to still have stencil buffer in UWP?
If so, how do you go about implementing shader for UWP utilizing stencil buffer? Is there any official documentation about this?
Maybe this was answered somewhere already, but I was wondering if it is possible to still have stencil buffer in UWP?
If so, how do you go about implementing shader for UWP utilizing stencil buffer? Is there any official documentation about this?
stencil buffers are supported but i do not know of any official documentation.
when it comes to writing shader using stencil options you will have to write these manually.
you may use shader graph but have to edit the generated code and add the stencil related code.
Garhhhh
Depending on what you’re trying to do, you might also be able to use the custom renderer features instead.
I was experimenting with stencils just yesterday trying to create that effect where an object is only visible through a portal/window. My research first led me to stencils and I had no luck getting that to work, but then I tried setting up some layers and custom renderer features and got exactly the effect I wanted surprisingly easily.
Check out this video, it’s for LWRP but it’s still pretty followable for URP.
Hi, for anyone else that stumbles across this post like I did and is having trouble using the Stencil buffer in the new URP (or LWRP), I’ve written a blog post on how worked out how to update my shaders to use the new Render Features (like the video posted above) to create portals/windows etc. I hope it saves someone the few hours I spent trying to work it all out!
Thank you for the blog post. Unfortunately it does not work for me. Does the object’s material behind the window overrides maybe this behavior?
Hi, Sorry I’m not sure I understand your question? The material on the objects behind the window in my example use the standard URP/Lit shader. Nothing special is done to the actual materials or shaders themselves; all the overrides are set in the Renderer Features. In both the Renderer Features the material isn’t overridden either. Hope this helps!
Yeah, following your blog post (2019.3.9f1) does nothing.
Just got this working in 2019.3.9f1 with URP. So can confirm it works there. Thanks for your great post!
The key was the Custom Mask shader rendered Opaque with ZWrite off for me. Also, make sure you remove the layers from the Forward Renderer’s Opaque Layer Mask. Then make sure your mask is on top so it writes the values before your other layer tries to read them. I have both my events on Before Rendering Opaques.
There does seem to be a weird glitch in the scene view where the masked objects look transparent, which was driving me crazy. If you turn off the unity axis gizmo preview, it looks fine.
I kept on trying to get this to work, but it turns out Stencil Buffer overrides on Render Objects is broken in 7.3.1. If you are on that version, downgrading to 7.2.1 fixed the problem for me. I’ve already reported the bug to Unity, but this is what happens in 7.3.1.
After moving to 7.2.1, the stencil values get applied and saved correctly.
I ran into that issue with 7.3.1 too. However, you can get it to work in 7.3.1 by clicking on the individual renderer feature in the project tab (instead of editing it via the renderer’s list of renderer features in the inspector).
Sorry you weren’t able to get it to work. I’ve upgraded my project to 2019.3.11f1 and confirmed that I’m using the Universal RP package version 7.3.1. Everything is still working OK for me.
If I’ve missed anything in my notes, please let me know an I’ll fix my post!
Do you have the project file on GitHub or somewhere? I can’t seem to get this working too.
I’ve created a sample scene using 2019.3.11f1 based off of the sample URP scene from Unity with the stencil cut-out working. I’ve updated my post here with a link to the example and how to use it: https://bdts.com.au/tips-and-resources/unity-create-windows-portals-using-stencils-with-the-universal-render-pipeline-urp.html
Hopefully this helps!
Thanks man! Appreciate it
Thanks mate… it worked
Based on some questions and feedback, I’ve updated my post to include info on how to reverse the effect - so you can hide objects behind a transparent window instead: https://bdts.com.au/tips-and-resour…s-with-the-universal-render-pipeline-urp.html
Hej @travis_unity746 , we downloaded your sample scene for URP and it works. However we are wondering whether we are missing some layermasks. Whether they got lost as we opened the scene. Does this scene use layermasks or it just works without them?
I’m not sure I understand your question, but I did create two layers for the game objects - a “Window” layer and a “HiddenObjects” layer. The Forward renderer object has two renderer objects which tell it how to draw objects on those two layers.
Thanks that answers it. I think we lost the layers on imports. But it still works dont know why. Thanks for the tutorial.