Home

Awesome

pt: a golang path tracer

Build Status GoDoc

This is a CPU-only, unidirectional path tracing engine written in Go. It has lots of features and a simple API.

Examples


Features

Installation

go get -u github.com/fogleman/pt/pt

Examples

The are lots of examples to learn from! To try them, just run, e.g.

cd go/src/github.com/fogleman/pt
go run examples/gopher.go

Optional Embree Acceleration

You can optionally utilize Intel's Embree ray tracing kernels to accelerate triangle mesh intersections. First, install embree on your system: http://embree.github.io/ Then get the go-embree wrapper and checkout the embree branch of pt.

git checkout embree
go get -u github.com/fogleman/go-embree

Hello World

The following code demonstrates the basics of the API.

package main

import . "github.com/fogleman/pt/pt"

func main() {
	// create a scene
	scene := Scene{}

	// create a material
	material := DiffuseMaterial(White)

	// add the floor (a plane)
	plane := NewPlane(V(0, 0, 0), V(0, 0, 1), material)
	scene.Add(plane)

	// add the ball (a sphere)
	sphere := NewSphere(V(0, 0, 1), 1, material)
	scene.Add(sphere)

	// add a spherical light source
	light := NewSphere(V(0, 0, 5), 1, LightMaterial(White, 8))
	scene.Add(light)

	// position the camera
	camera := LookAt(V(3, 3, 3), V(0, 0, 0.5), V(0, 0, 1), 50)

	// render the scene with progressive refinement
	sampler := NewSampler(4, 4)
	renderer := NewRenderer(&scene, &camera, sampler, 960, 540)
	renderer.AdaptiveSamples = 128
	renderer.IterativeRender("out%03d.png", 1000)
}

Hello World

Adaptive Sampling

There are several sampling options that can reduce the amount of time needed to converge to an acceptable noise level. Both images below were rendered in 60 seconds. On the left, no advanced features were enabled. On the right, the features listed below were used.

Gopher

Here are some of the options that are utilized to achieve this improvement:

Combining these features results in cleaner, faster renders. The specific parameters that should be used depend greatly on the scene being rendered.

Links

Here are some resources that I have found useful.

Samples

Go

Dragon

Cornell

Lucy

SDF

Spheres

Suzanne

Molecule