AR-like Camera Effect, How to Achieve Custom Shaped Culling Masks for Camera?

Hello all,

I apologize if I get formatting wrong or if this question is in the wrong place. This is my first time posting. I’m creating a futuristic game and the Main Character is wearing a visor. The visor has small spaces on the side which are not part of the in-game AR headset screen, but still see-through giving the player a full view of the environment. I wanted to place canvases and arrow graphics in World Space as AR navigational cues for the player but have these arrow graphics only render within the in-game AR headset screen, whilst not appearing on the sides of the in-game visor.

Here’s a link of an image I found that might better represent what I’m trying to accomplished, taken from Google Images. Image Example

The red lines encompassing the building are cut off on the device, the device in this case being the sides of the in-game visor which are not part of the player’s headset screen.

I took the liberty of taking a screenshot of what I had of my game and drafting a concept of what it might look like. Above is a screenshot of the player’s view. I highlighted the area of the player’s headset screen with the red outline, the red outline not being part of the desired outcome and just an indicator. The player will be able to see the environment as per normal in a camera outside of the red outline, but that area outside of the red outline should not render the AR directions I will have placed, either as World Space Canvases or any other solutions.

From what I could find, the Camera Culling Mask seems perfect for this, but it handles the whole screen of the camera, instead of being able to set a custom area. I could not find anything on the web about Custom Textures or Shaders for the Camera Culling Masks, so if it’s possible with Unity 5, I’d appreciate a sign to the right direction.

Other solutions I have tried to look into would be the render queues and depth masks, but those are out of my league and I didn’t understand enough of it to piece together a solution for the effect I’m going for.

If anyone can point me to the right direction of how I could achieve this effect, I would be very grateful.

Hey all,

so I finally got it to work properly. For the benefit of those following this question I’ll explain my solution.

I applied a Depth Mask shader to a visor mesh and placed it in front of the camera. Then I duplicated the camera and set the new camera to Depth only and it’s culling mask to not render the layer which holds all my AR effect objects but render the visor object. This new Camera was then set to a higher depth than my Main Camera. I then set the Main Camera’s culling mask to not render the visor.

This way, the new camera is what covers the whole screen, but since the new camera renders the visor which has a depth mask, the new camera can’t see anything behind the visor object, essentially cutting a hole in the shape of the visor in the new camera.

The main camera on the other hand, renders everything but the visor, and so the capture from the main camera shows up in the hole left by the depth mask. You can find the depth mask shader script here: Unify Community: Depth Mask

Hope this helps someone else!

These are examples of the above solution in effect:


The AR Camera is then parented to the Main Camera to move along with it when I control my character along with the visor.