Light
Reference Manual > Components > Rendering Components > Light

Light

Lights will bring personality and flavor to your game. You use lights to illuminate the scenes and objects to create the perfect visual mood. Lights can be used to simulate the sun, burning match light, flashlights, gun-fire, or explosions, just to name a few.


The Light Inspector

There are three types of lights in Unity:

Lights can also cast Shadows. Shadows are a Pro-only feature. Shadow properties can be adjusted on a per-light basis.

Properties

TypeThe current type of light object:
DirectionalA light placed infinitely far away. It affects everything in the scene and can not attenuate.
PointA light that shines equally in all directions from its location, affecting all objects within its Range.
SpotA light that shines everywhere within a cone (the Spot Angle), and a Range. Only objects within this region are affected by the light.
ColorThe color of the light emitted.
AttenuateDoes the light diminish with increasing distance? If disabled, objects' brightness will "pop" as they enter and exit the light's region of influence. It can be useful to turn off when you want to do some special effects. If the light is directional, this property is ignored.
IntensityBrightness of the light. Default value for Spot/Point lights is 1. Default value for Directional lights is 0.5
RangeHow far light is emitted from the center of the object.
Spot AngleIf the light is a Spot light, this determines the angle of the cone in degrees.
Shadows (Pro only)Options for shadows that will be cast by this light.
TypeHard or Soft shadows. Soft shadows are more expensive.
ResolutionDetail level of the shadows.
StrengthThe darkness of the shadows. Values are between 0 and 1.
ProjectionProjection type for Directional light shadows.
Constant BiasBias in world units used for shadows. This value is currently ignored for Point Light shadows.
Object Size BiasBias applied per shadow caster depending on it's size. Default value is 1% of caster's size. This value is currently ignored for Point Light shadows.
CookieYou can assign a texture to a light. The alpha channel of this texture is used as a mask that determines how bright the light is at different places. If the light is a Spot or a Directional light, this must be a 2D texture. If the light is a Point light, it must be a Cubemap.
Draw HaloIf checked, a spherical halo of light will be drawn with a radius equal to Range.
FlareOptional reference to the Flare that will be rendered at the light's position.
Render ModeChoose whether this light is rendered as a vertex light, pixel light, or determined automatically. For a detailed description of this tradoff, see Performance Considerations below. Options include:
AutoThe rendering method is determined at runtime depending on the brightness of nearby lights and current Quality Settings.
Force PixelThis light is always rendered at per-pixel quality. Use this for very important effects only (e.g. headlights of a player's car).
Force VertexThis light is always rendered as a vertex-lit light.
Culling MaskUse to selectively exclude groups of objects from being affected by the light; see Layers.

Details

There are three basic light types in Unity. Each type can be customized to fit your needs.

You can create a texture that contains an alpha channel and assign it to the Cookie variable of the light. The Cookie will be projected from the light. The Cookie's alpha mask modulates the light amount, creating light and dark spots on surfaces. They are a great way af adding lots of complexity or atmosphere to a scene.

All built-in shaders in Unity seamlessly work with any type of light. VertexLit shaders cannot display Cookies or Shadows, however.

In Unity Pro, all Lights can optionally cast Shadows. This is done by selecting either Hard Shadows or Soft Shadows from the Shadows property of each individual Light. For more information about shadows, please read the Shadows page.

Point Lights

Point lights shine out from a point in all directions. They are the most common lights in computer games - typically used for explosions, light bulbs, etc. They have an average cost on the graphics processor (though point light shadows are the most expensive).


Point Light

Point lights can have cookies - Cubemap texture with alpha channel. This Cubemap gets projected out in all directions. Point lights with cookies do not attenuate with distance.


Point Light with a Cookie

Spot Lights

Spot lights only shine in one direction, in a cone. They are perfect for flashlights, car headlights or lamp posts. They are the most expensive on the graphics processor.


Spot Light

Spot lights can also have cookies - a texture projected down the cone of the light. This is good for creating an effect of light shining through the window. It is very important that the texture is black at the edges, has Border Mipmaps option on and its wrapping mode is set to Clamp. For more info on this, see Textures.


Spot Light with a Cookie

Directional Lights

Directional lights are used mainly in outdoor scenes for sun & moonlight. The light affect all surfaces of objects in your scene. They are the least expensive on the graphics processor. Shadows from directional lights are explained in depth on this page.


Directional Light

When directional light has a cookie, it is projected down the center of the light's Z axis. The size of the cookie is controlled with Spot Angle property. Set the cookie texture's wrapping mode to Repeat in the Inspector.


Directional Light projecting a cloud-like cookie texture

A cookie is a great way to add some quick detail to large outdoor scenes. You can even slide the light slowly over the scene to give the impression of moving clouds.

Performance considerations

Lights can be rendered in one of two methods: vertex lighting and pixel lighting. Vertex lighting only calculates the lighting at the vertices of the game models, and interpolates the lighting over the surfaces of the models. Pixel lights are calculated at every screen pixel, and hence are much more expensive. Some older graphics cards only support vertex lighting.

While pixel lighting is slower to render, it does allow some effects that are not possible with vertex lighting. Bump-mapping, light cookies and realtime shadows are only rendered for pixel lights. Spotlight shapes and Point light highlights are much better when rendered in pixel mode as well. The three light types above would look like this when rendered in vertex light mode:


Point light in Vertex lighting mode.

Spot light in Vertex lighting mode.

Directional light in Vertex lighting mode.

Lights have a big impact on rendering speed - therefore a tradeoff has to be made betwen lighting quality and game speed. Since pixel lights are much more expensive than vertex lights, Unity will only render the brightest lights at per-pixel quality. The actual number of pixel lights can be set as in the Quality Settings.

You can explicitly control if a light should be rendered as a vertex or pixel light using the Render Mode property. By default Unity will classify the light automatically based on how much the object is affected by the light.

The actual lights that are rendered as pixel lights are determined on an object-by-object case. This means:

See here for more information about optimizing rendering performance.

Creating Cookies

For more information on creating cookies, please see the tutorial on how to create a Spot Light cookie here.

Hints