• Home
  • Projects
  • Publications
  • Personal

Jacco’s Blog

Links, Code & Articles

  • Home
  • Projects
  • Publications
  • Personal

Source Code: CPU Voxel Ray Tracer

March 28, 2019 Source Code No Comments

This source package is based on a somewhat old experiment on CPU ray tracing. The 3D world consists of voxels: a grand total of 8192x512x8192 of them, each with a 24-bit color, for a grand total of 128GB of raw data. The data is subdivided in chunks of 128^3 voxels, which are then compressed to a compact octree. The result is a much more manageable ~2GB world.

The data for the world is generated procedurally at runtime, and stored to disk once generated. The world generator is based on Dave Hoskin’s work on Shadertoy: https://t.co/G2b8w2akXE .

The first interesting bit in this code is the octree construction in file chunk.cpp. A 128^3 buffer (8MB of data) is first reordered into Morton order, which is essentially already an octree. We then mark, at each level of the octree, identical cells. The unused ‘alpha channel’ of the voxels is used for this: bit i in this channel is set for each voxel that is identical to the 7 other voxels at level i in the octree that have the same parent. The final octree is then obtained by using run-length encoding.

The other interesting bit may be the actual ray tracing code in packet.cpp, which is multithreaded and vectorized and uses ray packets to rapidly intersect the chunks and the compressed octree data directly.

Source code can be downloaded here (Windows / Visual Studio 2017).

Demo: Simplex Paternitas

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • A Voxel Renderer for Learning C/C++
  • OPT#4:SIMD (part 2 of 2)
  • OPT#3:SIMD (part 1 of 2)
  • Optimizing Trilinear Interpolation
  • Speeding Up Lighthouse 2

Recent Comments

  • Hugo on Probability Theory for Physically Based Rendering Part 2
  • Muhammad Mobeen Movania on Optimizing Trilinear Interpolation
  • jbikker on Optimizing Trilinear Interpolation
  • Dithermaster on Optimizing Trilinear Interpolation
  • jbikker on OPT#4:SIMD (part 2 of 2)

Archives

  • February 2021
  • May 2020
  • April 2020
  • March 2020
  • December 2019
  • July 2019
  • May 2019
  • March 2019

Categories

  • Article
  • Coding
  • Demo
  • Source Code
  • Tutorial

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Archives

  • February 2021
  • May 2020
  • April 2020
  • March 2020
  • December 2019
  • July 2019
  • May 2019
  • March 2019

Pages

  • Lighthouse 2 / RTX Path Tracing Benchmark
  • Personal
  • Projects
  • Publications
  • Voxel World Template
Proudly powered by WordPress | Theme: Doo by ThemeVS.