In this lesson, you will learn how to manipulate camera physical properties to guide your player’s eye using cinematic Depth of Field (DoF).
The Concept of Physical Focus
In real-world cinematography, a lens cannot focus on everything simultaneously. Depth of Field is the phenomenon where only a specific distance from the camera is sharp, while objects closer or further away blur. By controlling the Focus Distance, Aperture (f-stop), and Focal Length, you can isolate a character or interactable object from a cluttered background.
- Focus Distance: Defines the exact depth where your subject sits. Everything at this distance is crisp.
- Aperture (f-stop): Controls the size of the lens opening. A smaller f-stop (e.g.,
f/1.4) creates a wide opening, resulting in a shallow DoF (heavy blur). A larger f-stop (e.g.,f/16) creates a narrow opening, keeping more of your scene in focus. - Focal Length: Simulates lens magnification. Higher values compress depth, making background blur look more dramatic and "cinematic."
Implementation via Post-Processing
In Unity, we achieve this using the Depth of Field component within a Volume profile. Instead of manually tweaking math in code, we use these settings to create a composition that forces the player to look where you want them to.
If you are controlling this dynamically (e.g., snapping focus to a target object), you can manipulate the DepthOfField override in your volume settings via script:
using UnityEngine.Rendering.Universal; // Or HighDefinition
public void SetCameraFocus(Volume volume, Transform target) {
if (volume.profile.TryGet(out DepthOfField dof)) {
// Calculate distance from camera to the target object
float distance = Vector3.Distance(Camera.main.transform.position, target.position);
dof.focusDistance.Override(distance);
}
}
Cinematic Composition
When setting up your scene, treat the Focus Distance as a storytelling tool. If you are animating a cutscene, you can use a Volume transition to shift focus from a background enemy to an object in the player's hands. Always remember that a lower f-stop requires higher artistic intent; if the blur is too aggressive, the player may lose spatial awareness, making navigation difficult. Use this to highlight, not to obscure.
Key Takeaway: Use a low f-stop value and precise focus distance to isolate your subject, effectively using lens physics to direct the player's attention within a complex 3D environment.