Patch Editor: Creating Color Gradients

In Spark AR Studio, you can use the Patch Editor to add colorful gradients to materials. This is a great technique for building backgrounds and colorful filters.

In this tutorial, we'll look at how gradients are created in the Patch Editor. We'll then add a gradient to the whole scene, and to a signed distance field shape.

Setting up your project

Start by opening a new project in Spark AR Studio and adding a rectangle.

The rectangle will render the color gradient in the scene, and later be used to create a color filter that covers the whole scene. You can experiment with gradients using any other object, if you prefer. To add a rectangle:

  1. In the Scene panel, click Add Object.
  2. Select a Rectangle from the menu.

Make a couple of edits to the rectangle's properties in the Inspector. These edits will make the rectangle cover the device screen. Set

  1. Width to Fill Width.
  2. Height to Fill Height.

Next create a material for the rectangle. You'll use the Patch Editor to add the gradient effect to this material. To create a material:

  1. In the Inspector, go to Materials and click +.
  2. Select the material in the Assets panel.
  3. In the Inspector, set the Shader Type to Flat.

Opening the Patch Editor

Now it's time to open the Patch Editor, and create a patch to represent your material.

The patch representing your material will be connected to a series of gradient patches, rendering the gradient in the scene.

To create this patch:

  1. In the Assets panel, select the material.
  2. In the Inspector, go to Diffuse and click the arrow next to Texture.

This will open the Patch Editor and add a yellow patch representing the material:

Creating a gradient with 2 colors

You'll add 2 more patches to create a gradient with 2 colors - a Gradient patch and a Mix patch:

  1. Right-click in the Patch Editor to open the patch menu.
  2. Search for and select the Gradient and Mix patches.

You'll now see 3 patches in the Patch Editor:

In the Mix patch, use the dropdown menu at the bottom of the patch to change the data type to Color:

Now connect the patches. Connect:

  1. The output of the Gradient patch to the Alpha input in the Mix patch.
  2. The output of the Mix patch to the Diffuse Texture input in the material patch.

Setting the colors

Set colors for the gradient by adjusting the values in the Mix patch. The color set in the top of the patch will be the starting gradient. Below, we've added colors to the Mix patch:

Here's how the gradient appears:

Changing the gradient's shape

The shape of the gradient is Horizontal by default. You can adjust this to either a vertical or circular gradient by choosing an option from the dropdown menu inside the patch.

Gradients with more than 2 colors

Use the Gradient Step patch to blend a series of more than 2 colors together.

The first Gradient Step patch in a graph creates a 2 color gradient. Each Gradient Step patch added after that adds another color.

To build a gradient with 4 colors, start by creating the patches. Right-click in the Patch Editor and select:

  1. 3 Gradient Step patches
  2. 1 Gradient patch.

To build the graph, connect:

  1. The output of the Gradient patch to the Gradient input in a Gradient Step patch
  2. The outputs of the Gradient Step patch to the top 2 inputs in another Gradient Step patch.
  3. The Output port in your final Gradient Step patch to the Diffuse Texture input in a material patch.

Here's how your graph will look:

Set colors for the gradient in the boxes next to Previous Step and New Color.

Adjusting the Start Range and End Range in each Gradient Step patch will define where each color starts and ends.

Making a gradient filter

Easily add a colorful filter to your scene by adjusting the Opacity property of the material your gradient is applied to in the Inspector.

You could combine this technique with segmentation to show the gradient in the background of the effect only, or add different gradients to different parts of the scene.

Was this article helpful?