Falling Sand Simulation
Solo 8 Weeks C++
Assignment
For this school project we were given a template that could trace a voxel grid and return random colors. The task was to implement proper lighting and create some form of a game using CPU raytracing. Since the project was based on a voxel grid, I decided to build a 3D falling sand simulation, combining raytracing techniques with physics-based particle behavior.

CPU Raytracing
I implemented several lighting models to bring the voxel world to life. This included directional lights, point lights, spot lights, and spherical area lights for more realistic illumination. I added support for textures and reflections to give materials more visual depth. For more advanced lighting, I implemented image-based lighting using a Monte Carlo approach with stochastic sampling. This created a somewhat noisy result with trailing artifacts, but it gave the scene more realistic ambient lighting. I also implemented Beer’s law for volumetric absorption, which worked well for water and smoke effects. While I didn’t manage to implement refraction for water, the absorption effects still gave somewhat convincing results. I also implemented a multi-leveled brickmap for improved grid tracing performance for sparce grids. This was very effective especially when using it for the game, because it consists of mostly empty space.
Falling Sand Simulation
The falling sand simulation itself was surprisingly straightforward to implement. Rather than going for complex optimizations, I used a subgrid system where each subgrid could be marked as active or inactive. Subgrids only became active when particles were moving in that region, which reduced the computational overhead without requiring more in depth approaches. This allowed the simulation to handle a decent number of particles while maintaining reasonable performance for the CPU raytracer.
Result
To turn the sandbox into an actual game, I created a terrain generation system that produces a target structure. The player needs to recreate this terrain within a time limit using the falling sand mechanics. While the gameplay itself is fairly simple, it serves as a good showcase for both the raytracing and simulation systems working together in real-time.
