Skip to content

What are Shaders

MochiesCode edited this page Oct 16, 2026 · 1 revision

A shader is a small program that runs on the graphics card and decides what a surface looks like on screen. Every visible object in Unity is drawn by one: it places the mesh on screen, then works out the color of every pixel the mesh covers from its textures, the lights around it, and the camera's point of view. A material is the asset that picks a shader and stores its settings, like colors, textures, and feature toggles.

This page covers how shaders work, how Unity's Built-in Render Pipeline draws objects with them, how to set them up with materials, and what makes them expensive. For how physically based shaders light surfaces and which textures they use, see What is PBR?

How Shaders Work

Each time an object is drawn, the graphics card runs its shader in stages:

  • Vertex stage: Runs once for every vertex in the mesh. It works out where each vertex lands on screen, and passes along data like UVs, normals, and vertex colors. Effects that move the mesh, like wind, waves, and outlines, happen here.
  • Rasterization: The graphics card fills in the triangles between the vertices, finding every pixel each one covers, and blends the vertex data smoothly across each triangle. This stage isn't programmable.
  • Fragment stage: Runs once for every pixel the mesh covers, and outputs that pixel's color. Texture sampling, lighting, reflections, and most effects happen here.

Some shaders add optional stages after the vertex stage:

  • Tessellation: Splits triangles into smaller ones so the mesh can hold finer detail. Water (Tessellated) πŸ”’ uses it to add detail to its waves up close.
  • Geometry: Creates, moves, or removes whole triangles. Uber X's πŸ”’ Special Features use it for effects like clones and wireframe.

Forward Rendering

Unity's Built-in Render Pipeline can draw a scene with forward or deferred rendering. VRChat uses forward rendering, where each object is drawn and lit on its own, one light or group of lights at a time, and Mochie's shaders are made for it.

Passes

A shader is made up of one or more passes. Each pass is a separate draw of the object with its own job, and Unity picks which ones to run depending on what it's rendering and which lights reach the object.

  • ForwardBase: The main draw, which every visible object runs once per frame. It includes the brightest directional light, ambient light from the skybox, lightmaps and light probes, reflection probes, emission, and up to four vertex lights (see Lights).
  • ForwardAdd: Runs once for each extra pixel light reaching the object, like a point or spot light, and adds that light on top of the base pass. An object lit by three realtime point lights is drawn four times.
  • ShadowCaster: Draws the object into the shadow map of each realtime light that casts shadows, so it can cast shadows onto other objects. Unity also uses it to draw the camera depth texture. An object whose shader has no shadow caster pass doesn't cast shadows and doesn't show up in the depth texture.
  • Meta: Never runs in game. Lightmappers like Unity's and Bakery use it while baking to read the surface's color and emission, which is how emissive materials light up the scene in baked lighting. World shaders with emission, like Standard, Glass, and Water, have a Global Illumination setting that controls this.
  • GrabPass: Copies everything drawn on screen so far into a texture the shader can read, for effects that see through or reflect the scene: refraction in Glass, Water, and Uber, distortion in Particles, blur in Underwater Visuals, Screen FX's effects, and screen space reflections.
  • Other passes: Some shaders add their own. The Uber (Outline) variants draw the mesh a second time, slightly enlarged and inside out, to make the outline.

Lights

Each realtime light reaching an object is calculated in one of three ways:

  • Pixel light: Calculated for every pixel, with sharp highlights, and the only kind that can cast realtime shadows. The brightest directional light is part of the base pass, and every other pixel light adds a ForwardAdd pass.
  • Vertex light: Calculated per vertex in the base pass, for up to four point lights. Cheap, but soft and blurry, without sharp highlights. Uber's Vertex Intensity sets how strong they are.
  • Spherical harmonics (SH): Lights left over after that are folded into the object's ambient lighting, the same soft lighting light probes give. The cheapest and softest of the three.

The light's Render Mode decides which one it gets:

  • Important: Always a pixel light.
  • Not Important: Never a pixel light.
  • Auto: A pixel light while there's room, brightest first, up to the Pixel Light Count in the Quality settings. In VRChat, the game's own quality settings set the count, not your project's.

Lights that don't become pixel lights become vertex lights, then SH. Baked lights aren't part of this at all, since their light is stored in lightmaps and light probes.

