A high-performance, modular ray tracing engine written in modern C++ with a focus on clean architecture, extensibility, and educational value. This project demonstrates advanced C++ concepts, mathematical foundations, and computer graphics principles.
- Overview
- Features
- Architecture
- Installation
- Usage
- Technical Details
- Project Structure
- Roadmap
- Contributing
- License
This ray tracing engine implements a physically-based rendering system that simulates light transport in 3D environments. The project serves as both a learning platform for computer graphics concepts and a foundation for more advanced rendering applications.
- Modular Design: Clean separation of concerns with dedicated classes for vectors, rays, colors, and rendering
- Performance Optimized: Efficient mathematical operations and memory management
- Extensible Architecture: Easy to add new features like materials, lighting, and geometric primitives
- Modern C++: Utilizes C++17/20 features for type safety and performance
- Educational Focus: Well-documented codebase perfect for learning ray tracing fundamentals
- β Vector Mathematics: Complete 3D vector operations (addition, subtraction, multiplication, dot/cross products)
- β Ray Generation: Efficient ray creation and manipulation for camera projection
- β Color Management: RGB color space handling with proper gamma correction
- β Camera System: Pinhole camera model with configurable aspect ratio and resolution
- β Gradient Background: Sky-like gradient rendering based on ray direction
- β PPM Output: Standard PPM image format for easy viewing and processing
- π Geometric Primitives: Spheres, planes, triangles, and complex meshes
- π Material System: Diffuse, metallic, dielectric, and custom materials
- π Lighting: Point lights, area lights, and environment maps
- π Shadows & Reflections: Realistic shadow casting and surface reflections
- π Anti-aliasing: Multi-sampling for smooth edges and reduced noise
- π Acceleration Structures: BVH trees for efficient ray-object intersection
- π Texture Mapping: UV coordinates and procedural textures
- π Motion Blur: Temporal effects for dynamic scenes
The mathematical foundation of the engine, providing:
- 3D vector operations with operator overloading
- Efficient memory layout with array-based storage
- Mathematical utilities (length, normalization, dot/cross products)
- Type-safe operations with const-correctness
Represents light rays in 3D space:
- Origin and direction vectors
- Ray parameterization for intersection calculations
- Immutable design for thread safety
- Efficient
at(t)method for point evaluation
Handles color representation and output:
- RGB color space with proper gamma correction
- PPM format output for image generation
- Namespace-based organization for clarity
- Stream-based output for flexibility
Orchestrates the rendering pipeline:
- Camera setup with configurable parameters
- Ray generation for each pixel
- Viewport and pixel coordinate calculations
- Progress tracking and output management
- RAII: Automatic resource management
- Const Correctness: Immutable operations where appropriate
- Operator Overloading: Intuitive mathematical syntax
- Namespace Organization: Clear separation of concerns
- Stream-Based I/O: Flexible output handling
- C++17/20 compatible compiler (GCC 7+, Clang 5+, MSVC 2017+)
- CMake 3.10 or higher
- Make or Ninja build system
# Clone the repository
git clone <repository-url>
cd RT
# Create build directory
mkdir build && cd build
# Configure with CMake
cmake ..
# Build the project
make -j$(nproc)
# or
ninja# Generate a test image
./RT > output.ppm
# View the result (requires image viewer)
# On Linux: eog output.ppm
# On macOS: open output.ppm
# On Windows: start output.ppm#include "Color.h"
#include "Ray.h"
#include "Vec3.h"
// The engine automatically generates a gradient sky
// based on ray direction for each pixel// Modify these parameters in main.cpp for different results
auto aspect_ratio = 16.0 / 9.0; // Widescreen format
int image_width = 400; // Resolution
auto focal_length = 1.0; // Camera distance
auto viewport_height = 2.0; // Field of viewThe renderer outputs PPM (Portable Pixmap) format:
- Header:
P3(ASCII RGB) - Dimensions:
width height - Color depth:
255 - Pixel data:
R G Bvalues per line
- Addition/Subtraction: Component-wise operations
- Scalar Multiplication: Efficient scaling with operator overloading
- Dot Product: Used for lighting calculations and projections
- Cross Product: Essential for normal calculations and coordinate systems
- Normalization: Unit vector generation for direction calculations
- Camera Setup: Define viewport and pixel grid
- Ray Generation: Create rays from camera through each pixel
- Intersection Testing: (Future) Test rays against scene objects
- Color Calculation: Determine pixel color based on ray direction
- Output: Write RGB values to image file
- Right-handed: Standard computer graphics convention
- Y-up: World coordinate system with Y pointing upward
- Camera Space: Z-axis pointing into the scene
- Memory Layout: Array-based vector storage for cache efficiency
- Const References: Minimize copying in function parameters
- Inline Functions: Small mathematical operations inlined for speed
- Stream Buffering: Efficient output handling for large images
RT/
βββ CMakeLists.txt # Build configuration
βββ main.cpp # Main rendering loop
βββ Vec3.h # Vector mathematics interface
βββ Vec3.cpp # Vector mathematics implementation
βββ Ray.h # Ray class definition
βββ Color.h # Color utilities interface
βββ Color.cpp # Color utilities implementation
βββ cmake-build-debug/ # Build artifacts
CMakeLists.txt: Modern CMake configuration with proper target setupmain.cpp: Entry point with camera setup and rendering pipelineVec3.h/cpp: Mathematical foundation with 3D vector operationsRay.h: Ray representation for light transport simulationColor.h/cpp: Color space handling and image output utilities
- Vector mathematics library
- Ray representation and manipulation
- Basic camera system
- Color output system
- Gradient background rendering
- Sphere intersection algorithms
- Plane and triangle primitives
- Mesh loading and rendering
- Bounding box calculations
- Ray-object intersection testing
- Diffuse material implementation
- Metallic and dielectric materials
- Point and area light sources
- Shadow casting algorithms
- Reflection and refraction
- Anti-aliasing (multi-sampling)
- Acceleration structures (BVH)
- Texture mapping system
- Motion blur and depth of field
- Environment maps and HDR lighting
- Multi-threading support
- GPU acceleration (CUDA/OpenCL)
- Real-time preview mode
- Scene file format (JSON/YAML)
- GUI for parameter adjustment
- Advanced materials (subsurface scattering, anisotropy)
- Volume rendering (fog, smoke, clouds)
- Animation and keyframe support
- Network rendering capabilities
- Plugin system for custom shaders
We welcome contributions! Please see our contributing guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow modern C++ best practices
- Maintain const-correctness and RAII principles
- Add comprehensive unit tests for new features
- Update documentation for API changes
- Ensure cross-platform compatibility
- Use meaningful variable and function names
- Include proper header guards and includes
- Follow consistent indentation (4 spaces)
- Add comments for complex algorithms
- Use
[[nodiscard]]for important return values
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by "Ray Tracing in One Weekend" by Peter Shirley
- Built with modern C++ principles and best practices
- Designed for educational and professional use
Built with β€οΈ and modern C++