AR Android Stencil shader

trying to use a material with a shader as an hider material. The object should cover the object behind it and the camera image should be visible.
Often used on portals or on your smartphone.
Unfortunately it doesn’t work for me. Android and IOS simply show the object in white.

It looks correct in the Unity Scene. It is black in the game window and white in AR mode on the smartphone.

My material has a DepthMask and the material has the Export Lable

Original Post on Discord

by user 680853402338721851

Hello there – we have an experimental AI bot :robot: that might be able to help you with your question. Would you like to try this out?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

Here is what I found for you :brain: Discord

Hi, are you using the URP stencil renderer for this?

Hello Sabrina,

It sounds like the issue you’re encountering is with the shader and material setup for rendering AR content where a virtual object should serve as a mask to display the camera feed, commonly known as an “hider” material.

To troubleshoot the problem, consider the following steps:

  1. Ensure the shader supports AR rendering and is correctly set up to display the camera’s background texture through the objects it’s applied to.
  2. Verify if your shader and material settings are being preserved during the export process from Unity to your Android and iOS devices. If there’s an issue with the shader not being compatible with mobile platforms, it might show up as a default white material.
  3. When using Needle Engine, ensure that the material’s settings, particularly those that refer to depth and stencil buffers, are correctly configured for web rendering, as there might be differences between the Unity Editor and the web runtime environment.
  4. Confirm that the Export Label for your material is properly set so that Needle Engine recognizes it and includes it correctly in the exported project.

Since you mentioned the issue does not occur in the Unity scene or game window but manifests on the smartphone in AR mode, it’s very likely the problem is tied to platform-specific shader compatibility or incorrect material settings for web/AR environments.

Normally, checking the log output on your smartphone when running the AR session might provide more insights and error messages that can guide further investigation.

If there is a more specific question or if you have a code snippet or error message you’d like assistance with, please provide further details so I can offer more targeted help.

1 messages left GPT 4
thread_8NTZ3V5QAY7eRgrY2Jif2Wr2

“It look black in the game window” refers to the browser or the Unity game window?

by user 680853402338721851

the Unity game window

by user 680853402338721851

like on the screen shot, on the left the case i want on the right the game window

by user 680853402338721851

If the unity game window looks wrong already it will most likely not magically work in the exported scene.

I think what you’re trying to do here is creating a occluder and not a stencil effect. What you could use for the web is add a shadow catcher component and set it to occluder for this
image.png

Note that this won’t work on iOS AR tho (only android)

OK, I’ll take a look, thank you

by user 680853402338721851

Is there any more information about this? Or how exactly do I have to use it? If I just drag the script onto the object nothing happens.

by user 680853402338721851

This effect is currently not displayed in Unity - but you’ll see it in the browser

image.png

mh doesn´t work for me:

by user 680853402338721851

by user 680853402338721851

Das Objekt ist nicht zu sehen. und auch nicht beeinflusst die Kirche

by user 680853402338721851

ups, english: The object cannot be seen. nor does it influence the church

by user 680853402338721851

Can you show your unity setup please?