Skip to content

utsavll0/ray-tracer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ray Tracer

A high-performance C++ ray tracing engine that renders photorealistic 3D images using ray casting algorithms.

Features

  • Ray Tracing: Accurate lighting simulation using recursive ray tracing
  • Material System: Support for multiple material types:
    • Lambertian (diffuse) materials
    • Metal with configurable fuzz
    • Dielectric (glass/transparent) materials
  • Depth of Field: Camera depth of field effect with configurable defocus angle
  • Anti-aliasing: Multi-sample per pixel for smooth edgescna
  • Scene Generation: Procedurally generated random scenes with various objects

Building

Prerequisites

  • C++17 or later compiler
  • CMake 3.10+

Build Instructions

mkdir build
cd build
cmake ..
cmake --build .

Usage

Run the ray tracer to generate a PPM image:

./build/ray-tracer > output.ppm

The output is a PPM format image that can be viewed with any image viewer or converted to other formats.

Configuration

Edit the camera settings in main.cpp to customize the rendering:

cam.aspect_ratio = 16.0 / 9.0;      // Image aspect ratio
cam.image_width = 1200;              // Output width in pixels
cam.samples_per_pixel = 500;         // Samples per pixel (higher = less noise)
cam.max_depth = 50;                  // Maximum ray bounce depth

cam.vfov = 20;                       // Vertical field of view
cam.lookfrom = point3(13, 2, 3);    // Camera position
cam.lookat = point3(0, 0, 0);       // Look-at point
cam.vup = vec3(0, 1, 0);            // Camera up vector

cam.defocus_angle = 0.6;             // Depth of field effect
cam.focus_dist = 10.0;               // Focus distance

Architecture

Core Components

  • vec3.h: 3D vector math utilities
  • ray.h: Ray representation and operations
  • hittable.h: Base interface for scene objects
  • sphere.h: Sphere primitive implementation
  • material.h: Material definitions and scatter calculations
  • camera.h: Camera and rendering engine
  • color.h: Color representation and conversion

Performance Tips

  • Reduce samples_per_pixel for faster preview renders
  • Lower image_width for faster iteration
  • Reduce max_depth for simpler scenes
  • Increase image_width and samples_per_pixel for final high-quality renders

Output Format

The renderer outputs PPM (Portable Pixmap) format images. To convert to other formats:

# Convert PPM to PNG (requires ImageMagick)
convert output.ppm output.png

# Convert PPM to JPG
convert output.ppm output.jpg

Generated Images

Sample renders demonstrating the ray tracer's capabilities:

Low Quality (10 samples per pixel)

Low quality render Quick preview render with 10 samples per pixel - fast iteration

High Quality (500 samples per pixel)

High quality render Final quality render with 500 samples per pixel - significantly reduced noise

Inspiration

This project is inspired by Ray Tracing in a Weekend by Peter Shirley. The book provides an excellent introduction to ray tracing concepts and serves as a great guide for understanding how light rendering works. It's a fantastic resource for anyone interested in computer graphics and rendering algorithms.

License

This project is open source. Feel free to modify and use it for educational or personal purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors