what is raytracing in video games?

Thirdpen

Ray Tracing Logic

How computers simulate light to create photorealistic images.


The Reverse Path of Light

In the real world, light travels from a source (like the sun), bounces off objects, and eventually hits your eye.

Simulating billions of light photons is too slow for computers. Ray Tracing solves this by working backward. We shoot "view rays" from the camera (your eye), through each pixel on the screen, into the virtual world to see what they hit.

The Camera Ray Caster

This simulation shows the "Top Down" view of a 3D scene (left) and what the camera actually renders (right).

  1. Move your mouse (or touch) to rotate the camera.
  2. Watch how rays scan the scene to determine the color of each vertical column of pixels.

Reflections and Recursion

One of the biggest strengths of ray tracing is handling reflections. In traditional graphics (rasterization), reflections are faked using pre-rendered images. In ray tracing, they are calculated physically.

When a ray hits a shiny surface, it doesn't stop. It bounces off, creating a Secondary Ray.

  1. Primary Ray: Camera \rightarrow Mirror.
  2. Secondary Ray: Mirror \rightarrow Wall.
  3. The color of the wall travels back along the path to the camera.

Interactive Reflection Lab

  • Drag the mirror to change the angle.
  • Observe how the incident ray (blue) reflects (orange) based on the surface angle.
  • The normal vector (dotted line) is perpendicular to the surface.

Shadows and Visibility

How does the computer know if a pixel is in shadow? It fires a special ray called a Shadow Ray.

When a primary ray hits a surface (the floor), the computer instantly fires a new ray from that hit point directly toward the light source.

  • If the shadow ray reaches the light clearly: Pixel is lit.
  • If the shadow ray hits an object on the way: Pixel is in shadow.

Shadow Ray Logic Demo

Move the Blocker (Grey Circle) to interrupt the connection between the floor and the light.


Global Illumination (GI)

This is the "Holy Grail" of ray tracing. In real life, light doesn't just stop when it hits a wall; it scatters. If light hits a red wall, it bounces off and tints the nearby floor slightly red. This is called Color Bleeding.

Games without Ray Tracing often look flat because they lack this indirect bounce lighting.

Color Bleed Simulation

This simulation shoots "photons" (light packets) into a box.

  1. Toggle the Wall Color to see how it affects the floor.
  2. Watch the particles: White particles hit the colored wall, become colored, then land on the white floor, tinting it.

Why is it so demanding?

Looking at these examples, you might notice a pattern: for every single pixel on your screen, the computer has to calculate:

  1. Primary Ray: Hitting the object.
  2. Shadow Ray: Checking if it's blocked from the light.
  3. Reflection Ray: Bouncing if the object is shiny.
  4. GI Rays: Bouncing randomly to calculate ambient color.

A 4K screen has over 8 million pixels. Doing these calculations 60 times per second requires massive computational power, which is why specialized hardware (like RT Cores in modern GPUs) is necessary to accelerate the math.

Sign in to ask follow ups

Sign In to continue