Project

Raytracing on the CPU

A CPU-based voxel raytracer implemented in C++, featuring realistic lighting effects such as shadows, reflections, refractions, and light absorption using Beer's Law.

Raytracing on the CPU Preview

🎓 About the Project

This project was part of my university curriculum, where the goal was to implement a raytracing engine in 8 weeks using the provided template, focusing on voxel-based rendering. I designed and developed the core raytracing algorithm, which runs entirely on the CPU, allowing it to simulate lighting effects like shadows, reflections, and refractions.

The project served as my introduction into graphics programming.

🎮 Play on itch.io

📂 Source Code & Template

The game is based on a template I received during the block, which you can find here on GitHub.

📚 Project Articles (with code!)

Throughout the project, I documented my learning and development process in a series of articles. These posts dive into the various aspects of building a CPU-based raytracer and cover aspects of this project:

  1. Learning-Raytracing-in-8-weeks | Area Lights | Part 1
    An introduction to the project, focusing on area lights and realistic shadow casting.

  2. Learning-Raytracing-in-8-weeks | Glass made out of voxels | Part 2
    Techniques for simulating glass effects in a voxel-based raytracer.

  3. Learning-Raytracing-in-8-weeks | Transforming voxel volumes | Part 3
    A discussion on implementing transformations within voxel volumes.

  4. Learning-Raytracing-in-8-weeks | Simple Smoke with Beer’s Law | Part 4
    An exploration of Beer’s Law to simulate light absorption for semi-transparent objects like smoke.

🛠️ Technologies Used

  • C++: Developed core game logic and the raytracing algorithm.
  • GLFW: Managed graphics rendering, window handling, and input events to streamline the interface.
  • ImGui: Used to create an user interface for real-time control over raytracing parameters like light intensity and reflection settings.

⚙️ My Contributions

Voxel-Based Raytracing

Built a raytracer that renders voxel structures, allowing for dynamic scenes constructed from 3D grids.

Voxel volume transformation demonstration Real-time voxel volume rotation and transformation

Beer’s Law for Light Absorption

Implemented Beer’s Law to simulate light absorption in semi-transparent objects like smoke or glass.

Light absorption simulation using Beer's Law Smoke cloud rendered with volumetric light absorption

Area Lighting for Soft Shadows

Created area lights that cast realistic shadows based on the light source’s size and distance.

Soft shadow rendering with area lights Soft shadows created by area light sources

Optimization Techniques

Optimized the raytracing algorithm with:

  • Multithreading: Using multithreading to distribute ray calculations across multiple CPU cores.
  • SIMD (Single Instruction, Multiple Data): Applied SIMD instructions to process multiple rays simultaneously.