A shader is a set of algorithms that determines the appearance of a 3D object's surface. They're particularly useful for applying complex changes to a material.
You don't need to know how to code to create a shader. You can use the Patch Editor to create and connect a group of patches called a visual shader.
Visual shaders can be used to determine the appearance of an object instead of applying Spark AR Studio's built-in shaders through the Inspector.
Like other patches in Spark AR Studio, there are different types of patch to choose from.
Shader patches can be connected to other visual programming patches — but you always need to connect the output port of a visual programming patch to the input of a shader patch.
Shader patches use some different data types to other patches in Spark AR Studio.
This is an example of a visual shader that has three types of patch — an asset patch (the orange patch) representing a wall texture, two intermediary patches (a multiply and value patch) and a consumer patch (the yellow patch):
By connecting these patches, we've multiplied a color and a texture, and applied the result to a material.
The texture in this example is an asset we've imported to AR Studio. It's a 4-channel Texture, which means it contains both the color and alpha components of the texture asset. It's represented by a patch named wall-diffuse-texture. We made this patch by dragging the texture from the Assets panel, into the Patch Editor.
We then created a material by clicking Add Asset at the bottom of the Assets panel and selecting Material.
Because we want to apply the texture to this material, we created a patch that represents the Diffuse property of the material. To do this:
If we connected the RGBA port of the wall-diffuse-texture patch to the Diffuse Texture port in Material0, we'd apply the texture to our material in it's original state. We'd connect the RGBA port because our texture has 4 channels.
Intermediary patches are inserted by right clicking anywhere in the Patch Editor, and selecting a patch from the menu.
You can change the data type and add values to the Value patch. In this example we've clicked the patch to reveal the menu at the bottom, and changed the type from Number to Color. We chose a color by clicking the square to the right of Input.
Multiply is a math patch. That means it takes the information from the patches connected to its input port, and performs a math operation on this information.
In this case, we've connected:
To see the effect, we clicked restart icon in the Toolbar.
As a result, we've multiplied the color from the Value patch, with the texture.