What this is about
An AI image model guesses a picture from patterns it learned. A ray tracer does something different. It builds the picture from rules of light. It follows rays of light through a scene, like a very patient camera.
This article explains the idea in plain words. It uses our own renders to show why the results look real and why they cost so much time.
Why it matters
Films, product pictures and many game scenes are made this way. It is one of the clearest examples of a picture made by calculation, not by guesswork. If you know the idea you can see how it differs from How AI makes a picture from words, and you can judge what each is good for.
How it works
Light goes from a lamp, bounces around a room and enters your eye. Doing that forwards would waste almost every ray, because most never reach the eye. So the ray tracer runs it backwards.
- Pick a pixel. For each dot of the picture, send a ray from the camera through that dot into the scene.
- Find what it hits. The ray flies until it touches something: a wall, a cup, a table.
- Ask where the light came from. At that spot, ask: is there a lamp in view? Is it in shadow? Send new rays toward the lights, and bounce rays off the surface.
- Add it up. Color the pixel by the light that arrived, taking the color of the surface into account.
A mirror sends the ray one way. A rough wall scatters it many ways. Glass bends it. A path tracer, which is the most careful kind, sends many random paths for each pixel and averages them. That is why shadows are soft, color spills from a red wall onto a white one, and glass looks like glass.
Why it takes so long
The cost is roughly the number of pixels, times the paths per pixel, times the work to find what each ray hits.
- A 2048 by 2048 picture has over four million pixels.
- A good picture may need thousands of random paths per pixel. The setting is called samples per pixel, or spp.
- Each ray has to find what it hits in a scene with millions of triangles. A tree of boxes, a bounding volume hierarchy (BVH), helps by letting a ray skip most of the scene.
With too few paths the picture is grainy. That grain is noise: some pixels got lucky paths and some did not. More samples average it out, and a denoiser, a small program that cleans noise, can help.
What we measured
We run Gonzales, a path tracer that renders Disney's Moana scene in Mojo. It is Andreas Wendleder's project, under GPL-3, and we use a fork of it and claim no rights to it. You can look at our fork at github.com/amarbarosys/Gonzales.
On our RX 7900 XTX:
- The classic Cornell box test scene, 512 pixels and 64 samples per pixel, took 0.75 seconds on the GPU and 6.6 seconds on the CPU. The mean error between the two images was 0.0017, which is noise.
- A high quality render, with the denoiser, 2048 pixels, 4096 samples, a color view transform and 16-bit output, took 273 seconds. Grain, in our own measure, fell from 1.79 to 0.15.
So the same scene is under a second or over four minutes, depending on how much quality you ask for.
One more thing we learned: on the Cornell scene, a blur we saw was in the scene file's own pixel filter, not a fault in the renderer. When a render looks wrong, check the scene before you blame the program.
A cost that was the right cost
In one of our game-scene renders, a fix made the picture heavier, and that was correct. A frame drawn without the hospital's interior showed sky through the window. The fixed render took 12.48 seconds against 8.42, and used about 1.2 GB against about 980 MB. The cheap one was cheap because it was wrong. See What the hospital sky cost. This was a replay render in a game, not a ray tracer, but the lesson is the same: check the frame before the cost.
Can Mojo reach the ray-tracing hardware?
Some graphics cards have a special instruction for the BVH step. We found that Mojo, the language we use, has no ray-tracing interface, but a 20-line probe makes it emit that instruction for our card. We have only compiled it. We have never run it, and its arguments are garbage. A compile shows that the instruction is reachable, not that it works. The full account is in Mojo can reach ray-tracing hardware it does not expose.
Words you may meet
- Ray: a line of light followed through the scene.
- Path tracing: ray tracing with random bounces, averaged.
- Samples per pixel (spp): how many paths per dot.
- Noise or grain: the speckle from too few samples.
- BVH: a tree of boxes that helps rays find what they hit.
- Denoiser: a program that cleans noise.
Try it
- Look at the shadow of a cup on a table by a window. It is soft, with a darker core. That is what many random rays give you.
- Browse the renderer at github.com/amarbarosys/Gonzales.
- For a place where generated pictures end up in a 3D space, visit aiazic.com.
What we do not claim
The Cornell numbers are from one card and one scene. Wall times on a shared GPU swing a lot, and in our tests arms under 5 seconds swung 7 to 9 percent.

Reacties
Nog geen reacties.
Inloggen om te reageren.