University · Ages 18+First-year university · Physics olympiadsCore

 

Ray Tracing

A ray tracer makes an image by following rays of light backwards: from the camera, through each pixel, into the scene. At the first surface a ray hits, the laws of geometric optics decide the colour — how squarely the surface faces the light, how far away the light is, whether something casts a shadow, and what the surface reflects. Click any pixel to follow its ray and see every equation with its live numbers.

Key formulas

  • P⃗(t)=O⃗+t D^\vec{P}(t) = \vec{O} + t\,\hat{D}

    Parametric ray

    P⃗(t)\vec{P}(t)
    Point on the ray
    O⃗\vec{O}
    Ray origin (the camera)
    D^\hat{D}
    Direction (unit vector)
    tt
    Distance along the raym
    Open the formula card
  • Δ=b2−4ac,b=2 D^⋅(O⃗−C⃗),c=∣O⃗−C⃗∣2−r2\Delta = b^2 - 4ac,\quad b = 2\,\hat{D}\cdot(\vec{O}-\vec{C}),\quad c = |\vec{O}-\vec{C}|^2 - r^2

    Ray–sphere intersection

    Δ\Delta
    Discriminant
    C⃗\vec{C}
    Sphere centre
    rr
    Sphere radiusm
    aa
    \hat{D}\cdot\hat{D}, equal to 1 for a unit direction
    Open the formula card
  • E=I0d2E = \dfrac{I_0}{d^2}

    Inverse-square law of light

    EE
    Irradiance on the surfaceW/m²
    I0I_0
    Source intensityW/sr
    dd
    Distance from the sourcem
    Open the formula card
  • Id=kd E max⁡(0, N^⋅L^)I_d = k_d\,E\,\max(0,\ \hat{N}\cdot\hat{L})

    Lambert's cosine law

    IdI_d
    Diffuse brightnessW/m²
    kdk_d
    Diffuse reflectance (albedo)
    EE
    Incoming irradianceW/m²
    θ\theta
    Angle between normal \hat{N} and light \hat{L}°
    Open the formula card
  • D^r=D^−2(D^⋅N^) N^\hat{D}_r = \hat{D} - 2(\hat{D}\cdot\hat{N})\,\hat{N}

    Law of reflection

    D^\hat{D}
    Incoming direction (unit vector)
    N^\hat{N}
    Surface normal (unit vector)
    D^r\hat{D}_r
    Reflected direction
    Open the formula card

What you can change

  • Camera, sphere and light positions (drag them in the diagram)
  • Field of view
  • Sphere radius
  • Light intensity I₀
  • Ambient, diffuse and specular coefficients
  • Shininess n and reflectivity ρ

Key concepts

  • Rays as the model of geometric optics
  • Ray–sphere intersection and the discriminant
  • Lambert's cosine law
  • The inverse-square law for a point source
  • Shadows as blocked straight-line paths
  • The law of reflection and specular highlights

Community presets

Setups other learners found interesting in Ray Tracing. Try one, then tweak it.