Log in or register to post comments

Mask an AR camera using a custom alpha shape

July 9, 2012 - 9:14am #1

Hey all,

I'm creating an app using image targets that allows the user to point their camera at a printed page and see hidden content.  I'd like to create a "magnifying glass" effect in which I have a GUI element overlayed on the screen that looks like a magnifying glass and I only want to render the ARCamera's feed into the magnifying glass' circle and have a second camera that renders the camera feed around it.

In summary:

1. AR Scene with image target

2. GUI element that looks like magnifying glass

3. Second camera to render the non-AR camera feed

 

I'm trying to figure out the best approach to take in Unity to create a circular "scissor box" effect.  I'm thinking I'll need to create the magnifying glass image with an alpha-to-grayscale setting enabled in the inspector and then have the ARCamera render only the part of the screen within the alpha-masked circle.  Another strategy was to create a scissor box effect (which does not come out-of-box with Unity) and then add some sort of vignette effect or something to that area to mask out the hard right angles caused by the box.

I've attached an image to show what I'm trying to accomplish.  Any suggestions or examples would be great.

 

AR Camera Mask Example

Mask an AR camera using a custom alpha shape

February 22, 2013 - 10:45am #10

The BackgroundTextureAccess sample shows how to assign the camera image to a texture - you can do this within the ARCamera's Inspector.

But the effect that you're looking for doesn't require a Texture2D. Instead you build a mesh, or arrangement of meshes, for the borders of the augmented view and apply a depth mask to these, and make this a child of the ARCamera so that the ARCamera is looking through the mesh frame. The depth mask will prevent the augmentation from being rendered under the mesh are so that you'll only see it in the unmasked region.

Mask an AR camera using a custom alpha shape

February 21, 2013 - 11:39pm #9

Hello David,

 

I know its an old thread, but I'd like to do something similar on a texture2D. What I want is the camera stream to be rendered on a Texture2D instead of the full mobile screen. An example is shown in the image below:

Is this possible? If it is, can it be done using depth mask? I tried to follow this thread, but I'm stuck at where to position my texture. Any help here will be highly appreciated.

Edit:

Link: https://www.dropbox.com/s/uddjig1e8ugl14j/example.png

Regards,

Parth

Mask an AR camera using a custom alpha shape

July 14, 2012 - 5:00pm #8

muhammadgyan,

Set your AR Camera's clear flags to "Depth only" for this effect to work properly.  It allows you to only render what's in the depth buffer.

Mask an AR camera using a custom alpha shape

July 14, 2012 - 1:57pm #7

To do this using depth masking you would create a mesh with a open area in the center and apply a depth mask to that mesh. So only the area in the center is rendered and anything covered by the depth mask region, from the camera perspective, is not.

Mask an AR camera using a custom alpha shape

July 14, 2012 - 12:11pm #6

Hi there,

actually i want to create something similar..i have a mesh on the center of the screen with depth mask material..but i dont know how to make my augmented reality view only rendered on this "depth mask" view not on the AR camera..can you give me any code to do this??

Mask an AR camera using a custom alpha shape

July 13, 2012 - 12:11pm #5

Thanks for giving this a try David, looks like render texture is the way to go.

 

Vince

Mask an AR camera using a custom alpha shape

July 10, 2012 - 2:41pm #4

I'm seeing

07-10 17:38:04.953: E/Unity(10764): Unsupported texture format - needs to be ARGB32, RGBA32, BGRA32, RGB24, Alpha8 or DXT
07-10 17:38:04.953: E/Unity(10764): 
07-10 17:38:04.953: E/Unity(10764): (Filename: ./Runtime/Graphics/Image.cpp Line: 1176)

The ARCamera only supports a select set of formats.

Take a look at the BackgroundTextureAccess sample for an alternative approach to adding effects to the rendered camera image, using shaders on a background texture.

Mask an AR camera using a custom alpha shape

July 10, 2012 - 2:12pm #3

Thanks for the reply David.  Got everything working now.

One question remains:

I'd like to add an Pro Image Effect to the AR Camera (works fine in Editor) but when I run on mobile, the camera feed is completely black.  All I did was import the Pro Image Effects and add the Fisheye script to the AR camera.  The effect works in the editor, but not when run on Android/iOS.

Am I missing something?  I understand that Image Effects are generally a no-no on mobile devices, but I'd like to get it working on the mobile devices and test it so that some of the higher end devices that can handle the effect will have it while unsupported devices will default to a non-post-processed AR camera feed.

 

P.S. I have a fully licensed Unity Pro iOS/Android

Mask an AR camera using a custom alpha shape

July 9, 2012 - 9:14pm #2

Something like this? - http://www.moosejaw.com/moosejaw/shop/content_xraypr

That effect can be accomplished with depth masking. You would need to apply a depth mask to a mesh, or composition of meshes, with a 'viewport' in the center, and make these children of the ARCamera so that they follow the position and orientation of the ARCamera. Those regions of the augmentation applied to the target that are covered by the depth masked regions, from the ARCamera's perspective, will not be rendered. This construction will cause the augmentation to only be rendered within a restricted region of the ARCamera view.

Log in or register to post comments