Skip to content
← 02 / Projects

05 / Description

Ray Tracer in C

A ray tracer in C: move a light source and watch colours refract.

  • C
  • Computer graphics
  • Phong shading
Flat object colours only
Fig. 1 Albedo only
Diffuse term
Fig. 2 Diffuse term
Specular term
Fig. 3 Specular term
Full render with reflections and shadows
Fig. 4 Full render: Phong, reflection, shadows

Problem

Build the rendering pipeline from scratch: no graphics library, only rays, intersections and lighting maths.

Approach

Rays are cast per pixel against transformed ellipsoids and a plane. Each hit is lit with the Phong model (ambient, diffuse, specular) and extended with shadows and recursive reflection. The four figures above split the final image into its parts.

Key technical decision

Objects are unit primitives with a transform matrix and its stored inverse, so intersection runs in object space and any scaling, rotation or translation costs one matrix multiply per ray.

Result

A 512 x 512 render of two ellipsoids and a floor with shading, reflections and shadows. It is a native program, so the site shows its output rather than running it.

Build it

cd "Light Raytracer"
gcc -O2 -o RayTracer RayTracer.c utils.c svdDynamic.c -lm
./RayTracer 512 3 0 out.ppm    # size, recursion depth, antialias 0/1, output file