No description
| .cargo | ||
| octree | ||
| src | ||
| .gitignore | ||
| .rust-analyzer.toml | ||
| Cargo.lock | ||
| Cargo.toml | ||
| optimized_0.log | ||
| optimized_2.log | ||
| optimized_octree_1.log | ||
| readme.md | ||
| unoptimized_0.log | ||
| unoptimized_1.log | ||
| unoptimized_2.log | ||
rt
rt is a Rust path tracer with a live windowed preview and a GPU compute rendering path built on CubeCL/WGPU. The current application opens a Speedy2D window, renders a procedural scene of cylinders with physically inspired materials, and progressively updates the image tile by tile.
Project render sample.
Current Status
- The active renderer is GPU-backed through
cubeclusing the WGPU Vulkan feature. cargo checkpasses on the current tree.- The project still contains older CPU and octree experiments, but they are not part of the active render loop.
- Several modules contain unused imports and inactive compatibility code; expect compiler warnings during
cargo checkorcargo run.
Features
- Live preview window: Speedy2D displays the render buffer and requests redraws continuously.
- GPU path tracing kernel: CubeCL launches a compute kernel for the active render tile and writes RGB data into a GPU buffer.
- Tile-based rendering: The frame is rendered in 256 x 256 tiles, one tile step at a time, then copied back for display.
- Procedural scene generation: The scene is generated at startup with a large ground cylinder and a grid of randomly assigned smaller cylinders.
- Cylinder primitive support: The active hittable path uses analytic finite-cylinder intersection.
- Material scattering:
- Lambertian diffuse scattering
- Metal reflection with configurable fuzz
- Dielectric refraction using Schlick reflectance
- Perspective camera: Camera basis vectors, viewport dimensions, FOV, look-from/look-at, and per-pixel ray generation are computed from camera parameters.
- Monte Carlo sampling: Each pixel uses a small grid of samples per pixel and traces up to a fixed maximum depth.
- Gamma correction: Linear color values are converted before writing to the display buffer.
- Resize handling: The render target, camera, GPU pixel buffer, and tile indices are rebuilt when the window size changes.
Architecture
src/
main.rs Application setup, scene creation, window loop, GPU launches
core/
camera.rs Camera model, GPU render kernel, path tracing loop
ray.rs CPU/GPU ray types
interval.rs Ray interval helpers
hittable_list.rs Scene container and GPU cylinder packing
hittable_enum.rs Active hittable enum, currently cylinder-only
hittable_trait.rs Hit records, AABB helpers, compatibility traits
math/
vec3.rs CPU/GPU vector math and sampling helpers
mat4.rs Matrix utilities used by sphere code
random.rs Deterministic GPU-friendly RNG
fast_isqrt.rs Math experiment/utility
materiales/
diffuse.rs Lambertian material
metal.rs Reflective material
dielectric.rs Refractive material
material_enum.rs Material dispatch types
material_trait.rs Shared material record types
shapes/
cilinder.rs Active cylinder primitive and GPU intersection
sphere.rs Transformed sphere implementation, currently inactive
gpu/
gpu.rs Earlier GPU wrapper experiment, not used by main loop
octree/
octree.rs Older CPU octree acceleration experiment, not wired into Cargo
The runtime flow is:
main.rscreates a1024 x 1024Speedy2D window.initbuilds a procedural cylinder scene and initializes a perspective camera.- The scene is packed into a flat GPU buffer with
13floats per cylinder:[center, axis, radius, height, material type, material payload]. - Every draw callback uploads the packed camera data and launches the CubeCL
renderkernel for the current tile. - The GPU pixel buffer is read back into a CPU
Vec<u8>. - Speedy2D creates an image from the raw RGB pixels and draws it to the window.
- The renderer advances to the next tile and loops back to the beginning after the full image has been covered.
Optimizations
- GPU execution: Ray generation, material scattering, intersection tests, and color accumulation run inside a CubeCL kernel.
- Flat scene buffers: Cylinders are serialized into a compact contiguous
f32buffer, avoiding pointer-heavy scene traversal on the GPU. - Tile dispatch: Work is bounded to fixed-size tiles, which keeps each kernel launch predictable and allows progressive feedback in the window.
- Closest-hit tracking: Intersection loops keep the nearest valid hit and narrow the accepted ray interval as objects are tested.
- Iterative bounce loop: The GPU path tracing code uses an explicit loop and active flag for bounce control.
- Packed vector layout: GPU vector types use four-wide storage where useful for alignment with shader-style data access.
- Procedural RNG: A lightweight deterministic RNG is used per pixel/sample in GPU-compatible code.
Build and Run
Requirements:
- Rust toolchain with edition 2024 support.
- A GPU/driver stack supported by WGPU Vulkan.
- Linux windowing dependencies required by Speedy2D/WGPU.
Build check:
cargo check
Run:
cargo run --release
A window titled rt opens and the current scene renders progressively. The initial window size is 1024 x 1024.
Notes for Contributors
- The active project entry point is
src/main.rs. src/core/camera.rscontains both camera setup and the active CubeCL render kernel.src/core/hittable_list.rsis the bridge between host-side scene data and GPU buffers.src/core/shapes/cilinder.rsis intentionally spelled as it exists in the codebase.octree/is useful historical context but should not be treated as production runtime code until it is ported to the current module names and render path.- The sphere implementation is present, including transform and GPU variants, but the current scene and active hittable enum only use cylinders.
Roadmap
- Clean unused imports and inactive compatibility code.
- Reintroduce acceleration structures in the active GPU path.
- Wire transformed spheres into the current hittable list.
- Add scene loading from a structured format.
- Add configurable render settings for resolution, samples, depth, and tile size.
- Reduce or eliminate full-buffer readback after each tile.
- Add screenshot/export support.
