Project page with paper pdf and supplemental video can be found here.
Note that this is all research-quality code. The interesting bits are contained entirely within /src/compute.wgsl.
- Download and install Rust
- Clone this repository
- Run
cargo run --release -- --Awarningsin the root directory
- Press
rto hot-reload/src/compute.wgsl - Camera controls are
w,a,s,d+ mouse to look - Scroll up or down to change movement speed
- If the camera controls feel wrong, disable the scene-dependant view matrix modifications in
fn rt_mainin/src/compute.wgsl
Ctrl+ffor "PARAMETERS" in/src/compute.wgsl, here you will find the following:localsubdivcontrols the octree resolution, e.g., 8 -> (2^8, or 256)^3 and 10 -> (2^10, or 1024)^3deltacontrols the temporal error tolerance, e.g., 0.01 (depends on the Lipschitz bounds off)pointsampleenables world-space point-sampling within indeterminate leavesfastenabledenables the fast-evaluation optimizationlipschitz_correctedenables Lipschitz-correction on deltaswept_volumeenables swept-volume renderingnormalvissets the surface color to the world-space normalscinematicenables naive pathtracing withtotalsamplessamples per pixelfast_normalsenables per-pixel normals via finite-differencesceneselects which scene's normals (iffast_normalsis true) / lighting / camera settings to use
- To enable fullscreen, set
shouldbefullscreenin/src/main.rsto true - To save frames to disk, set
save_frames_to_diskin/src/main.rsto true - To save timing data to disk, set
save_timing_to_diskin/src/main.rsto true
- Make
file_contentsin/src/IR.rsread fromscenes/something_else.ll - Set
scenein/src/compute.wgslaccording to the comment next to it
- Create new file
/scenes/example.cppand paste in your GLSL code - The field function must be named
f, mapping 4 floatsx,y,z,tto a single float - Paste this at the top of
/scenes/example.cpp#include <math.h> #include <cstring> #include "include/swizzle/setup.h" #include "overloads.h" - Install Clang and run
./compile.sh exampleto generateexample.ll - Fiddle with the code until
example.llcontains no branches or casts in the field function - In
/src/IR.rspoint the constructor's file contents toscenes/example.ll - Set
scenein/src/compute.wgslto some new value - Make sure
fast_normalsin/src/compute.wgslis set to false to get per-voxel normals. If you want per-pixel normals, keep reading
-
Paste your GLSL code into a temp file called
example.frag -
Paste this at the top of
example.fraglayout(location = 0) out vec4 color; void main() { color = vec4(0.0); } -
Run
naga example.frag example.wgslin the CLI -
Paste the contents of
example.wgslat the top of/src/compute.wgsl, ignoring theFragmentOutputandcolorlines (top of the file) as well asfn main()(bottom of file) -
Rename
fn fto something else, e.g.,fn example -
Add a new case to
fn finite_diff_normalin/src/compute.wgslto callfn exampleifsceneis set appropriately -
Make sure
scenein/src/compute.wgslis set to your new value -
Set
fastenabledin/src/compute.wgslto true so thatfn finite_diff_normalsis used
I've tested this code on Windows 10, Vulkan backend, with an RTX 3080 / i7 3930k. It should in theory work on other operating systems / GPUs and even the web thanks to wgpu. If you need help setting it up, please open an issue.