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 the sample content follow along with this tutorial.
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.
This effect uses the Patch Editor. If you haven't used the Patch Editor before, it's worth learning the basics Follow our tutorial or find more information in our documentation.
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:
The Eyeball Position ports in the Eyeball patch to the 3D Position ports of their corresponding object patches.
The Eyeball Rotation ports in the Eyeball patch to the 3D Rotation ports of their corresponding object patches.
Your finished graph will look like this:
The 3D eyeball objects should cover and track the eyes:
To apply the the texture included in this tutorial:
Your effect will look like this:
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.
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.
Removing the Eyeball texture
Start off by removing the eyeball texture already applied to the material.
Connecting the patch asset to the material
In the Patch Editor:
Your graph will look like this:
Customizing the material
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!