Stencil Shader for AR-Portal

Hey, I try to create a simple AR Portal for iOS and Android but I have problems with the stencil shader. I tried a few things that I could found on the discord Server, tagged the shader but it always seems that the shader is not exported. In Unity it works perfect but on web the masks are just white.
I have read that Quicklook also have a problem with custom shaders, so is there any possibility to create a stencil shader for quicklook? Thanks for your answers :slightly_smiling_face:

{
    Properties
    {

    }
    SubShader
    {

    ZWrite off
    ColorMask 0

    Stencil
    {
        Ref 1
        Pass replace
    }
        Pass
        {
           Blend Zero One
        }
    }
} ```

```Shader "Unlit/StencilGeom"
{
    Properties
    {
        [IntRange] _StencilID ("Stencil ID", Range(0,255)) = 0
    }
    SubShader
    {
        Tags    
        {
            "RenderType"="Opaque"
            "RenderPipeline" = "UniversalPipeline"    
            "Queue" = "Geometry"
        }
       
        Pass
        {
            Blend Zero One
            ZWrite Off
            
            Stencil
            {
                Ref [_StencilID]
                Comp Always
                Pass Replace
                Fail Keep
            }
        }
    }
}

Stencil1.PNG
Stencil2.PNG


Original Post on Discord

by user 347826372732780545

Sadly even the template project “Stencil Portals” is not working although I use URP. If I create a new Render Pipeline and try different settings on stencil nothing happens when I try to export it. Am I missing something essential to get the stencil running? I know that there was a post with the same problem, but i cant solve it.

by user 347826372732780545

Hey :wave: what version of Unity are you using?

2022.3.7
Should I try an older version?

by user 347826372732780545

Hi, please make sure you assign the URP settings from the sample with the stencil layers. Looks like you have a different sample asset assigned here :slightly_smiling_face:
image.png

Nothing changes when I assign this settings to the RP component. Neither in discord nore on glitch :frowning_with_open_mouth:

by user 347826372732780545

But you do have URP installed in your project?

And assigned in ProjectSettings/Graphics as the current RP ?

I would have said yes :thinking: :sweat_smile:

by user 347826372732780545

I’ll download your version and test in a clean project :+1:

Thats the only Error i get, after I imported the packages for Needle but I am not sure if this is responsible for my problem.
I try it with an older Unity Version :smile: Maybe that helps

by user 347826372732780545

Hi @MarcChris we’re investigating :slightly_smiling_face: we wanted to make a release just now and it seems like the Stencil settings are missing in the exported samples package. We’ll get back to you in a little bit :slightly_smiling_face:

Thanks a lot :slightly_smiling_face:

by user 347826372732780545

Okay I tried the project with Unity 2021 and although there are some Materials not working in Unity, it works after I export it on Glitch. I dont know if I have some settings wrong in 2022, but I keep testing :smile:

by user 347826372732780545

Hello @MarcChris can you try updating to the latest sample release (version 0.13.0) ?

Now its working on Unity 2022, but only after I assigned the Renderer from the sample. Then there was a error about blitter and Unity tried to rebuild the scene for 7 minutes, before I closed and restarted Unity. And then Unity fixed the error by itself and everything worked perfectly. :thinking:

by user 347826372732780545

Good to hear it works now - do you have by any chance the editor still open and could send the current and prev editor log (just in case it contains anything useful)

You can DM it if you want :slightly_smiling_face: