Skip to content

Repository files navigation

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

About

A deterministic pure Ruby path tracer for learning geometry, materials, and rendering backends.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages