How does CGI rendering work?

Every frame of an animated film starts as millions of rays fired from a camera that does not exist. A virtual camera looks through an image plane cut into pixels. For each pixel, a ray leaves the eye and runs into the 3D scene; the first thing it hits gives the pixel its colour.

Every frame of an animated film starts as millions of rays fired from a camera that does not exist. Run a real ray tracer and path tracer in your browser, watch the noise melt as samples pile up, and work out why Toy Story needed about 800,000 machine-hours.

CGIClearOpened 4 Sept 202615 min to playFree · no sign-up

In 60 seconds

  1. One ray for every pixel

    A virtual camera looks through an image plane cut into pixels. For each pixel, a ray leaves the eye and runs into the 3D scene; the first thing it hits gives the pixel its colour. A second ray towards the lamp decides light or shadow. A full-HD frame needs over 2 million rays before any bouncing.

  2. Games rasterise, films trace rays

    Rasterising projects each triangle onto the screen and fills its pixels, with a z-buffer keeping only the nearest surface. It is fast but blind to the rest of the scene, so shadows and reflections must be faked. Ray tracing follows light itself, so they come for free, at a higher cost per frame.

  3. Light bounces, and noise falls as 1/√N

    Path tracing follows random light paths that bounce around the scene, so shadows fill in and colours bleed from wall to wall. Each pixel averages many samples; four times the samples halves the noise. Denoisers clean up what is left.

  4. Shaders decide what light does

    A BRDF says where light goes after it hits a surface: everywhere for matte, one way for a mirror, a lobe in between set by roughness. Glass refracts and reflects more at glancing angles (Fresnel). Skin, wax and jade let light wander inside: subsurface scattering.

  5. Hours per frame, years per film

    A feature film has well over 100,000 frames. Toy Story took about 800,000 machine-hours; Monsters University reportedly averaged about 29 hours a frame on some 2,000 computers. Render farms share the frames out, and every frame is also saved as passes for compositing.

  6. Real-time ray tracing is here

    Since RTX cards in 2018, GPUs have hardware for rays. At 60 fps they can afford only a few samples per pixel, so games take one noisy sample, blend frames and denoise. Game engines now also light film sets through LED walls in virtual production.

The history

From a 1968 paper that fired imaginary rays at a drawing to film studios path tracing every frame and games doing it 60 times a second.

Read the full history
  1. 1968Firing rays from the eye
  2. 1975The shiny highlight
  3. 1986One equation for all light
  4. 2006Path tracing goes to the movies
  5. 2014An Indian company joins London's DNEG
  6. 2019The LED volume

The full explanation

CGIClear, chapter by chapter

Chapter 1

One ray for every pixel

A virtual camera, a grid of pixels, and a ray fired through each one.

A computer-made picture starts with a virtual camera: a point for the eye and, just in front of it, a flat image plane cut into a grid of pixels. Your screen is the same grid, only much finer.

To colour one pixel, the computer draws a straight line, a ray, from the eye through the middle of that pixel and out into the 3D scene. It works out the first thing the ray hits: the floor, a ball, the block. That thing gives the pixel its colour. Do this for every pixel and you have a picture. This is ray casting, first described by Arthur Appel at IBM in 1968.

From the hit point, a second ray heads for the lamp. If it gets there, the spot is lit; if something is in the way, it is in shadow. Let rays bounce off the mirror ball too and you have ray tracing. A full-HD frame is 1920 × 1080 pixels, so it needs over 2 million rays before any bouncing. Where the scene's shapes come from, the modelling and rigging, is in Anim3DClear.

Try “Pixels and rays” in the interactive model →

Chapter 2

Rasterising vs ray tracing

Games throw triangles at the screen. Films follow rays of light.

There are two big ways to turn a 3D scene into pixels, and the monitor draws the same scene both ways, timed on your device.

Rasterising is how games draw. Every object is first cut into flat triangles. The three corners of each triangle are projected onto the screen, and the pixels inside are filled in. Triangles arrive in any order, so a z-buffer remembers how far away each pixel's surface is. A new triangle only paints a pixel if it is nearer. Ed Catmull described this in 1974, and Wolfgang Straßer had the same idea that year. Graphics chips (GPUs) do billions of these triangle-pixel tests a second.

But a triangle is drawn on its own, with no idea what else is in the scene. So a rasteriser gets no true shadows or reflections. Games fake them with clever tricks, like shadow maps and pre-baked reflections.

Ray tracing works the other way round: one ray per pixel, plus rays to the lamp and off mirrors. Shadows and reflections come straight from the physics. It is slower, which is why films, which can wait minutes for a frame, used it first, while a game at 60 frames a second has just 16.7 ms per frame.

