
TRay
Ray tracing in the terminal. Extending ansipixels.
Inspired by the Ray Tracing In One Weekend book.
Compared to the book:
- This version is in Go (golang)
- Code is (imo) a lot easier to read
With generics to share code between colors and vectors/points yet different types sadly go generics on [3]float64 has a huge negative performance impact. so... not anymore.
- It uses goroutines to render faster (yeah go)
- It can render to any ANSI terminal (truecolor support being better)
- While also saving the full resolution as regular PNG (instead of PPM)
- Lots of (generated, mostly) tests
- You can specify a specific seed for the scene, for reproducible results
- Exact same as C++ output in benchmark/ which was used to compare and get:
- High performance (4x improvements from initial version), almost matches the single threaded C++ (and thus beats it with multiple go routines/cpu cores)
- WIP: navigation in the world
Current demo scene

(Created using tray -save example.png -r 64 -s 8 -d 50 -seed 2 > /tmp/example.ansi on a 160x45 terminal.
It does take a while, 3 minutes on 11 core M3 pro)
Install
You can get the binary from releases
Or just run
CGO_ENABLED=0 go install fortio.org/tray@latest # to install (in ~/go/bin typically) or just
CGO_ENABLED=0 go run fortio.org/tray@latest # to run without install
or
brew install fortio/tap/tray
or even - but multicast that we need doesn't seem to work at least on docker for mac.
docker run --network host -v ~/.tray:/home/user/.tray -ti fortio/tray
Usage
Hit a key to hide the splash info. After which any key causes a re-render, 'Q' to quit.
Save the full resolution image using -save file.png.
More options (number of workers, rays per pixel, image super sampling, etc...)
tray help
flags:
-d int
Maximum ray bounce depth (default 12)
-exit
Not interactive (no raw), and exit immediately after rendering the image once (for timing purposes)
-profile-cpu string
Write CPU profile to file
-r int
Number of rays per pixel (default 64)
-s float
Image supersampling factor (default 4)
-save string
Save the rendered image to the specified PNG file
-seed uint
Seed for the random generators (0 randomizes each time)
-w int
Number of parallel workers (0 = GOMAXPROCS)
See also benchmark help for the non terminal drawing version used to check raytracer performance and output
with a fixed image size (independent of terminal size/supersampling).