Skip to content
A simple Raytracer, written in Swift
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
SwiftRay
doc
.gitignore
LICENSE
README.md

README.md

SwiftRay

A simplistic Path tracer written in Swift.

Sample image produced by SwiftRay

What is SwiftRay

SwiftRay is a Path Tracer (a kind of Raytracer) written in Swift and loosely based on the e-book Ray Tracing in One Weekend by Peter Shirley.

There are three books in the series, but SwiftRay is only based on the first two. The original source code is written in C++. Should you wish to know how the path tracer works, buy the book, since it's cheap, and provides nice explanations.

Features

  • Antialiasing (by multisampling every pixel)
  • Several materials: Lambertian (matte colour), Metal (reflective) and Dielectric (refractive)
  • Depth-of-field blur
  • Motion blur
  • Multi-threaded, to exploit multiple cores
  • A Bounding Volume Hierarchy algorithm speeds-up calculations

Limitations

  • There are only two type of object: Spheres and rectangles oriented on the axes.
  • The algorithm is interesting but very slow: Path tracing is slow by principle.

Supported plateforms

It currently only runs on a Mac.

It should be possible to run it on a iOS device, but a little adaptation is needed because it runs on the command line.

Running it on Linux would be more work, since it relies on Core Graphics to save the image to a PNG file. (It also imports Darwin for mathematical functions, but that can be replaced with libc on Linux).

What programmers might find interesting

Begin with main.swift. It contains enough comments to understand the structure of the app.

Take a look at Bitmap.swift which does low-level memory access to the bitmap.

Vector.swift also contains overloaded operators. Thanks to Swift, the implementation is simple and elegant.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.