A lightweight ray tracing renderer written in Go, designed for simulating realistic lighting effects such as reflection, refraction, and shadows. This project demonstrates the fundamentals of ray tracing, material modeling, and rendering geometric shapes, using simple but extensible code.
The program generates a 1024x768 PPM image with spheres and discs rendered under multiple light sources. Here’s a preview of the result:
Ray Tracing Algorithm
- Rays are cast from the camera through each pixel on the canvas.
- For each ray:
- Intersection: Check which object the ray hits first.
- Lighting: Calculate diffuse and specular contributions from all light sources.
- Reflection and Refraction: Recursively trace reflected and refracted rays. Shading Model
- Diffuse Shading: Light intensity proportional to the angle between the light ray and surface normal.
- Specular Shading: Simulates shiny surfaces using the Phong reflection model.
- Reflection: Simulates light bouncing off reflective surfaces.
- Refraction: Simulates light bending through transparent materials.
- Clone the Repository:
git clone https://github.com/liang256/go-raytracer.git
cd go-raytracer
- Install Dependencies:
go mod tidy
- Run the Program:
go run main.go
- Output: The program generates an image file out.ppm in the project directory. Open the file using any PPM-compatible viewer or convert it to a more common format like PNG using tools such as ImageMagick:
convert out.ppm out.png