Skip to content

Repository files navigation

Path-Tracer

A concurrent, CPU-based Monte Carlo path tracer in Go — glass, metal, emissive area lights and OBJ meshes, accelerated by an SAH k-d tree.

A translucent Utah teapot on a diffuse floor lit by area lights with soft shadows, rendered by the path tracer

Path-Tracer renders physically-based images by tracing many light paths per pixel through a scene of spheres and triangle meshes. It handles refractive glass, glossy metal and emissive lights, samples area lights for soft shadows, and adapts its sample count to per-pixel variance. A small Windows GUI exposes samples-per-pixel, shadow-ray and bounce-depth controls and previews the render. It was written as a project to learn Go.

Features

  • Unidirectional Monte Carlo path tracing — rays bounce recursively and stochastically pick specular, diffuse or refractive scattering, with gamma-correct output.
  • Physically-based materials — Lambertian diffuse, glossy metal, transparent dielectric (Snell refraction with total internal reflection) and emissive lights, with tunable gloss, reflectivity and tint.
  • Area lights & soft shadows — direct lighting is estimated by firing shadow rays at random points on emissive spheres and triangles (next-event estimation).
  • OBJ + MTL mesh loading — triangle meshes via Möller–Trumbore intersection with per-vertex normals; the Stanford bunny, Utah teapot and a barrel model are included.
  • SAH k-d tree acceleration — surface-area-heuristic split selection over an AABB hierarchy keeps ray/scene queries fast.
  • Concurrent & adaptive — one goroutine per CPU core, online (Welford) variance driving adaptive sampling, and a thin-lens camera for depth of field.

Run it

Targets Windows — the GUI uses the Win32 lxn/walk toolkit — and the legacy GOPATH Go toolchain (2016-era, relative imports, no go.mod):

set GO111MODULE=off
go get github.com/lxn/walk
go build -o pathtracer.exe .
pathtracer.exe

Set samples/pixel, shadow rays and bounce depth in the Tools tab, click Render, and the image is displayed and written to img.png. The scene — camera, models and materials — is defined in setUpScene() in Integrator.go.

How it works

Each pixel fires rays through a thin-lens camera; every ray is traced recursively, scattering off surfaces by their material until it reaches a light or exceeds the maximum bounce depth. At each diffuse hit the integrator sums direct light (shadow rays sampled toward emissive objects) with indirect light (the recursive bounce), while a surface-area-heuristic k-d tree makes intersecting meshes like the teapot and bunny cheap enough to trace. Per-pixel variance is tracked online, so extra samples are spent only where the image is still noisy (the author's reference render used 2000 samples/pixel plus 128 adaptive samples, ~57 minutes).

Built to learn Go, it implements standard path-tracing techniques in the spirit of Peter Shirley's Ray Tracing books, and its OBJ/MTL loader follows the approach of Michael Fogleman's pt.

Tech: Go, github.com/lxn/walk (Win32 GUI).

About

Concurrent Monte Carlo path tracer in Go — glass, metal, area lights, OBJ meshes, SAH k-d tree

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages