Skip to content

non-linear raytraycing based on "Raytracing in One Weekend"

Notifications You must be signed in to change notification settings

Kwasniok/cpp-raytracing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ray Tracing

This project is based on https://raytracing.github.io/ and includes some additional twists like curved space.

Note: For a conventional linear ray tracer see commit b6bbcfe.

Features

Adaptive Non-Linear Ray Propagation

basic_swirl highres

Created with build/examples/basic_swirl (version ee5499f) using swirl_strength = 0.01 and resolution_factor = 4.

basic_twisted_orb highres

Created with build/examples/basic_twisted_orb (version f952428) using twist_angle = -6.0, resolution_factor = 4, ray_error_abs = 1e-12 and ray_depth = 10000.

example_schwarzschild

Created with build/examples/schwarzschild (version e931515) using speed_of_light = 100.0, schwarzschild_radius = 1.0, resolution_factor = 4, ray_error_abs = 1e-8 and ray_depth = 75. Took 303min12sec user time (intel i5-4590).

N-Dimensional Manifolds

Minkowski Space

instant_speed_of_light_60fps.mp4

Conventional 3D raytracing with infinite speed of light (for reference). The 3D spheres grow and shrink over time. All textures are time-independent. Everything appears to be synchronized. Created with build/examples/basic_minkowski (version 9693243b).

fixed_speed_of_light_60fps.mp4

4D raytracing in Minkowski space with a finite speed_of_light=7.0. Shown are 4D spheres (glomes) which appear to change size over time. All textures are 4D time-dependent chess board patterns and change color for every unit of space or time. The finite speed reults in distant events appearing to be delayed. Created with build/examples/basic_minkowski (version 9693243b).

slow_speed_of_light_0_to_20_60fps.mp4

Same setup as before but for varying speed_of_light (0 to 20) for a fixed moment in time. The faster the speed of light, the shorter the aparrent delay between two spatial regions. Created with build/examples/basic_minkowski (version 27d8af63).

Materials

materials: diffuse glass metal emitter

Diffuse, Dielectric, Metal & Emission

Rolling Shutter & Motion Blur

rolling shutter: rotor in motion

Wheel in Motion.

rolling shutter: rotor at rest

Resting.

Optimizations

  • Multi-Threaded
    • Rendering (fully)
    • BVH Tree Generation (partially)
  • Bounding Volume Hierachy (BVH)

Performance

basic_twisted_orb twist_angle -6 err_abs e-10 basic_twisted_orb twist_angle -3 err_abs e-10 basic_twisted_orb angle_0 err_abs_e-10
geometry curved curved flat
method adaptive Cash-Karp adaptive Cash-Karp adaptive Cash-Karp
file (commit f229e20) examples/basic_twisted_orb examples/basic_twisted_orb examples/basic_twisted_orb
size (resolution_factor) 480x270 pixel (2) 480x270 pixel (2) 480x270 pixel (2)
samples 100 100 100
twist_angle -6.0 -3.0 0.0
ray_error_abs 1e-10 1e-10 1e-3
user time (intel i5-4590) 61min31sec 47min17sec 2min41sec
basic_swirl swirl_strength 0.01 err_abs_e-10 basic_swirl 0 err_abs_e-10 basic_euclidean
geometry curved flat flat
method adaptive Cash-Karp adaptive Cash-Karp linear
file (commit 2cc272e) examples/basic_swirl examples/basic_swirl examples/basic_euclidean
size (resolution_factor) 480x270 pixel (2) 480x270 pixel (2) 480x270 pixel (2)
samples 100 100 100
swirl_strength 0.01 0.0 -
ray_error_abs 1e-10 1e-10 -
user time (intel i5-4590) 30min11sec 5min47sec 9sec

note: The image in the middle and right are identical due to the strong similarity of the renderers and usage of pseudo-random number generators with fixed seeds.

Build, Test & Preview

make

See ./build for the executables and ./out directory for the test image output.

Documentation

make doc

See ./doc directory for the documentation.

Run

./build/examples/<executable>

Where <executable> is any of the provided executables. Use --help to see the respective usage.

Image File Formats & Processing

The current image formats focus on ease on implementation and depend on netpbm.

  • PPM (Protable PixelMap also known as PNM) dircrete netpbm format (similar to PNG, JPEG etc.)
  • PFM (Protable FloatMap) floating point netpbm format (similar to HDR, RAW etc.)

To convert to the desired formats via the netpbm package. E.g.

pnmtopng $file.pnm > $file.png
pfmtopam $file.pfm > $file.pam
pamtopng $file.pam > $file.PNG
# ...

Or use imagemagick. E.g.

magick $file.pfm -gamma 1.0 -set gamma 1.0 $file.png
magick $file.pfm -gamma 1.0 -set gamma 1.0 $file.tiff

Proper exposure and color grading can be archived the same way as for images taken by real cameras. E.g. with darktable.

Build Documentation

make doc

See doc/html/index.html for the documentation.

Auto-Format

Run

.auto_format

to automatically format the entire code base (requires clang-format).

Debug

Add DEBUG=1 to make. The executables will be placed in build/debug instead.

Profile

Run

./profile

to get a profile (requires valgrind (profiler) and kcachegrind (show data)).

Requirements

  • Linux kernel v6.3+
  • C++20
  • C++ Boost v1.80+
  • gcc v13.1+ or glang v15.0+
  • make v4.4+
  • doxygen v1.9+ (optional, documentation)
  • netpbm v10.73+ (optional, image processing)
  • imagemagick v7.1+ (optional, image processing)
  • darktable v3.8+ (optional, image processing)
  • ffmpeg v6.0+ (optional, video processing)
  • clang-format v15.0+ (optional, development)
  • clang-tidy v15.0+ (optional, development)
  • valgrind v3.21+ (optional, debug & profiling)
  • kcachegrind v23.04+ (optional. debug & profiling)

General Remarks

  • The heavy usage of headers is intended for future use of c++ modules. Unfortunately, c++ modules are currently (Sep 2022) not widespread enough to be considered supported by all compilers.

Movies

Curved

mov_0-60.highq.mp4

Flat

mov_flat_0-60.highq.mp4
geometry curved flat
method non-linear propagation linear/conventional propagation
file (commit ed4358e) examples/swirl_triangles examples/triangles
size (resolution_factor) 480x270 pixel (2) 480x270 pixel (2)
frames 60 60
samples 1000 1000
ray_depth 500 500
ray_step_size 0.1 -
swirl_strength 0.01 -
wall time (AMD Ryzen 5 5600X) 2.5days 7min
max. total ray segments 3,888,000,000,000 3,888,000,000,000