World Eraser Template
With the ML Eraser Custom Component, Lens Developers can build unique AR experiences powered SnapML to alter and remove real world content in real-time. The World Eraser Template combines the power of World Tracking with SnapML's ML Eraser Custom Component to erase objects on screen independently from the camera position.
ML Eraser Component
The ML Eraser Component contains various inputs that can be modified manually or via a script. It can be introduced to a project by dragging it from the resources panel onto a new Scene Object.
- Input Mask: The mask texture to be inpainted.
- Eraser Mix: Controls the opacity of the inpainting while blending with the Input Mask.
- Output Material: The material created from the Custom Component.
- Use fallback: Allows for a fallback option that uses a shader instead of the ML inpainting neural network. In this case we use a naive solution which is more blurry.
Template Walkthrough
There are two example scripts in this template: Area Select and Paint to Erase.
Area Select
The Area Select script enables developer to outline a selection on their device in 2D to estimate the area to erase. Once selected, an unlit 3D cylinder is generated in the Mask Camera in the approximate world region.
You can change the Dilation Factor to see how it affects the Area Select example.
The Mask Camera’s Render Target is used as the mask for the ML Eraser. Users are able to use multiple masks that can be placed in the world, along with an undo button allows the user to remove the masks as well.
Since world tracking is on, you can place another 3D model on top of the erased area.
There are some options provided to adjust the Dilation Factor, how far beyond the selection the cylinder should extend, and to replace the erased area with a 3D model of a duck.
Paint To Erase
To enable this example, enable Paint To Erase
and make sure to have Area Select
disabled.
The Tap To Erase script places 3D spheres at the location of the user’s tap, with options to set the size of the sphere. You can combine multiple spheres together to form more elaborate masks.
To visualize the mask, you can change the Render Target of the Mask Camera to “Render Target”.
Once swapped, you will see mask content now render on the screen.
Previewing Your Lens
You’re now ready to preview your Lens! To preview your Lens in Snapchat, follow the Pairing to Snapchat guide.
What's Next?
Now that you have learned about how to create different types of world easer effects with ML Eraser, take a look at some of the other Templates that use ML Eraser.