In this lesson, you will learn how to configure Reflection Probes to capture real-time surroundings, ensuring your metallic and glossy materials respond accurately to a shifting environment.
While baked reflections are efficient for static scenes, they fail to capture moving objects or changing light states. By utilizing Reflection Probes set to Realtime mode, we can instruct Unity to render the environment into a cubemap dynamically, allowing your high-specularity materials—like polished chrome or wet asphalt—to reflect the world around them as it evolves.
Configuring the Probe
To implement this, add a Reflection Probe component to your scene. Set the Type to Realtime. You will notice a Refresh Mode option:
- On Awake: Updates only when the scene starts.
- Every Frame: Updates every tick, which is visually perfect but performance-intensive.
- Via Scripting: Allows you to trigger updates only when necessary (e.g., when a player moves into a specific zone), which is the industry standard for optimizing dynamic reflections.
Controlling Real-Time Updates
If you choose Via Scripting, you can trigger a refresh manually in your controller script using the RenderProbe() method. This is far more performant than "Every Frame" because you only update the reflection when the visual change is significant enough to warrant the GPU overhead:
public class DynamicReflector : MonoBehaviour
{
public ReflectionProbe probe;
void Update()
{
// Only trigger the capture when movement occurs
if (transform.hasChanged)
{
probe.RenderProbe();
transform.hasChanged = false;
}
}
}
Pro-Tip: Box Projection and Offset
Ensure you check Box Projection on your probe component. Without this, reflections will appear to "swim" or distort unnaturally as the camera moves. Box Projection uses the probe's box volume to calculate the parallax correction, forcing the reflection to align correctly with the surface geometry. Always align the Box Size closely to your physical area of interest to avoid leaking light and color information from outside the local environment.
Key Takeaway: Use Realtime Reflection Probes with the "Via Scripting" refresh mode to maintain high-fidelity surface reflections without sacrificing your project's frame rate.