Skip to content

RadaanMadhan/RayTracing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌟 RayTracing

CI - Unit Tests

A high-performance C++ ray tracing engine that generates photorealistic images using Monte Carlo path tracing

This project implements a CPU-based ray tracer with support for various materials, realistic lighting, and geometric primitives, producing stunning rendered images with physically-based accuracy.

πŸ“Έ Gallery

Sample Ray Traced Scene
Sample render showcasing Lambertian Sphere

✨ Features

🎯 Core Ray Tracing

  • Monte Carlo Path Tracing: High-quality rendering with configurable samples per pixel
  • Physically-Based Materials: Support for multiple material types with realistic light interaction
  • Anti-aliasing: Multi-sampling for smooth, high-quality images
  • Recursive Ray Bouncing: Configurable maximum ray depth for realistic lighting

🎨 Materials

  • 🏐 Lambertian: Diffuse materials for matte surfaces
  • πŸͺž Metal: Reflective surfaces with configurable fuzziness
  • πŸ’Ž Dielectric: Glass-like materials with refraction and reflection
  • πŸ’‘ Emissive: Light-emitting materials for illumination

πŸ“ Geometry

  • βšͺ Spheres: Primary geometric primitive with material assignment
  • πŸ“‹ HittableList: Scene management for multiple objects
  • 🎯 Hit Testing: Efficient ray-geometry intersection calculations

πŸ“· Camera System

  • πŸ”­ Perspective Camera: Configurable field of view and aspect ratio
  • 🎯 Flexible Positioning: Look-at system with customizable up vector
  • πŸ“‘ Ray Generation: Generates camera rays for each pixel

πŸ–ΌοΈ Rendering

  • πŸ–ΌοΈ PPM Image Output: Standard image format for rendered results
  • ⏱️ Performance Timing: Built-in render time measurement
  • πŸ“ Configurable Resolution: Customizable image dimensions
  • 🌈 Background Control: Adjustable background colors

πŸ“‚ Project Structure

RayTracing/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.cpp              # Main application entry point
β”‚   β”œβ”€β”€ core/                 # Core ray tracing components
β”‚   β”‚   β”œβ”€β”€ Vec3.*            # 3D vector mathematics
β”‚   β”‚   β”œβ”€β”€ Ray.*             # Ray class for ray casting
β”‚   β”‚   └── Camera.*          # Camera system
β”‚   β”œβ”€β”€ geometry/             # Geometric primitives
β”‚   β”‚   β”œβ”€β”€ Hittable.h        # Base class for hittable objects
β”‚   β”‚   β”œβ”€β”€ HitRecord.h       # Ray-object intersection data
β”‚   β”‚   β”œβ”€β”€ HittableList.*    # Scene object container
β”‚   β”‚   └── Sphere.*          # Sphere primitive implementation
β”‚   β”œβ”€β”€ materials/            # Material system
β”‚   β”‚   β”œβ”€β”€ Material.h        # Base material interface
β”‚   β”‚   β”œβ”€β”€ Lambertian.*      # Diffuse material
β”‚   β”‚   β”œβ”€β”€ Metal.*           # Metallic material
β”‚   β”‚   β”œβ”€β”€ Dielectric.*      # Glass/transparent material
β”‚   β”‚   └── Emissive.*        # Light-emitting material
β”‚   β”œβ”€β”€ render/               # Rendering system
β”‚   β”‚   β”œβ”€β”€ Renderer.*        # Main rendering engine
β”‚   β”‚   └── Image.*           # Image handling
β”‚   β”œβ”€β”€ gpu/                  # GPU rendering (placeholder)
β”‚   β”‚   └── raytracer.cu      # CUDA implementation (empty)
β”‚   └── utils/                # Utility functions
β”œβ”€β”€ tests/                    # Unit tests
β”œβ”€β”€ include/                  # Additional headers
β”œβ”€β”€ scenes/                   # Scene configuration files
β”œβ”€β”€ docs/                     # Documentation
└── build/                    # Build output directory

