How to Use Light Probes in Unity3D
Light Probes in Unity are a powerful feature used to provide more accurate and realistic lighting for dynamic (moving) objects in your scene, particularly when those objects pass through areas with varying lighting conditions. They capture information about the light that bounces off static geometry in the scene, allowing dynamic objects to be lit by this “baked” indirect light.
Why Use Light Probes?
- Indirect Lighting for Dynamic Objects: While static objects can use baked Global Illumination (GI) for indirect light, dynamic objects (like a player character or a moving enemy) cannot. Light Probes store the indirect light information at specific points in space, allowing dynamic objects to sample this data as they move, creating the illusion of being lit by the environment.
- Performance: Baking indirect lighting into Light Probes is computationally intensive during development, but at runtime, sampling these probes is very efficient, leading to good performance.
- Realism: They significantly enhance the visual fidelity of dynamic objects by making them appear integrated into the scene’s lighting, rather than looking artificially lit.
How Light Probes Work
Light Probes work by interpolating lighting information. When you place Light Probes throughout your scene and “bake” the lighting, each probe captures the incoming light from all directions at its location. At runtime, a dynamic object’s renderer will look at the Light Probes nearest to it and interpolate the lighting data from these probes to determine how it should be lit by indirect light.
Step-by-Step: Implementing Light Probes
Let’s walk through the process of setting up and baking Light Probes in your Unity scene.
Prerequisites:
- Unity Editor installed.
- A new or existing Unity Project open with some static geometry (e.g., a floor, walls, some objects) and at least one dynamic object (e.g., a default Cube set to
Static
off). - Your scene should have a Light (e.g., Directional Light, Point Light) providing some illumination.
1. Prepare Your Scene for Baking
For Light Probes to work correctly, your static geometry needs to be marked as Static
for lighting.
- Select Static Objects: In the
Hierarchy
window, select all the GameObjects that are stationary and should contribute to the baked lighting (e.g., floor, walls, props). - Mark as Static: In the
Inspector
window, at the top right, check theStatic
checkbox. A dropdown will appear; make sureContribute GI
(Global Illumination) is checked.- (You would see a screenshot of the
Inspector
with theStatic
checkbox and dropdown.)
- (You would see a screenshot of the
2. Add Light Probes to Your Scene
- Create Light Probe Group: In the
Hierarchy
window, right-click an empty space. - Go to
Light > Light Probe Group
.- (You would see the context menu in the
Hierarchy
withLight Probe Group
highlighted.)
- (You would see the context menu in the
- A
Light Probe Group
GameObject will be added to your scene. It will initially show a grid of yellow spheres. These are the individual Light Probes.- (You would see a screenshot of the scene view with the yellow Light Probes grid.)
3. Position and Arrange Light Probes
Proper placement of Light Probes is critical for good results.
- Select the
Light Probe Group
: Select theLight Probe Group
in theHierarchy
. - Edit Probes: In the
Inspector
window, find theLight Probe Group
component. Click theEdit Light Probes
button.- (You would see a screenshot of the
Light Probe Group
component with the “Edit Light Probes” button highlighted.) - (When in
Edit Light Probes
mode, you’ll see gizmos for moving, rotating, and scaling the probes, similar to how you manipulate regular GameObjects.)
- (You would see a screenshot of the
- Placement Guidelines:
- Place probes where dynamic objects will be. Don’t place them inside solid objects.
- Place probes at the “corners” or “edges” of distinct lighting areas. For example, at the entrance of a tunnel, under a shadow, in a brightly lit area, and at the transition points between them.
- Use enough probes to accurately capture the light variation. More variation means more probes are needed.
- Form a 3D volume. Ensure your probes form a convex volume around the areas where dynamic objects will move. The dynamic object will interpolate between the closest probes, so you need probes surrounding the paths they will take.
- Avoid placing probes in thin lines or flat planes. They work best when forming a clear 3D volume.
- Consider heights: Place probes at different heights to capture vertical light changes (e.g., near the floor, at waist height, near the ceiling).
- Manipulate Probes:
- Use the standard Unity transform tools (
W
for Move,E
for Rotate,R
for Scale) to position individual probes or groups of probes. - You can select multiple probes by holding
Shift
orCtrl
(Windows) /Cmd
(macOS) and clicking. - Use
Shift + Click
on an existing probe to add a new probe at that location when inEdit Light Probes
mode. - Use
Ctrl + Delete
(Windows) /Cmd + Delete
(macOS) to delete selected probes. - To get a good starting point, you can click
Bake
on the Lighting window, then clickGenerate Lighting
to get a first estimate. Then, manually add/remove/move probes to refine the positions. - (You would see screenshots illustrating good and bad probe placement examples.)
- Use the standard Unity transform tools (
4. Configure Your Lighting Settings
- Open the Lighting Window: Go to
Window > Rendering > Lighting
.- (You would see a screenshot of the
Lighting
window.)
- (You would see a screenshot of the
- Generate Lighting Tab: In the
Lighting
window, go to theGenerate Lighting
tab. - Realtime vs. Baked GI:
- Ensure your scene has a
Light
component (e.g.,Directional Light
). - For the Light Probes to capture baked indirect lighting, your static lights should be set to
Baked
orMixed
Mode
in theirLight
component in theInspector
. - In the
Lighting
window, ensureBaked Global Illumination
is enabled. - (You would see screenshots of the
Light
component settings and theLighting
window settings.)
- Ensure your scene has a
5. Bake the Lighting
- Click Generate Lighting: In the
Lighting
window, at the bottom, click theGenerate Lighting
button.- (You would see a screenshot of the
Generate Lighting
button.)
- (You would see a screenshot of the
- Unity will now calculate and bake the indirect lighting information into your Light Probes (and lightmaps for static objects). This process can take some time depending on your scene’s complexity and your computer’s power.
- (You would see a progress bar indicating the baking process.)
- Once baking is complete, your Light Probes will store the captured light data. You might see their colors change in the Scene view to reflect the light they’ve absorbed.
- (You would see a screenshot of the Light Probes in the scene view after baking, showing varied colors.)
6. Ensure Dynamic Objects Use Light Probes
For your dynamic objects to benefit from Light Probes, their Renderer
component (e.g., Mesh Renderer
, Skinned Mesh Renderer
) needs to be configured correctly.
- Select Your Dynamic Object: Select the GameObject that moves (e.g., a Cube that is NOT
Static
). - Renderer Settings: In its
Inspector
window, find theMesh Renderer
(or relevant renderer) component. - Light Probes Property: Look for the
Light Probes
dropdown.- Ensure it is set to
Blend Probes
(the default). This tells the renderer to sample and blend the light from nearby probes. - (You would see a screenshot of the
Mesh Renderer
component with theLight Probes
dropdown.)
- Ensure it is set to
7. Test Your Dynamic Object’s Lighting
- Enter Play Mode: Run your game in the Unity Editor (click the
Play
button). - Move Your Object: Move your dynamic object through different lighting areas of your scene.
- Observe Lighting: Notice how the dynamic object’s lighting changes as it passes from bright to shadowed areas, or through different colored light. It should now appear much more naturally integrated into the scene’s lighting.
- (You would see a video or animated GIF demonstrating a dynamic object moving through baked indirect light, showing the effect of Light Probes.)
Important Considerations and Best Practices
- Baking Time: Baking can be time-consuming. Use the
Auto Generate
checkbox in theLighting
window sparingly, especially for large scenes, as it will re-bake every time you make a change. - Probe Density: Use more probes in areas with rapid lighting changes and fewer in uniform areas. Over-sampling (too many probes) increases bake time and memory usage without significant visual improvement.
- Visual Debugging: In the Scene view, select your
Light Probe Group
and you can visualize the probe interpolation. This helps identify areas where more probes might be needed. - Reflection Probes vs. Light Probes:
- Light Probes: Handle indirect diffuse lighting for dynamic objects.
- Reflection Probes: Handle specular reflections for both static and dynamic objects. They capture the environment’s reflections. You’ll typically use both together for comprehensive lighting.
- Scene Organization: Keep your Light Probe Groups organized, especially in large scenes. You can have multiple
Light Probe Group
GameObjects for different areas. - Probe Volume: Always ensure your probes form a convex hull around the areas where dynamic objects will move. If an object moves outside the probe volume, its lighting might become incorrect or revert to default.
By carefully placing and baking Light Probes, you can significantly enhance the visual quality and realism of your Unity scenes, making your dynamic objects feel truly part of the environment’s lighting.