What is the most expensive light type in Unity 3D ?

Which one of the light types in Unity 3D is the most expensive for the GPU and/or CPU ?

Directional light,point light,etc,etc,…

Thanks.

Would have to say directional since it lights the entire level followed by point since its 4 spotlights followed by spotlight.

All depends on what the lights pointed at.

Each light = +1 drawcalls per mesh it hits (based on shaders).

Directional light is definitely the fastest as long as the object would be hit by the other types of lights. I’m not sure how the performance is affected based on what you’re talking about, though.

How do you figure that?

Only for forward-rendered pixel lights.

spot light and point light technically could be the same, cause one is just the other with some cookie. but for optimization spot lights are normally done a bit different :wink:

Point light is definitely the most expensive but not due to “being 4 spot” (it would be 6 by your logic by the way, one per projected cube surface direction), but because its 360 degree light casting and thus the most complex math

but if you don’t have shadows, the lights themself are not that much of a problem actually, pixel shader performance is normally strong enough for that unless you totally overdo the materials.

Draw calls skyrocket if you have alot of meshes and add in a directional light or 2. (pixel lights since vertex lights look odd with low polycounts)

My mistake for some reason I was thinking of the spot lights focus angle when I posted. But they do Effect alot more meshes usealy.

you get at max 1 additional drawcall per mesh per light
if you get more then you have shadows (blob or real) which force every touched mesh to redraw (-> new drawcall)

And how is real-time(dynamic) light calculated in Unity,on de CPU or on the GPU or on both ?

the pixel light is pure gpu

for vertex lights I’m not 100% sure due to the capabilities etc it offers. normally its gpu thought too

I’m sorry for the insane necroposting, but since this is the only post on this topic i feel like i need to clear this up for the people who might still stumble upon this post.

The way forward rendering works in Unity, is that the ForwardBase pass always renders one directional light + ambient lighting, even if there is no directional light in the scene (in this case, it is rendered with zero intensity). This means that if you choose to have a spotlight instead of a directional light, all objects lit will actually be rendered with two passes. Directional lights are also mathematically the cheapest, since they have uniform direction and no attenuation (falloff). For other lights, you need to calculate light direction per vertex and attenuation per pixel.

Spot lights are cheaper than point lights, both in GPU instructions and from the fact that a cone can generally cull more objects than a sphere. Most significantly, shadow calculations are much more complex for point lights, where they typically create a cube depth map rendering all affected objects from 6 different directions (in a single pass, though). Spot and directional lights use a single light space matrix.

For deferred rendering, all lights are very cheap and won’t add to the draw call count (at least not for opaque objects), but shadows are still expensive.

14 Likes

@khalvr Beautiful and concise explanation, thank you! :smile:

2 Likes

This isn’t very accurate. Directional lights are “free” in forward and deferred, as they’re done in the initial forward pass. Documentation indicates that additional directional lights after the first one are added in as spherical harmonics which, if I recall correctly, can also be done in the initial forward pass and are cheap.

The statement “each light = +1 drawcalls per mesh” is VERY wrong. This is ONLY true in forward rendering mode, which isn’t always used. Deferred will not incurr an additive pass per light per on a mesh. Additionally, you can get away with multiple realtime lights in forward by making them vertex lights, as it’s done in the initial forward pass too.

This is all ignoring shadows.

The differences in calculation of lighting between the various differences in light types is not going to have an impact. The performance considerations are all about the consequence of the light, which requires context such as: where is it, is it casting shadows, what rendering mode, how complex is the shader of the mesh it is hitting and etc.

**edit: @khalvr ** breaks down the actual cost of the type of light very well, with specifics.

6 Likes