Draw Order

Objects draw in order of their material's render queue, from low to high:

Queue Used for
1000 (Background) Skyboxes and backdrops
2000 (Geometry) Opaque surfaces
2450 (AlphaTest) Cutout surfaces, like foliage and chain-link fences
3000 (Transparent) Blended surfaces, like glass, water, and particles
4000 (Overlay) Effects drawn over everything, like screen overlays
  • Opaque objects (queues up to 2500) draw roughly front to back, so pixels hidden behind closer surfaces can be skipped. They write to the depth buffer, which records how far away each pixel is.
  • Transparent objects (queues above 2500) draw back to front by each object's center, so the ones behind are blended in first. They usually don't write to the depth buffer, and they aren't included in the depth texture.
  • Sorting by center can go wrong when transparent objects overlap or one sits inside another. Fix it by moving one of them earlier or later with the material's Render Queue Offset, or Render Queue in inspectors that set the queue directly.
  • Effects that read the opaque scene, like screen space reflections and refraction, need a queue above 2500 so the scene is already drawn when they run. The inspectors set the queue for you; see Render Queues.

Materials

A shader on its own is just a program. To use one, make a material with it and put that material on a renderer. One shader can be used by any number of materials, each with its own settings.

Making a Material

  1. In the Project window, right-click and select Create > Material.
  2. Select the material. At the top of the inspector, open the Shader dropdown and pick one of Mochie's shaders from the Mochie submenu. Standard can also be made directly with Create Material.
  3. Set it up in the inspector: assign textures, set colors, and turn on the features you want. Each shader's page explains its settings, and Texture Import Settings covers how to import its textures.

Assigning Materials

  • Drag the material from the Project window onto the object in the Scene view, or into a slot in the Materials list of its Mesh Renderer, Skinned Mesh Renderer, or the Renderer module of a Particle System.
  • A mesh can be split into submeshes, and each slot in the Materials list draws one submesh, in order. Slots past the number of submeshes draw the last submesh again with their material, on top of the first.
  • Every object using the same material shares it, so changing the material changes all of them. Duplicate it (Ctrl+D) to make a variation.

Switching Shaders

Changing a material's shader keeps the settings both shaders have in common, matched by their internal names, and the rest start at the new shader's defaults. Expect to go over the material again after switching, especially between shaders from different authors. Between Standard's variants, Global Standard Settings swaps many materials at once and keeps every setting.

Feature Toggles

Most of the toggles and dropdowns that turn features on, like a section's toggle or a mode dropdown, switch the material to a different version of the shader with only those features compiled in. Features that are off aren't in the material's version of the shader at all.

Animation clips can't switch the shader's version, so animating one of these toggles doesn't turn the feature on or off in game. Leave the feature on and animate its strength, color, or other values instead, or swap to another material that has it on.

Performance

The biggest factors in what shaders cost:

  • Screen coverage: The fragment stage runs for every pixel an object covers, so a cheap shader on a wall that fills the view can cost more than an expensive one on a small prop.
  • Overdraw: Each layer of transparency is drawn on top of what's behind it, so stacked transparent surfaces like particles, glass, and hair run the fragment stage several times for the same pixel.
  • VR: Every pixel is drawn once for each eye, at a high resolution.
  • Pixel lights: Each one draws every object in its range again. Use as few as you can, keep their ranges small, and set lights that don't need sharp highlights or shadows to Not Important. Baked lights cost nothing at runtime.
  • GrabPass: Copying the screen is expensive, especially in VR, so effects that use one cost more than their settings suggest.
  • Extra material slots: Each slot past the submesh count draws the last submesh again (see Assigning Materials).
  • Unused features: Turn features you don't use off instead of setting their strength to zero. A feature that's off costs nothing (see Feature Toggles).

πŸ”’ = Patrons only


Avatar Shaders

Uber
Uber X πŸ”’
Uber X (Outline) πŸ”’
Taken πŸ”’
Avatar Props πŸ”’

Environment Shaders

Standard
Water
Water (Tessellated) πŸ”’
Underwater Visuals
Glass
Splat Mapping πŸ”’
LED Screen

Special Effects Shaders

Particles
Particles X πŸ”’
Screen FX
Screen FX X πŸ”’
Corruption πŸ”’

Links

Clone this wiki locally