Kwasniok / cpp-raytracing

non-linear raytraycing based on "Raytracing in One Weekend"
2 stars 0 forks source link
cpp cpp20 linux multithreading non-euclidean non-euclidean-raytracing nonlinear nonlinear-raytracing openmp raytracing raytracing-one-weekend

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

https://user-images.githubusercontent.com/7516208/204099110-1542b566-2150-459e-9823-26b5d7b94740.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).

https://user-images.githubusercontent.com/7516208/204099119-b7f8173d-471f-46bd-bddc-3b9e0f70dbe6.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).

https://user-images.githubusercontent.com/7516208/203775340-f9e0c10b-fd77-4084-9130-7be2bd69b9e7.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

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.

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

General Remarks

Movies

Curved

https://user-images.githubusercontent.com/7516208/191520786-c169b980-c4e6-4899-bd09-c5c95d53e7d6.mp4

Flat

https://user-images.githubusercontent.com/7516208/191520742-2c9fdb1e-5f0b-4696-b266-64c635c4e64b.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