Introduction to materials and shaders
Understand how materials and shaders control the appearance of surfaces in Unity Spark, how a shader graph becomes a material, and what each kind of shader graph is for.
Read time 4 minutesLast updated 3 hours ago
Every visible object in your game draws with a material. A material decides the appearance of a surface: its color, how shiny or rough it is, and whether it glows or lets light through.
Materials, shaders, and renderers
A shader is a set of instructions that tells the graphics card how to draw a surface. A material uses a shader and sets its values, such as a color or a texture, which is an image wrapped onto the surface.
Think of a shader as a recipe, and a material as one dish made from it with your choice of ingredients. Many objects can share one material, and many materials can use the same shader with different values.
Unity Spark includes ready-made shaders, such as Lit, which reacts to lights and shadows, and Unlit, which draws a flat color that lights don't affect. For most objects, a material with one of these shaders is all you need. For instructions, refer to Create and apply materials.
An object holds its materials in its renderer, the component that draws it, such as a MeshRenderer or a SpriteRenderer. A model can have several material slots, one for each part with a different appearance, for example, one for the main surface and others for trim.
Change a read-only material
Built-in materials, and materials that come with an imported model, are read-only. To change one of these materials, you need to make an editable copy:
- Select the material in the Project window.
- Click Edit Material.
The copy replaces the original only on the object you changed.
Create a custom shader with a shader graph
When a ready-made shader can't create the effect you want, such as water, a hologram, or an object that dissolves, create your own shader in the Shader Graph window. Instead of writing code, a shader graph lets you create a shader by connecting boxes, called nodes, on a canvas. Each node does one small job, such as reading a texture, picking a color, or adding two values. You connect nodes with wires, and the result flows into the Master node, which decides the final appearance of the surface.
A shader graph has the following workflow:
- You create the graph in the Shader Graph window.
- You select Apply, which turns the graph into a shader that the graphics card can run.
- You choose the graph as the Shader of a material. The graph's properties appear as fields on the material, so each material can use different values.
- You assign the material to an object.
When you apply a change to a graph, every material that uses it updates. For instructions, refer to Create a Shader Graph material.
Choose a shader graph kind
Each shader graph has a Kind, which decides what the graph draws and where you use it.
Kind | Description |
|---|---|
| Unlit | Use for a material surface that lights don't affect. Ideal for glows, holograms, and flat styles. |
| Lit | Use for a material surface with lighting, shadows, and reflections. |
| Visual Effect | Lots of small moving pieces, called particles, that the graphics card moves, such as sparks, trails, and ribbons. Use this type of shader graph in a VisualEffect component. |
| Instancing | Many copies of one 3D model drawn at once, such as grass, rocks, or crowds. Use it in an InstancedMeshRenderer component. |
| Fullscreen | Use for an effect drawn over the whole screen, such as a custom color filter, which a script enables. It draws only in Play mode. |
| Compute | An advanced program that runs on the graphics card to compute data, which other shaders then use. |
Only Unlit and Lit graphs appear in a material's Shader list. The other kinds are advanced. To use the other kinds, ask the AI assistant to create the effect. For simple particle effects, use a Particle System object instead of a Visual Effect graph.
Write custom shader code
Most games never need custom code. To write your own shader code, use a Custom Function node in a graph, or a Compute graph with Use shader code enabled. Shader code in Unity Spark uses WebGPU Shading Language (WGSL). Unity Spark can't import shader files, and doesn't run High-Level Shading Language (HLSL) code.
Let the assistant create materials
The assistant can create materials, set their values, and assign them to objects. When an effect needs a custom shader, it creates a shader graph material for you and checks the result. For example, you can enter the following prompts:
Make the lake shimmer like water.Give the shield a pulsing glow.Make the enemy dissolve when it dies.Toon-shade the whole scene.