A Virtual Reality or Augmented Reality device allows for guided viewing in a controlled environment; the enhanced capabilities of the user experience can make it ideal for eye related solutions. When working on developing a solution, you may come across an issue when trying to render objects to one of the user’s eyes. Normally, players using a Vive, Occulus or HoloLens are able to see rendered objects in both eyes. Simply put, both of the user’s eyes are seeing the exact same imagery, mimicking real life perception. However, there are options within Unity to allow for rendered objects targeting only one eye instead of both.
Targeting Both Eyes
I started working on a solution to this problem. The project I was working on involved certain objects being rendered for the left eye, and another set of objects being rendered only for the right eye. At first I attempted to write a shader that would do this for me, however an even simpler solution is to use the HoloLens tools given to you in the Inspector. Let us first look at what the HoloLens Camera Components look like in the Inspector:
The Green Arrow points to the tag of the camera. Notice how it is untagged. That is because I am actually using two cameras. If I want half of the objects to render only to the user’s left eye, and the rest to render to the user’s right eye, I create two cameras, one tasked with rendering to left and vice versa. Now on my left camera, I leave it untagged. My right camera has the Main Camera tag on it. (Do not have two cameras with the main camera tag on both. Leave one with the main camera tag, and the other one as untagged. The HoloLens does not like having two main cameras. Don’t worry, the untagged camera will still render.)
The Blue Arrow points to the culling mask, the layers that this HoloLens will render. To the right of the tag field, you will see the layer field. I created a tag for my Left Eye objects called “Left.” Therefore, the “left layer” will designate objects for the left camera. Additionally, I included the “UI”, and “Ignore Raycast” layers in my culling mask. This will allow any objects on those layers rendered to the left eye. I repeated this process for the right eye camera, setting the right objects to “right” layer.
Finally, at the bottom of the picture, the Red Arrow points to the Target Eye setting. This special component option sets that camera to only render to that eye. Thus, the objects on the left layer are rendered only to the left camera, which only shows to the left eye.
Working with new technologies, these type of problems will usually emerge. Creative applications require the testing of device limitations. In this case, the use of this feature is one of the main components of the application. By using two cameras, and making sure objects are layered correctly, objects render to certain eyes easily using Unity component settings.