Skip to content
Ray Tracing Basics
step 1/5

Reading — step 1 of 5

Read

~2 min readRay Tracing

Ray Tracing Basics

Different paradigm from rasterization:

For each pixel:
    cast ray from camera through pixel
    find closest hit
    compute color (recursive for reflections)
    return color

Each pixel = one or more rays. Each ray finds geometry.

python

Camera ray generation:

  • Camera position + viewing direction.
  • For pixel (x, y), compute ray through it in world space.
python

Pinhole camera:

  • Simple model: rays through single point.
  • No lens distortion / depth of field.
  • Standard for CGI.

Anti-aliasing:

  • Multiple rays per pixel, average colors.
  • 4x supersampling = 4 rays per pixel.
  • Stratified or Halton sequences for low-discrepancy sampling.

Bounded recursion:

  • Reflections: bounce ray, recurse.
  • Limit depth (5-10 bounces) to prevent infinite recursion.
python

Shadow rays:

  • For each light: cast ray from hit point to light.
  • If blocked: shadow.
  • If not: light contributes.
python

The 0.001 offset (epsilon) prevents self-intersection.

Performance: O(rays * triangles). Acceleration: BVH (next).

Path tracing:

  • For each ray: bounce randomly, accumulate emission.
  • Many samples per pixel (1000+).
  • Physically correct but slow.
  • Production rendering (films): minutes per frame.
  • Modern GPU: real-time path tracing with denoising (NVIDIA RTX).

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…