Skip to content

Working through the exercises in "The Ray Tracer Challenge" by Jamis Buck.

License

Notifications You must be signed in to change notification settings

hockeybuggy/ray_tracer

Repository files navigation

Ray Tracer

Build and Test Status Check Formatting Status

This repository is just me working through the exercises in "The Ray Tracer Challenge" by Jamis Buck.

Quite a bit of it is just me trying to get better at Rust.

My first sphere

Getting started

Start off by cloning the repo. You'll also need a version of Rust and Cargo (consider using rustup to install this).

Running tests

To run the unit tests and the end to end tests.

cargo test

If one of the end to end tests produces a different result from the reference image in the tests/fixtures directory the result will be written into the root of the project directory. The mechanism can be use for rendering higher resolution version of the scenes in the tests by changing the SCALE constant at the top of the test then running the test.

Gallery

These are some of the scenes the ray tracer can render. The size of these images are small because these images are used as fixtures that tests use to compare to the results they generate and smaller images are faster to render.

The basics

Name

Image

Simple Circle A black and white sphere with a checkered pattern
Simple Sphere A pink sphere on a black background. The sphere is shiny and fades to dark.
Translated Sphere A pink sphere with a translated pattern

Patterns

Name

Image

Checkered Sphere A black and white sphere with a checkered pattern
Gradient Sphere A black and white sphere with a gradient pattern
Ring Sphere A black and white sphere with a ring pattern
Stripe Sphere A black and white sphere with a stripe pattern

Worlds

Name

Image

World floor A scene of three spheres on a beige plane. The spheres are various sizes and colours.
Simple World A scene of three spheres in a beige corner of what could be a room. The spheres are various sizes and colours.
World with non reflective checkered floor A world with green sphere sitting on a matte checkered floor.
World with reflective checkered floor A world with green sphere sitting on a reflective checkered floor.
World with reflective floor A world with three spheres of different colours sitting on a reflective floor.
World with reflective floor and spheres A world with three reflective spheres of different colours sitting on a reflective floor.
World glass sphere A world with a glass spheres sitting on a patterned floor.

Running benchmarks

This project contains benchmarks which measure the performance and allow you to compare how quickly the ray tracer is able to render scenes.

cargo bench

This will output something like:

render simple world     time:   [48.247 ms 48.335 ms 48.427 ms]
                        change: [-1.7688% -1.3561% -0.9619%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

This will compare a bench mark to the previous results. This allows you to make a change that you expect to improve performance and know if it worked on not.

Possible improvements

  • Add multiple light sources (note for this on 138 of the book).
  • Builder interface for shapes.
  • Update setting of transformation matrices
  • Add a file input method for world description
  • Create animated gifs

About

Working through the exercises in "The Ray Tracer Challenge" by Jamis Buck.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published