Skip to content

jackpal/smallpt-swift

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

Small Path Tracer in Swift

This is a straightforward translation of http://www.kevinbeason.com/smallpt/ to Swift.

Example Image

An example output image

Setup

  • Install Xcode 6.1
  • Install a PPM image viewing program such as Toy Viewer

Build and run

xcrun swiftc -O -sdk `xcrun --show-sdk-path --sdk macosx` smallpt.swift
./smallpt
open image.ppm

You can also run the swift file directly. And in either case you can supply the number of samples per pixel. (Default = 4 samples per pixel.):

./smallpt.swift 512 && open image.ppm

Performance

On a MacBook Pro (Retina, 15-inch, Early 2013):

Language time (seconds)
C++ single threaded 5.6 s
Swift single threaded 13.8 s (of which 5.6 s is rendering, 8 s is file output)
Swift GCD 9.8 s (of which 1 s is rendering, 8 s is file output)

Discussion

  • Swift file output seems to be very slow compared to C.
    • partly because it is unbuffered
    • partly because it is converting from Unicode to UTF8

About

Smallpt: Global Illumination in Swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published