To be fair, both sides here use exactly the same triangles. The ray tracer first checks a bubble around each object before testing its triangles; real renderers use a whole tree of such boxes, a BVH, to skip most triangles.

Try “Raster vs rays” in the interactive model →

Chapter 3

Light bounces, and noise

Path tracing follows random light paths. More samples, less noise.

Real light does not stop at the first surface. It bounces: off the floor, onto the walls, into the shadows. That is why a room lit by one lamp is not pitch black in the corners, and why a white wall next to a red sofa looks a little pink. Renderers call this global illumination.

A path tracer copies nature with dice. For each pixel it follows one random path: from the camera to a surface, then off in a random direction, and so on, bounce after bounce. At every stop it also checks the lamp. One path is a wild guess, so the picture is speckled with noise. Average many paths, called samples per pixel, and the guesses settle on the right answer. Jim Kajiya wrote down the maths, the rendering equation, in 1986.

The catch: noise only falls as 1/√N. Four times the samples gives half the noise, so a clean frame takes hundreds or thousands of samples. That is why films now also use denoisers, smart filters, many of them trained by machine learning, that clean up a noisy frame. Our room is a cousin of the famous Cornell box from 1984. How real lamps are placed on set is in LightingClear, and how heat radiates the same way light does is in HeatClear.

Try “Light bounces” in the interactive model →

Chapter 4

Shaders: what a surface does with light

Matte, glossy, mirror, glass and skin, all from a few rules.

When a ray hits a surface, the renderer asks the shader: what happens to the light now? The answer is a rule called a BRDF, which says how much light arriving from one direction leaves in each other direction. The board draws it as a lobe.

A matte surface (the Lambert rule) scatters light evenly everywhere. A mirror sends it one way only. Most things are in between: the roughness slider widens a shiny lobe from a sharp mirror to a soft sheen.

Glass splits light. Some bounces off, and the rest goes in and refracts, bending by an amount set by its index of refraction; SnellClear shows the bending. How much reflects follows the Fresnel equations: straight on, glass reflects only about 4%, but at a glancing angle nearly all of it. That is why a lake is a mirror near the horizon and clear at your feet.

Subsurface scattering is for skin, wax, milk and jade: light slips inside, bounces around, and leaks out nearby, giving a soft glow. Films use it for every face. Lighting a real set is in LightingClear.

Try “Materials” in the interactive model →

Chapter 5

The render farm

Hours per frame × frames = years of computer time. So share it out.

A film runs at 24 frames a second, so a 90-minute feature is 129,600 frames. If each one takes hours to render, one computer would need centuries. So studios build a render farm: racks of computers, each rendering different frames at the same time.

Toy Story (1995), the first fully computer-animated feature, had 114,240 frames and took about 800,000 machine-hours, on a farm usually given as 117 Sun computers. For Monsters University (2013), Pixar reportedly averaged about 29 hours per frame on about 2,000 computers with 24,000 cores. Frames got faster, but films asked for ever richer light, so render times stayed long. Today studios also rent machines in the cloud when a deadline looms.

A renderer does not only save the finished picture. It also writes passes (also called AOVs): the diffuse light, the shiny reflections, the shadows, the depth and more, each as its own image. Artists can then brighten a reflection or tint a shadow without rendering again. Putting passes and live footage together is compositing, the subject of VFXClear.

Try “Render farm” in the interactive model →

Chapter 6

Ray tracing in real time

One noisy sample a frame, then clever cleaning. The gap is closing.

For decades, ray tracing was for films and rasterising was for games. That changed in 2018, when Nvidia launched RTX graphics cards with special RT cores that test rays against triangles in hardware. Nvidia claimed about 10 billion rays a second, roughly ten times its previous card.

Ten billion sounds endless, but a 1080p screen at 60 frames a second has 124 million pixels a second to fill. With a few rays per light path, that leaves only a handful of samples per pixel, far from the hundreds a film uses. So games take one noisy sample per pixel, blend it with the last few frames (temporal accumulation) and run a denoiser, often a neural network, to clean it up. Try it on the monitor: this page is doing it for real, just much slower.

Films borrow the other way too. Game engines now drive virtual production: giant LED walls show a live, engine-rendered world behind the actors, as on The Mandalorian (2019). That is in VirtualProdClear. Offline renders are still richer, but the gap between film and game pictures is narrowing every year.

Try “Real time now” in the interactive model →

Test yourself

Frequently asked

In ray casting, what decides the colour of a pixel?

The first thing the ray through that pixel hits. The ray leaves the eye, passes through the pixel and stops at the first surface. That surface gives the pixel its colour.

