Performance of Unity shaders
Reference Manual > Built-in Shader Guide > Performance of Unity shaders

Performance of Unity shaders

There are a number of factors that can affect the overall performance of your game. This page will talk specifically about the performance considerations for shaders. There are two basic categories of shaders from a performance perspective, Vertex-Lit, and Pixel-Lit.

Vertex-Lit shaders are always cheaper than Pixel-Lit shaders. These shaders work by calculating lighting based on the mesh vertices, using all lights at once. Because of this, no matter how many lights are shining on the object, it will only have to be drawn once.

Pixel-Lit shaders calculate final lighting at each pixel that is drawn. Because of this, the object has to be drawn once to get the "ambient" image, and once per light that is shining on it. Thus the formula is N+1 draws, where N is the final number of pixel lights shining on the object. This increases the load on the CPU to process and send off commands to the graphics card, and on the graphics card to process the vertices and draw the pixels. The size of the Pixel-lit object on the screen will also affect the speed at which it is drawn. The larger the object, the slower it will be drawn.

So pixel lit shaders come at performance cost, but that cost allows for some spectacular effects: shadows, bump-mapping, good looking specular highlights and light cookies, just to name a few.

Remember that lights can be forced into a pixel or vertex mode. Any vertex lights shining on a Pixel-Lit shader will be calculated based on the object's vertices, and will not add to the rendering cost or visual effects that are associated with pixel lights.

Out of pixel lit shaders, they come roughly in this order of increasing complexity: