Skip to content
FoundationSource checked

Ray Tracing

Renders images by tracing rays from the camera into a scene.

Quick Facts

Compact metadata for implementation and discovery.

Category
Rendering
Difficulty
Advanced
Family
Ray-Based Rendering
Tier
Foundation
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
20
Code example
Not ready
Visualization
Ready
Aliases
Raytracing

Overview

Ray Tracing follows rays to find visible surfaces and can spawn more rays for shadows, reflection, and refraction.

Core Concepts

camera rayray-surface intersectionrecursive visibilitylighting samplerendered imagegeometric calculationvisibility orderingrecursive decomposition

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(p log n)

Average

O(p r log n)

Worst

O(p r n)

Space

O(n)

When to Use

  • Use it when visibility is naturally expressed as ray-surface intersection.
  • Use it for reflections, refractions, shadows, and high-quality offline rendering.
  • Use acceleration structures for nontrivial scenes.

When Not to Use

  • Avoid brute-force ray tracing without acceleration structures on large scenes.
  • Avoid deep recursive ray paths without a depth or contribution limit.
  • Avoid it when rasterization gives the needed quality within a tighter frame budget.

What It Does

  • Finds ray-surface intersections
  • Computes lighting along rays

Use Cases

  • Photorealistic rendering
  • Reflection and shadow simulation
  • Offline image generation

Inputs

  • Scene geometry
  • Materials
  • Camera
  • Lights

Outputs

  • Rendered image

Key Formulas (1)

Ray equation

point(t) = origin + t · direction
point(t) = origin + t * direction

Defines points along a ray for intersection tests.

Pseudocode

  1. 1.Create one or more rays for each pixel
  2. 2.Find the nearest surface hit for each ray
  3. 3.Shade the hit using lights and material properties
  4. 4.Trace secondary rays when needed
  5. 5.Average samples into the final pixel color

Canonical Example

Input
one sphere, one camera ray through the center pixel
Output
nearest hit point on the sphere
Explanation
The ray is intersected with the sphere, and the closest positive hit determines the visible surface.

Implementation Notes

  • Generate primary rays from camera parameters and pixel sample positions.
  • Find the closest positive intersection along each ray.
  • Use BVHs or other acceleration structures before scaling beyond tiny scenes.

Common Pitfalls

  • Testing every ray against every object instead of using an acceleration structure.
  • Choosing epsilon offsets that cause either self-intersection or light leaks.
  • Letting recursive reflection or refraction paths run without a termination rule.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Show rays leaving the camera and hitting scene objects.

Ray Tracing mechanism walkthrough step 1 of 5
Step 1 of 5: Create one or more rays for each pixel
camera-rays

Notes

Ray tracing becomes practical for complex scenes only with spatial acceleration and careful sampling.

Sources (1)

What each reference supports for this entry.

Physically Based Rendering

Book

Rendering reference covering ray tracing, visibility, materials, and sampling.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Ray tracing commonly uses BVH traversal to accelerate ray-scene intersection.

Prerequisite ofPath Tracing

Path tracing builds on ray tracing with stochastic light transport sampling.

Whitted ray tracing is a recursive ray tracing model for reflections and refractions.

Related Algorithms

Tags

GraphicsGeometryVisibilityRecursion