How many primary rays does a 1920 × 1080 frame need, with one ray per pixel?

About 2 million. 1920 × 1080 = 2,073,600 pixels, so just over 2 million rays, before any shadow or bounce rays.

What is a shadow ray for?

To check whether anything blocks the light from a point. From each hit point a ray heads to the lamp. If it hits something on the way, that point is in shadow.

What does the z-buffer store for each pixel?

The depth of the nearest surface drawn there so far. A new triangle may only paint a pixel if it is nearer than the depth stored there. That is how the rasteriser gets the front-to-back order right.

Why can a simple rasteriser not draw a true reflection in a mirror ball?

Each triangle is drawn on its own, with no idea what else is in the scene. Rasterising projects each triangle straight to the screen. To see a reflection you must follow light from the ball to other objects, which is what ray tracing does.

A game running at 60 frames per second has how long to draw each frame?

About 16.7 milliseconds. 1 ÷ 60 = 0.0167 s, or 16.7 ms, for everything: the game logic, the physics and the picture.

You render a frame with 16 samples per pixel. How many samples do you need for half the noise?

64. Noise falls as 1/√N, so halving it needs four times the samples: 16 × 4 = 64.

Why does the white box look a little orange on one side?

Light bounces off the terracotta wall onto it: colour bleeding. Light that hits the terracotta wall comes off tinted, and some of it lands on the box. You only see it when the renderer follows bounces.

With 0 bounces (direct light only), what do the shadows look like?

Completely black, because no bounced light fills them. Without bounced light, anything the lamp cannot see directly gets no light at all.

What does a BRDF describe?

How much light from one direction leaves in each other direction. A BRDF is the surface’s rule for scattering light. A matte one spreads light everywhere, a mirror sends it one way.

Straight on, glass reflects about 4% of light. At a very glancing angle it reflects…

Nearly all of it. That is the Fresnel effect: reflectance climbs towards 100% as the angle approaches 90°. Look across a lake at the horizon to see it.

Why do renderers need subsurface scattering for faces?

Light enters skin, scatters inside and comes out nearby, giving a soft glow. Without it, skin looks like painted plastic. With it, light bleeds through thin parts like ears and softens shadows.

A 100-minute film at 24 fps has how many frames?

144,000. 100 minutes × 60 seconds × 24 frames = 144,000 frames.

10,000 frames take 10 hours each. How long on a farm of 1,000 machines, ideally?

About 4 days. 10,000 × 10 = 100,000 machine-hours. Shared by 1,000 machines that is 100 hours, a little over 4 days.

Why do renderers save passes (AOVs) like shadows and reflections separately?

So artists can adjust each part later in compositing without rendering again. Re-rendering a frame can take hours. Tweaking a shadow pass in compositing takes seconds.

What did Nvidia’s RTX cards (2018) add to make real-time ray tracing possible?

RT cores: hardware built to test rays against triangles. RT cores do the ray-triangle tests in dedicated hardware. Nvidia claimed about 10 billion rays a second.

Why do real-time path-traced games use denoisers?

They can only afford about one sample per pixel, which is very noisy. At 60 frames a second there is time for only a few rays per pixel. A denoiser turns that noisy estimate into a clean picture.

Blending new frames with old ones reduces noise but causes…

Ghost trails behind moving objects. Old frames still show where the object was, so it smears. Real engines use motion vectors to follow the movement and reduce this.

Words worth knowing

Ray
A straight line fired from the camera through a pixel into the scene, or from a surface towards a light.
Rasterising
Drawing by projecting triangles onto the screen and filling their pixels, the way games do.
Z-buffer
A depth value per pixel that keeps only the nearest surface when triangles overlap.
Path tracing
Averaging many random light paths per pixel to capture bounced light.
Samples per pixel
How many random paths are averaged for each pixel. Noise falls as 1/√N.
Global illumination
Light that reaches a surface after bouncing off other surfaces.
BRDF
A surface's rule for how light arriving from one direction leaves in each other direction.
Fresnel effect
Surfaces reflect more light at glancing angles: about 4% straight on for glass, nearly all at grazing angles.
Render farm
Many computers rendering different frames of a film at the same time.

Fork it. Teach with it.

This box is plain HTML, CSS and JavaScript, with no build step and no accounts. Run it yourself and it sends nothing anywhere. The code is MIT. The words, images and videos are CC BY 4.0, so you can reuse them anywhere if you credit “Glassbox, glassbox.how/e/cgiclear”.

git clone https://github.com/bdeeps/cgiclear.git

Built with three.js (MIT), Geist, Instrument Serif (SIL OFL 1.1).

←→ previous / next box · / search

Would you like to see the full page, with the interactive model?