Back to Portfolio

rachit-pt

A physically-based software path tracer written from scratch in Rust.

Rust Path Tracing Computer Graphics

A software path tracer written in Rust from scratch. rachit-pt generates images of 3D scenes by simulating the physical behavior of light, implementing a recursive ray tracing algorithm with global illumination.

Current Output Example render with HDR skybox and depth of field. Render time: 01:31:56

Features

  • Global Illumination: Physically-based light transport using a recursive path tracing algorithm.
  • Material System:
    • Lambertian (Diffuse): Realistic matte surfaces using random hemisphere scatter.
    • Metal: Reflective surfaces with adjustable roughness/fuzziness.
    • Dielectric (Glass): Refraction and reflection utilizing Snell’s Law and the Schlick approximation for view-dependent Fresnel effects.
  • Camera Optics: A physically simulated thin-lens camera model supporting customizable vertical Field of View (FOV) and Depth of Field (defocus blur).
  • Environment Lighting:
    • Procedural gradient sky.
    • Image-based lighting via HDR environment maps (HDR skybox support).
  • Gamma Correction: Accurate color space conversion to sRGB.
  • Anti-Aliasing: High-quality multi-sampled anti-aliasing (MSAA) using randomized pixel sampling.
  • Fast Math: Leverages the glam crate for high-performance vectorized operations.
  • Terminal progress bar
  • GitHub continuous integration to build the Rust project on commit

Technical Details

Architecture

The engine is structured into focused modules:

  • scene.rs: Manages the world state, camera setup, and HDR texture loading.
  • geometries.rs: Defines the Ray structure and handles mathematical intersections. Currently supports mathematically perfect sphere intersections by solving quadratic equations.
  • materials.rs: Implements light scattering logic and material properties.
  • main.rs: The core rendering loop, configuring the camera, evaluating anti-aliased samples per pixel, casting rays, and writing output via an indicatif progress bar.

Rendering Equation

The path tracer recursively computes the color of a pixel by shooting rays from the camera into the scene. When a ray hits an object, a new ray is scattered based on the material’s BRDF (Bidirectional Reflectance Distribution Function), accumulating attenuation until the maximum bounce depth is reached or the ray escapes to the skybox.

Getting Started

Prerequisites

  • Rust: Ensure you have the latest stable Rust toolchain installed (edition 2024).

Building and Running

  1. Clone the repository:

    git clone https://github.com/rachitkakkar/rachit-pt.git
    cd rachit-pt
    
  2. Run the renderer in release mode (highly recommended for performance):

    cargo run --release
    
  3. The engine will render the scene and output an image file named output.png in the project root. You can monitor the progress via the integrated terminal progress bar.

Roadmap & Potential Features

  • A multithreaded progressive rendering system (e.g., via rayon)
  • A Phong bidirectional reflectance distribution function (BRDF) model for physically-based rendering
  • Bounding Volume Hierarchies (BVH) or bounding box acceleration structures
  • Support for triangle meshes (GLTF and OBJ model loading)
  • Texture and normal map support
  • Disney BSDF support (Low-Priority)

Sources & Acknowledgments