βš™οΈ Requirements

πŸ”§ Build Dependencies

  • CMake 3.29+: Build system
  • C++20 Compatible Compiler: GCC, Clang, or MSVC
  • SFML 3.0.1: Graphics library (automatically downloaded)

πŸƒβ€β™‚οΈ Runtime Dependencies

  • SFML Libraries: Graphics, Window, and System modules

πŸ”¨ Building the Project

πŸ“‹ Prerequisites

Make sure you have the following installed:

  • CMake 3.29 or higher
  • A C++20 compatible compiler
  • Git (for dependency fetching)

πŸš€ Build Steps

  1. πŸ“₯ Clone the repository:

    git clone https://github.com/RadaanMadhan/RayTracing.git
    cd RayTracing
  2. πŸ“ Create and navigate to build directory:

    mkdir build
    cd build
  3. βš™οΈ Configure with CMake:

    cmake ..
  4. πŸ”¨ Build the project:

    cmake --build .

🎯 Build Targets

  • raytracer: Main executable for ray tracing
  • raytracer_lib: Static library with core functionality
  • Test executables: Vec3_tests, Ray_tests, Camera_tests, Sphere_tests

πŸš€ Usage

▢️ Running the Ray Tracer

After building, run the main executable from the build directory:

./src/raytracer        # On Linux/Mac
.\src\raytracer.exe    # On Windows

The program will:

  1. Initialize a scene with spheres and materials
  2. Set up a camera with configurable parameters
  3. Render the scene using Monte Carlo sampling
  4. Output the result as render.ppm
  5. Display render time statistics

βš™οΈ Configuration

The main rendering parameters can be modified in src/main.cpp:

constexpr int imageWidth = 800;      // Image width in pixels
constexpr int imageHeight = 400;     // Image height in pixels
constexpr int samplesPerPixel = 200; // Anti-aliasing samples
constexpr int maxDepth = 50;         // Maximum ray bounce depth

πŸ“· Camera Settings

const Vec3 origin(0, 0, -5);         // Camera position
const Vec3 lookAt(0, 0, 0.5);        // Look at point
const Vec3 up(0, 1, 0);              // Up vector
float fov = 40 * M_PI / 180;         // Field of view in radians

πŸ§ͺ Testing

The project includes comprehensive unit tests using Google Test:

πŸƒβ€β™‚οΈ Running Tests

cd build
ctest                    # Run all tests
./tests/Vec3_tests       # Run specific test suite

πŸ“Š Test Coverage

  • Vec3 Tests: Vector mathematics operations
  • Ray Tests: Ray creation and manipulation
  • Camera Tests: Camera ray generation
  • Sphere Tests: Sphere-ray intersection

πŸ–ΌοΈ Output

The ray tracer generates images in PPM format (render.ppm). This format can be:

  • Viewed with image viewers that support PPM
  • Converted to other formats using tools like ImageMagick:
    convert render.ppm render.png

⚑ Performance

πŸ–₯️ Current Implementation

  • CPU-based rendering: Single-threaded Monte Carlo path tracing
  • Typical render times: Varies based on resolution and sample count
  • Memory usage: Minimal, suitable for complex scenes

πŸš€ Future Improvements

  • GPU acceleration using CUDA (framework in place)
  • Multi-threading support
  • Acceleration structures (BVH, etc.)
  • Additional geometric primitives

🀝 Contributing

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch
  3. πŸ§ͺ Add tests for new functionality
  4. βœ… Ensure all tests pass
  5. πŸ“ Submit a pull request

πŸ“„ License

This project is open source. Please check the repository for license details.

πŸ™ Acknowledgments

This ray tracing implementation is inspired by:

  • πŸ“š "Ray Tracing in One Weekend" series by Peter Shirley
  • πŸ“– "Physically Based Rendering" by Pharr, Jakob, and Humphreys
  • πŸ”¬ Real-time rendering techniques and Monte Carlo methods

About

A high-performance C++ ray tracing engine that generates photorealistic images using Monte Carlo path tracing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors