Skip to content

Esspyyy/Raytracer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

145 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Raytracer

A high-performance, distributed ray tracing system with physically-based rendering capabilities, advanced geometry support, and spatial acceleration structures.

πŸš€ Features

Core Rendering Features

  • Distributed Rendering Architecture: Client-server model for parallel processing across multiple machines
  • Multi-threaded Rendering: Utilizes all available cores for maximum performance
  • Supersampling Anti-aliasing: Up to 64Γ— anti-aliasing for crisp, clean images
  • Advanced Lighting Algorithms:
    • Phong illumination model with customizable parameters
    • Ambient, directional, and point light support
    • Ambient occlusion for realistic light falloff in corners and crevices
    • Soft shadows with realistic penumbra

Materials and Effects

  • Reflections: Variable reflectivity for mirror-like surfaces
  • Transparency: Support for transparent objects with refraction
  • Configurable Material Properties: Customize colors, specularity, shininess, and more

Geometry Support

  • Primitive Shapes:
    • Spheres
    • Planes
    • Cylinders (full and limited)
    • Cones (full and limited)
    • Tori
    • Triangles for complex mesh construction
  • OBJ Model Loading: Import external 3D models

Performance Optimizations

  • Binary Space Partitioning (BSP): Spatial partitioning for faster ray-primitive intersection
  • Bounding Volume Hierarchy: Quick culling of non-intersecting primitives
  • Network Protocol: Efficient chunk-based rendering distribution system

Visualization

  • Live Preview: Real-time rendering preview with SFML
  • PPM Image Output: High-quality image export
  • Progressive Rendering: See your image refine over time

🧠 How It Works

Ray Tracing Fundamentals

Ray tracing simulates the physical behavior of light by following rays from the camera through each pixel into the scene:

  1. Ray Generation: For each pixel, a ray is cast from the camera position through the pixel into the scene
  2. Intersection Testing: The ray is tested against all scene objects to find the closest intersection
  3. Shading: At the intersection point, lighting calculations determine the pixel color
  4. Secondary Rays: For reflections and refractions, additional rays are recursively cast

Distributed Architecture

Our implementation uses a client-server architecture to distribute the rendering workload:

  1. Server:

    • Manages the scene data
    • Divides the image into chunks
    • Distributes chunks to connected clients
    • Assembles the final image from client results
  2. Client:

    • Connects to the server
    • Receives scene data and chunk assignments
    • Renders assigned chunks using local CPU resources
    • Returns rendered pixel data to the server

BSP Tree Acceleration

To optimize intersection testing, we implement Binary Space Partitioning:

  1. The 3D space is recursively divided into smaller regions
  2. Primitives are organized in tree nodes based on their position
  3. When a ray traverses the scene, large sections can be quickly eliminated
  4. Only primitives in relevant regions are tested for intersection

πŸ›  Building and Running

Prerequisites

  • C++20 compatible compiler (GCC 10+ or Clang 10+)
  • SFML Graphics library
  • libconfig++
  • pthread library

Building

# Clone the repository
git clone https://github.com/yourusername/raytracer.git
cd raytracer

# Build both client and server
make

# Build only the server
make server

# Build only the client
make client

Running the Server

./raytracer_server -p <port> -m <scene_file>

Running Client(s)

./raytracer_client -h <server_ip> -p <port> [-d]

Where:

  • -h: Server IP address
  • -p: Port number
  • -d: Optional debug mode

πŸ“ Scene Configuration

Scenes are defined using a configuration file format. Here's a simple example:

camera:
{
  resolution = { width = 1920; height = 1080; };
  position = { x = 0.0; y = -100.0; z = 20.0; };
  fieldOfView = 72.0;
};

primitives:
{
  spheres = (
    {
      x = 0.0; y = 0.0; z = 0.0; r = 10.0;
      color = { r = 255; g = 0; b = 0; };
      reflectivity = 0.5;
    }
  );
};

lights:
{
  ambient = { intensity = 0.2; };
  point = (
    { x = -50.0; y = -50.0; z = 50.0; intensity = 0.6; }
  );
};

πŸ”„ Network Protocol

The client and server communicate using the Raytracer Distributed Rendering Protocol (RDRP), a custom binary protocol for efficient data transfer:

  1. Connection Handshake: Client connects and authenticates
  2. Scene Data Transfer: Server sends scene description
  3. Chunk Assignment: Server assigns image chunks to the client
  4. Rendering: Client processes chunks and returns pixel data
  5. Termination: Server notifies client when rendering is complete

πŸ“š Project Structure

  • /include: Header files
    • /Client: Client-side components
    • /Factory: Object factories for dynamic creation
    • /Lights: Light source implementations
    • /Math: Vector and matrix operations
    • /Network: Socket and serialization utilities
    • /Primitives: 3D object implementations
    • /Raytracer: Core raytracing algorithms
    • /Server: Server-side components
    • /SpacePartitioning: Spatial acceleration structures
  • /src: Implementation files
  • /scenes: Example scene configuration files
  • /assets: Images and resources

πŸ§ͺ Advanced Features Showcase

Complex Multi-threaded Rendering

Complex multi-threaded rendering example High-performance rendering of complex scenes with multiple objects, materials, and lighting conditions, accelerated by multi-threading.

Phong Shading Model

Phong shading model showcase Advanced Phong illumination model demonstrating realistic specular highlights, diffuse lighting, and shadow effects.

Reflection and Refraction

Realistic simulations of mirrors, glass, and other materials with physically-based reflection and refraction effects.

Complex Geometry

Support for a wide range of primitive shapes and imported 3D models allows for complex scene creation.

Ambient Occlusion

Subtle shadowing in corners and crevices adds realism by simulating how ambient light is blocked by nearby geometry.

πŸ–₯️ Class Diagram

Class diagram showing the architecture

πŸ‘₯ Contributors

βš–οΈ License

This project is part of the Epitech curriculum.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors