I have a ScrollRect containing a list of cars with 3D models inside every entry of the list itself. The cars are placed in front of the whole UI. It’s working as expected, except obviously for the masking of the 3D models:
The masking is done with the standard UI Mask component. Is it possible to mask them with a shader, somehow? I’d like to avoid using RenderTextures or dirty pieces of UI sticked above the cars just to cover them strategically. I’d also like to keep the Canvas set to Screen Space - Camera (current setup of the whole UI).
I tried applying UI shaders on the cars, but they just render wrong and never get correctly masked.
Thanks for any help!
I know that the question is too old, but I had the same problem with 3D objects in the UI, so I would like to help. I found some website where there is a solution (https://alastaira.wordpress.com/2014/12/27/using-the-stencil-buffer-in-unity-free/).
However, I think it’s a little bit confusing, so I’m going to explain what I did:
- First of all, you need 2 different shaders. (Create >> Shader >> Standard Shader). I called them ‘Portal’ (the space to see the objects) and ‘Backobjects’.
- Here are the 2 shaders (I just copied the examples in the page that I mentioned before)
- Now you need to create 2 different materials which use these shaders (Create >> Material >> Shader: Custom/Portal OR right click on the shader, and create material).
- The last step is to apply the materials to the objects and it’s done!
I hope this will help everyone who reads this answer.
Sebastian Lague has a super-simple tutorial on creating a system like Rodrysson referred to. Here’s the link: Field of view visualisation (E03: stencil shader) - YouTube
You can assign a mesh to the canvas renderer (manually through script), then the mask component will work on that as expected.
Yo, I found a solution by rendering the objects into a image via secondary camera and making the camera and image child of ui and making the secondary camera and all the 3D objects away from primary camera.
It worked flawlessly for me.