Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 39 ยท Scene, Camera and Renderer

Orthographic, Multiple and Special Cameras

Use the Three.js OrthographicCamera for 2D and isometric views, render several viewports from different cameras, and meet CubeCamera, ArrayCamera and StereoCamera.

A perspective camera makes distant things smaller. Sometimes you do not want that. A strategy game map, a CAD drawing, a 2D game with layered sprites and a UI overlay all work better when size does not depend on distance. For those, Three.js has the OrthographicCamera. This lesson also shows how to draw several views in one canvas and introduces the special cameras.

OrthographicCamera

JavaScript
const camera = new THREE.OrthographicCamera(left, right, top, bottom, near, far);

Instead of a field of view, you give the box of space the camera sees: its left, right, top and bottom edges (in world units) plus near and far. There is no perspective: parallel lines stay parallel, and an object has the same on-screen size at any distance.

The box must keep the same aspect ratio as the canvas, or the picture stretches. A standard recipe chooses a viewSize (the height in world units) and derives the width from the aspect:

JavaScript
const viewSize = 10;
function resizeCamera(aspect) {
  camera.left = (-viewSize * aspect) / 2;
  camera.right = (viewSize * aspect) / 2;
  camera.top = viewSize / 2;
  camera.bottom = -viewSize / 2;
  camera.updateProjectionMatrix();
}

camera.zoom scales the view without changing the box: camera.zoom = 2 zooms in by two. Call updateProjectionMatrix() afterwards.

Perspective versus orthographic

The same scene through both cameras:

Perspective and orthographic side by side

On the left, the rows shrink toward the horizon. On the right, every cube is the same size and the rows line up.

An isometric view

An isometric look combines an orthographic camera with a diagonal position. Place the camera at equal x, y and z offsets and aim it at the middle:

JavaScript
camera.position.set(10, 10, 10);
camera.lookAt(0, 0, 0);

This is the classic look of builder and strategy games. Because there is no perspective, an object keeps its size however far it is, so you must rely on shading and shadows to give depth.

Several viewports in one canvas

You can draw more than one picture per frame by restricting where the renderer draws. setViewport(x, y, w, h) sets the rectangle for rendering, and setScissor plus setScissorTest(true) ensures clearing only affects that rectangle. Three.js measures y from the bottom of the canvas.

The pattern is:

JavaScript
renderer.setScissorTest(true);
for (const view of views) {
  renderer.setViewport(view.x, view.y, view.w, view.h);
  renderer.setScissor(view.x, view.y, view.w, view.h);
  renderer.render(scene, view.camera);
}

This is how 3D editors show top, front, side and perspective views together. Give each camera the right aspect for its rectangle.

Special cameras

Camera What it does
ArrayCamera Holds an array of sub cameras, each with a viewport; one render call draws them all. Used for multi-view and some VR displays.
CubeCamera Renders the scene six times, once per cube face, into a WebGLCubeRenderTarget. Use it to get live reflections on a shiny object or to make a mini environment map.
StereoCamera Produces left and right eye cameras for side-by-side stereoscopic output.
PerspectiveCamera / OrthographicCamera The two everyday cameras.

CubeCamera for reflections

A mirror ball needs to see its surroundings. Put a CubeCamera at the ball's position, hide the ball, update the camera, show the ball again, and assign the render target's texture as the ball's envMap. The demo below does that once per frame for a chrome sphere in a colorful room.

Live reflections with CubeCamera

Rendering the scene six extra times per frame is expensive, so real projects lower the resolution, update only every few frames, or bake a static environment instead.

Switching an existing scene between perspective and orthographic is easy: keep both cameras, render with the one you want, and keep their positions in sync. Many 3D editors offer exactly this toggle.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main visual difference of an OrthographicCamera?

    Without perspective, size does not depend on distance and parallel lines stay parallel.
  2. 2. An orthographic camera is defined by:

    It describes a box of world space. Keep the box's aspect equal to the canvas aspect.
  3. 3. Which calls let you draw a second view into part of the canvas?

    They restrict drawing and clearing to a rectangle. Remember y is measured from the bottom.
  4. 4. What is a CubeCamera typically used for?

    It renders the scene in six directions into a cube render target which can be used as an environment map.

Summary

  • OrthographicCamera removes perspective; define it with a box of space and keep its aspect equal to the canvas.
  • Isometric views use an orthographic camera at equal x, y, z offsets.
  • Several viewports are drawn with setViewport, setScissor and one render per view.
  • CubeCamera makes live reflections; ArrayCamera and StereoCamera serve multi-view and stereo output.

Next: WebGLRenderer in Depth