A fun little 3D raytracer written in Go that turns math into magic! Watch as simple geometric primitives become beautiful, photorealistic renders with reflections, refractions, and depth of field effects.
This raytracer simulates how light bounces around a 3D scene to create stunning images. It supports:
- โจ Multiple Materials: Matte surfaces, shiny metals, and crystal-clear glass
- ๐ธ Depth of Field: Realistic camera blur effects
- ๐ฎ Glass Refraction: Light bending through transparent objects
- โก Parallel Rendering: Multi-core processing for faster renders
- ๐ฏ Clean Architecture: Easy to understand and extend
go build -o raytracer cmd/main.go
./raytracer -o output.png
go test ./...
The codebase is organized into clean, modular packages:
cmd/main.go # CLI entry point with Cobra
internal/
โโโ render.go # Main rendering pipeline
โโโ scene.go # Scene setup and configuration
โโโ camera.go # Camera with depth of field
โโโ geometry/
โ โโโ vector.go # 3D vector math
โโโ ray.go # Ray definitions
โโโ sphere.go # Sphere primitives
โโโ materials/
โโโ diffuse.go # Matte surfaces
โโโ metal.go # Shiny reflective surfaces
โโโ dielectric.go # Glass-like refraction
The built-in scene features:
- A red matte sphere (left) - classic Lambertian diffuse material
- A golden metal sphere (right) - with a touch of fuzziness for realism
- A glass sphere (center) - with realistic refraction and a neat hollow effect
- A large ground plane - to catch all those beautiful shadows
- Go: Fast, concurrent, and fun to write
- Cobra: Elegant CLI interface
- Parallel Processing: One goroutine per pixel row for speedy renders
- Pure Go: No external rendering dependencies, just math and creativity
Sometimes you want to understand how light works. Sometimes you want to make pretty pictures. Sometimes you just want to write some Go code that does something visually cool. This project scratches all those itches!
The raytracer uses Go's excellent concurrency features to render multiple pixel rows in parallel. On a modern multi-core machine, you'll see all your CPU cores happily crunching through rays and intersections.
- More primitive types (planes, triangles, meshes)
- Texture mapping
- Area lights and soft shadows
- More advanced materials (subsurface scattering, anyone?)
- Scene file format for custom scenes
- Progressive rendering with live preview
Happy ray tracing! ๐จ