A high-performance, distributed ray tracing system with physically-based rendering capabilities, advanced geometry support, and spatial acceleration structures.
- 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
- Reflections: Variable reflectivity for mirror-like surfaces
- Transparency: Support for transparent objects with refraction
- Configurable Material Properties: Customize colors, specularity, shininess, and more
- 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
- 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
- Live Preview: Real-time rendering preview with SFML
- PPM Image Output: High-quality image export
- Progressive Rendering: See your image refine over time
Ray tracing simulates the physical behavior of light by following rays from the camera through each pixel into the scene:
- Ray Generation: For each pixel, a ray is cast from the camera position through the pixel into the scene
- Intersection Testing: The ray is tested against all scene objects to find the closest intersection
- Shading: At the intersection point, lighting calculations determine the pixel color
- Secondary Rays: For reflections and refractions, additional rays are recursively cast
Our implementation uses a client-server architecture to distribute the rendering workload:
-
Server:
- Manages the scene data
- Divides the image into chunks
- Distributes chunks to connected clients
- Assembles the final image from client results
-
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
To optimize intersection testing, we implement Binary Space Partitioning:
- The 3D space is recursively divided into smaller regions
- Primitives are organized in tree nodes based on their position
- When a ray traverses the scene, large sections can be quickly eliminated
- Only primitives in relevant regions are tested for intersection
- C++20 compatible compiler (GCC 10+ or Clang 10+)
- SFML Graphics library
- libconfig++
- pthread library
# 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./raytracer_server -p <port> -m <scene_file>./raytracer_client -h <server_ip> -p <port> [-d]Where:
-h: Server IP address-p: Port number-d: Optional debug mode
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; }
);
};
The client and server communicate using the Raytracer Distributed Rendering Protocol (RDRP), a custom binary protocol for efficient data transfer:
- Connection Handshake: Client connects and authenticates
- Scene Data Transfer: Server sends scene description
- Chunk Assignment: Server assigns image chunks to the client
- Rendering: Client processes chunks and returns pixel data
- Termination: Server notifies client when rendering is complete
/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
High-performance rendering of complex scenes with multiple objects, materials, and lighting conditions, accelerated by multi-threading.
Advanced Phong illumination model demonstrating realistic specular highlights, diffuse lighting, and shadow effects.
Realistic simulations of mirrors, glass, and other materials with physically-based reflection and refraction effects.
Support for a wide range of primitive shapes and imported 3D models allows for complex scene creation.
Subtle shadowing in corners and crevices adds realism by simulating how ambient light is blocked by nearby geometry.
- Matis Taam (@matis.taam)
- Youssef Mehili (@youssef.mehili)
- Spencer Pay (@spencer.pay)
- Elio Pinguet (@elio.pinguet)
This project is part of the Epitech curriculum.
