Adding iris tracking in Spark AR studio exposes details about the position and rotation of a user’s eye. This allows you to create different effects, including changing the appearance of someone's eyes, by tracking 3D objects to the eye.
In this tutorial, you’ll learn how to add iris tracking to an AR effect. Download this example project to try this effect. In the unfinished project, you'll see:
You can adapt the example project to make your own iris tracking AR effects.
The eyeball 3D objects will be visible in the Viewport and Simulator. They’re positioned behind each other in the middle of the face because they’re not tracked to the eyes yet.
Open the Patch Editor and drag faceTracker0 from the Scene panel into the Patch Editor. You'll see a group of 3 patches: Face Finder, Face Select and faceTracker0.
The Face Finder patch is usually used to detect and follow the entire face. In this effect we need to capture the positioning and orientation of the eyes. To do this, you’ll need to attach an Eyeball patch:
Here's how your graph will look:
The Eyeball patch has 6 outputs. For this effect you'll use the following ports:
You'll need to connect these ports to patches that represent the Position and Rotation properties of the left and right eyeball 3D objects:
To do this:
This will create 4 yellow patches, to represent these values:
Your finished graph will look like this:
The 3D eyeball objects should cover and track the eyes in your effect:
You can apply any texture you wish to the 3D eyeball objects.For example, you can experiment by importing copyright-free images and using them as textures or creating your own.
To apply the the texture included in this tutorial:
Your effect will look like this:
In the Assets panel there’s a patch asset called Eyeball Shader. This is made of several visual shader patch graphs. The patch asset can be used to apply a more complex texture to the material covering the eyeball 3D objects.
You can easily customize this texture by editing the values in the Eyeball Shader to change how the eyes look.
Start off by removing the eyeball texture already applied to the material.
You can use the Specular to define the shininess and highlight color of the texture that we’ll apply with the Eyeball Shader. To apply the strong shiny surface highlight for this effect:
Connecting the patch asset to the material
In the Patch Editor:
Your graph will look like this:
You can easily customize your effect by editing the values in the Eyeball Shader to change attributes such as Iris Color, Pupil Color and Opacity. For example, to change the Iris Color:
If you choose to keep the original values in the Eyeball Shader your final effect will look like this!