Skip to main content
Version: 5.x
Supported on
Snapchat
Camera Kit

Ground Segmentation

Ground Segmentation is available in Lens Studio Asset Library. Import the asset to your project, create new Orthographic camera and place the prefab under it.

The ground segmentation template allows you to modify the ground by using a ground segmentation mask provided by the ML Component. Additionally, objects in the scene can be occluded when they are placed beyond the ground

Tutorial

Guide

Floor Examples

There are 3 different default ground examples to explore, check them out simply by enabling/disabling them in the Scene Hierarchy panel under Ground Segmentation [OBJECTS_HERE] > Floor Example.

Each of these examples come with a special material that you can modify. You’ll find all materials in the Asset Browser panel under Materials > Advanced Ground Examples.

Ice Parallax

The Ice Parallax material uses duplications and Parallax Coord in the Material Editor to achieve depth in textures. Try adjusting the Depth parameter on the material to change its depth. Adjust Loop Iterations inside the graph to change the amount of parallax effect. Adjust the Brightness/Contrast Node to get different color effects.

There are also 2 sets of textures for the Ice Parallax example, feel free to switch them for different styles.

The Tiled Ground

The Tiled Ground Material allows you to tile a texture across the floor. To get started, select the tiled_ground Material in the Asset Browser panel. You can try replacing Base Texture on tiled_ground with your own image in the Inspector panel.

Simple Ground

The Simple Ground material is a simple Unlit Material with a default white texture, try replacing the texture with your own for an unlit tiling effect on the ground.

Applying Ground Mask

Ground Mask allows you to mask out parts of your virtual ground based on a texture input. To enable ground mask, check the Show Ground Mask option on any of the ground materials above, and linkGround Mask [FOR GROUND MATERIALS]under the Textures folder into theGround Mask Textureslot.

To edit the shape or position of the ground mask, edit the material attached to theGround Mask[FOR_GROUND_MATERIAL]object. For example, you can bring in your own texture by selecting the object in the Scene Hierarchy panel, then in the Inspector panel replace the Texture field with your own texture.

To make any object part of the ground mask, set their layer to the GroundMaskCamera layer. Areas rendered as white on this layer by the Ground Mask Camera will mask the ground material.

Creating Custom Materials for Ground Segmentation

To create additional materials which will be occluded beyond the ground, you can duplicate the materials labeled [DUPLICATE_ME] . These materials are just the regular default Graph Unlit and Graph PBR with the additional  ground mask nodes explained in the next section.

Modifying Graph Materials to Use Ground Segmentation

Materials with ground segmentation are any graph materials with additional nodes used for occlusions.

The Color’s alpha value represents the opacity for that part of the object. To learn more about Graph materials, check out the Material Editor guide.

To make a material from scratch, go to the Resources folder and select + > Graph Materials. Then copy paste the Occluder section from either of the materials marked [DUPLICATE_ME] in the Asset Browser panel under Materials > Advanced Ground Example. Drag your mouse around the Occluder section, right click and press Copy. Finally, in the material you want masked, right click, press Paste and connect it to the Alpha value.

If custom materials already have its alpha channel, make sure to use the Multiply Node with the Alpha output from the Occluder group.

Take a look at the example materials to see different ways of connecting the Occluder node to your Color(Pixel)’s Alpha value.

 Make sure Script Name of the u_segmentationTexture node is set as u_segmentationTexture.

With your nodes attached to the alpha value, we need to set the materials blend mode to Normal so that it will be used. In the Inspector panel, make sure to have Blend Mode set as not Disabled.

We also need to pass in our ground segmentation mask to this material to be used. To do this, in the Inspector panel, link processed_segmentation_texture to u_segmentationTexture, which can be found under Segmentation Resources [DO_NOT_DELETE] > Render Targets.

To apply ground mask to your custom material, rather than feeding the Occluder group directly to the object’s material, we will pass it through our Mask Camera Occluder group. Specifically, we will connect the Ground Seg Occluder output to the X port of the Multiply Node, and the Default port of the If / Else node.

Finally, as before we will feed in the segmentation texture we want to use. Select the modified material in the Asset Browser panel, then in the Inspector panel, toggle Show Ground Mask, and pass in Ground Mask [FOR GROUND MATERIALS] under Textures to the Ground Mask Texture field.

Animated Objects

This template also comes with the World Object Controller that you can use to add movable objects to your Lens. You can delete this object if you do not need it.

Put your objects under the World Object Controllerin order for it to be dragged around and manipulated.

To have your animation play different animations depending on whether it is being picked up, link its Animation Mixer Component to the Animation Mixer slot on the script attached to Pickup Animated Object Controller. Make sure to name the animations according to your object’s animation, in the case of the example object, it is Idle and PickUp.

if you just want your object to play the animation it has automatically, enable Autoplay on its Animation Mixer component, otherwise animation will be played by the PickupAnimatedObjectController script.

If your object doesn’t have animations, you can disable or delete the Pickup Animation Object Controller object.

Ground segmentation requires surface tracking to be active. If you want to disable objects when ground segmentation is unavailable, you can select Device Tracking [DO_NOT_EDIT] in the Scene Hierarchy panel, then in the Inspector panel under the Switch Tracking script, enable the Advanced checkbox and add your objects there.

Previewing Your Lens

You’re now ready to preview your Lens! To preview your Lens in Snapchat, follow the Pairing to Snapchat guide.

Was this page helpful?
Yes
No