Skip to content

SwiftPush/raytracer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

39 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒŸ Raytracer

example render

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.

๐ŸŽจ What Does It Do?

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

๐Ÿš€ Quick Start

Build It

go build -o raytracer cmd/main.go

Run It

./raytracer -o output.png

๐Ÿ›  Development

Run Tests

go test ./...

๐Ÿ— Architecture

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 Default Scene

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

๐Ÿ”ง Tech Stack

  • 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

๐ŸŽฏ Why This Exists

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!

๐Ÿ“ˆ Performance

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.

๐Ÿš€ Future Ideas

  • 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! ๐ŸŽจ

About

๐ŸŒŸ A fun little 3D raytracer written in Go that turns math into magic!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages