Project

caustics

0.0
The project is in a healthy, maintained state
A deterministic pure Ruby ray tracer used as an rbgfx teaching example.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 0.1.0, < 1
 Project Readme

Caustics

A deterministic pure Ruby path tracer and teaching example.

Gem Version Downloads Ruby Version License

Features · Installation · Quick Start · Engines


Caustics is a small ray tracer for experimenting with cameras, materials, textures, acceleration, and renderer backends. The Ruby engine is the reference implementation; optional RLSL and Metal engines cover a deliberately smaller shader subset.

Features

  • Rays, spheres, planes, triangles, quads, and a BVH accelerator.
  • Lambertian, metal, dielectric, emission, checker, image, and Perlin textures.
  • Depth of field, deterministic per-pixel sampling, and an accumulator.
  • Process-parallel rendering where fork is available.
  • Interactive preview with progressive sampling.
  • Ruby, rlsl C, and Metal command-line engines.

Installation

Add Caustics to your Gemfile:

gem "caustics"

Then run:

bundle install

Or install the released gem:

gem install caustics

Requirements

  • Ruby 3.1 or newer.
  • The Metal engine requires macOS with a Metal-capable device.

Quick Start

Render the included scene:

caustics render scenes/weekend.rb --size 400x225 --spp 16 --workers 4 -o out.png
caustics render scenes/weekend.rb --size 400x225 --spp 16 --progress-gif -o progress.gif
caustics preview scenes/weekend.rb --size 400x225 --spp 16 -o preview.png

--progress-gif writes a cumulative frame after every sample. Install the optional Flipbook gem to use it.

Use the Ruby API directly:

require "caustics"

scene = Caustics::Scene.build do
  sphere center: [0, 0, 0], radius: 0.5,
         material: lambertian([0.8, 0.2, 0.2])
end

Caustics.render(scene, width: 320, height: 180, spp: 16, workers: 4).write("out.png")

Engines

caustics bench scenes/shader.rb --size 64x36 --spp 2 --engine ruby,rlsl_c
caustics render scenes/shader.rb --engine rlsl_c --size 400x225 --spp 2 --max-depth 2 -o out.png
caustics codegen scenes/shader.rb

The :rlsl_c and :metal engines currently support constant-colored Lambertian spheres with deterministic sampling and bounce limits. The Metal engine requires a Metal-capable macOS host.

Development

bundle install
bundle exec rake verify

Contributing

Bug reports and pull requests are welcome at rbgfx/caustics.

License

MIT