Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 39 ยท Scene, Camera and Renderer

PerspectiveCamera: Field of View and Frustum

Master the Three.js PerspectiveCamera: field of view, aspect ratio, near and far planes, lookAt and the viewing frustum, with a live frustum visualizer.

The camera decides what part of the scene ends up on the screen. The most used camera in Three.js is PerspectiveCamera, which imitates the way eyes and photo cameras see: things get smaller with distance, parallel lines converge, and close objects loom large. This lesson explains its four numbers and how to place it.

The constructor

JavaScript
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
  • fov is the vertical field of view in degrees. Humans perceive roughly 50 to 60 degrees as natural. Small values (20) feel like a telephoto lens: flat and zoomed in. Large values (100+) feel like a wide-angle or fisheye lens with strong distortion.
  • aspect is width divided by height of the canvas. A wrong aspect stretches the picture.
  • near and far are the distances of the clipping planes. Anything closer than near or farther than far is not drawn.

The region the camera sees is a four-sided pyramid with its tip cut off, called the view frustum.

flowchart LR
  E["Camera position"] --> N["Near plane"]
  N --> F["Far plane"]
  F --> X["Things beyond far are cut"]

Only objects between the near and the far plane, inside the pyramid, are drawn.

Visualizing the frustum

The demo shows the world from a free viewpoint (left half) while a second camera, drawn with a CameraHelper, looks at some cubes. Change fov, near and far in the code and watch the pyramid change. Cubes outside the pyramid are not visible to the camera; the small inset shows what that camera really renders.

The viewing frustum

Increase near and the nearest row of cubes vanishes from the inset. Lower far and the back rows disappear. Raise fov and the pyramid widens, so more cubes fit, each looking smaller.

The inset uses two techniques you will meet again: setViewport and setScissor restrict drawing to a rectangle of the canvas. The multiple cameras lesson goes deeper.

Positioning and aiming

A camera is an Object3D, so it has position and rotation. By default it looks down its own negative z axis, with +y up. The convenient way to aim is lookAt:

JavaScript
camera.position.set(4, 3, 6);
camera.lookAt(0, 1, 0);        // a point, or lookAt(vector3 / object.position)

lookAt rotates the camera once. If the target moves, call it every frame. Controls such as OrbitControls do this for you and overwrite manual lookAt calls, since they own the camera's orientation.

To fit an object in view, use some trigonometry. The vertical field of view and the object's height give the distance:

JavaScript
const height = 2;                           // size to fit
const dist = (height / 2) / Math.tan(THREE.MathUtils.degToRad(camera.fov / 2));
camera.position.z = dist * 1.2;             // 20% margin

Choosing near and far

Depth precision is not spread evenly: it is concentrated near the camera. A near of 0.0001 with a far of 1,000,000 wastes it all, and distant surfaces start to flicker against each other, an artifact known as z-fighting. Use the largest near and the smallest far that still contain your scene, for example 0.1 and 100 for a room, 1 and 5000 for a landscape.

Updating after changes

The camera caches its projection matrix. Whenever you change fov, aspect, near, far or zoom, call camera.updateProjectionMatrix(). Forgetting this is the most common camera bug: you edit a number and nothing happens.

You can also get the camera's frustum bounds, ask whether a point is inside it, or convert between screen and world coordinates, all covered in the transforms and interaction lessons.

Dolly zoom

The central cube keeps the same size while the background stretches and squashes. Filmmakers call this the dolly zoom: the field of view changes the perception of depth, not only the size.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In PerspectiveCamera(fov, aspect, near, far), what does fov measure?

    fov is the vertical field of view in degrees. The horizontal one follows from the aspect ratio.
  2. 2. You change camera.far in code but the picture does not change. What was probably forgotten?

    The projection matrix is cached and only rebuilt when you call updateProjectionMatrix().
  3. 3. What problem can a near value of 0.0001 combined with a far of 1,000,000 cause?

    Depth precision is concentrated near the camera. A huge range leaves little precision for distant surfaces.
  4. 4. Which way does a camera look by default?

    Cameras look along their local -z axis, with +y as up. lookAt() rotates them toward a target.

Summary

  • PerspectiveCamera(fov, aspect, near, far) defines a view frustum; only objects inside it are drawn.
  • fov is vertical, in degrees; aspect is canvas width over height.
  • Aim with lookAt, and always call updateProjectionMatrix() after changing camera parameters.
  • Keep the near/far range as tight as the scene allows to avoid z-fighting.
  • CameraHelper makes the frustum visible when debugging.

Next: Orthographic and Other Cameras