How expensive is unbaked lighting?
This section covers exactly what the cost of each type of light is.
As we're measuring cost, our currency is draw call passes. A draw call is Unity sending data to the graphics card to render. We won't consider the cost of actually shading pixels in this section - if it doesn't add passes, we'll call it free. Otherwise, we'll note the number of draw call passes it incurs.
Let's consider a totally blank scene with no lights.
The first light we add isn't a real light, but the Skybox. This provides ambient light, and is free. The lighting from the skybox goes into the light probes, which we'll cover more later.
The second light we add is a Directional Light. This provides the main lighting, and is free. Every lit shader will render one directional light, no matter what.
However, that's assuming it casts no shadows. If we turn the shadows on, we reach our first additional cost. Unity must render the shadow cascades - a set of textures that contain the shadows for everything in view. VRchat will render 4 splits, each of which can contain everything visible from the light's perspective, which in the worst case will render everything 4 times. (Also, shadows do not use occlusion culling.)
There is an additional cost. When shadows are enabled, Unity will need to render a depth buffer which renders a depth pass for everything visible. This is rendered beside the main shadow pass. The depth buffer is really useful for shader effects, but it is an extra cost.
The third light we add is a Point Light. This adds 1 pass to everything within its radius, and renders everything it touches again.
Our Point Light has no shadows. If we enable shadows, Unity will render a cubemap - a six sided texture - from the light's perspective with the shadows. This means things within the light's radius can be rendered up to 6 times.
The fourth light we add is a Spot Light. It works the same as a Point Light, adding 1 pass to everything within its radius.
If we enable shadows on the Spot Light, it will render 1 pass for the shadows. It only needs one because it's a Spot Light.
The fifth light we add is an Area Light. Nothing happens, because Area Lights can only be baked.
If we set these lights to Baked, and bake the lighting, they will no longer have a cost. They'll be merged into the light probes, which previously contained only the ambient light.
Every non-static object can read the light probe data Unity provides based on its position. It is the cheapest form of lighting, even though it can represent an arbitrary number of lights and their bounces - which can't be represented normally.
Baked lights are great because they're cheap and look good.
3 Comments
This seems like a great guide for beginners. Maybe we should add a tag for that!
That sounds good to me! (I don't know how to add tags to pages)
I made a page for that! 😁 https://vrclibrary.com/wiki/books/rules-content-guidelines/page/how-to-tag-your-content