No description
Find a file
2026-07-04 15:59:22 +01:00
.cargo rewriting the whole code to fix problimatic dyn 2026-04-25 21:35:54 +01:00
octree rewriting the whole code to fix problimatic dyn 2026-04-25 21:35:54 +01:00
src switching to vulkan 2026-05-16 21:31:14 +01:00
.gitignore init 2026-04-01 20:55:56 +01:00
.rust-analyzer.toml completed the diffuze material gpgpu and fixed a bunch of bugs 2026-05-03 18:40:54 +01:00
Cargo.lock switching to vulkan 2026-05-16 21:31:14 +01:00
Cargo.toml switching to vulkan 2026-05-16 21:31:14 +01:00
optimized_0.log Add Cargo config for release optimizations and benchmark logs 2026-04-17 17:43:40 +01:00
optimized_2.log Refactor octree to use ArcOct for improved type safety and clarity 2026-04-20 17:48:46 +01:00
optimized_octree_1.log Update elapsed time values in optimized_octree_1.log 2026-04-19 20:14:34 +01:00
readme.md updated the readme 2026-07-04 15:59:22 +01:00
unoptimized_0.log Add Cargo config for release optimizations and benchmark logs 2026-04-17 17:43:40 +01:00
unoptimized_1.log ``` 2026-04-19 20:13:22 +01:00
unoptimized_2.log Refactor octree to use ArcOct for improved type safety and clarity 2026-04-20 17:48:46 +01:00

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.

Rendered scene

Project render sample.

Current Status

  • The active renderer is GPU-backed through cubecl using the WGPU Vulkan feature.
  • cargo check passes 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 check or cargo 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:

  1. main.rs creates a 1024 x 1024 Speedy2D window.
  2. init builds a procedural cylinder scene and initializes a perspective camera.
  3. The scene is packed into a flat GPU buffer with 13 floats per cylinder: [center, axis, radius, height, material type, material payload].
  4. Every draw callback uploads the packed camera data and launches the CubeCL render kernel for the current tile.
  5. The GPU pixel buffer is read back into a CPU Vec<u8>.
  6. Speedy2D creates an image from the raw RGB pixels and draws it to the window.
  7. 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 f32 buffer, 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.rs contains both camera setup and the active CubeCL render kernel.
  • src/core/hittable_list.rs is the bridge between host-side scene data and GPU buffers.
  • src/core/shapes/cilinder.rs is 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.

Author

Majid Abdelilah
GitHub · YouTube