Skip to content

ray-tracer

A compact GPU ray-tracing showcase in Rust. A WGSL fragment shader traces a small scene with two shaded spheres, a checkerboard floor, hard shadows, a sky gradient, and a fixed four-point antialiasing pattern. The rendered RGBA texture is copied back from wgpu and encoded directly as a PNG by the application.

Requirements

  • Rust 1.98.1, managed by the checked-in mise.toml.
  • A working wgpu graphics backend and driver (Vulkan on most Linux systems, Metal on macOS, or DX12 on Windows). No external renderer is invoked.
  • For headless/software rendering, a fallback adapter must be available. On Linux this is commonly provided by Mesa lavapipe and the Vulkan loader.

Install the pinned Rust toolchain and fetch the exact, locked crate versions:

mise run install

Render the built-in scene (default output is render.png, 800×450):

mise run run
# or: cargo run --locked -- --output scene.png --size 640x360

Ask wgpu specifically for a software/fallback adapter when running headlessly:

cargo run --locked -- --software --output render.png --size 320x180

Use --help for the available options. Dimensions must be positive and are capped at 16384 pixels per side. Adapter discovery and device creation failures include actionable driver/fallback guidance.

Development checks

mise run check

The check task runs deterministic unit tests and Clippy for all targets/features; Clippy's all and pedantic lint groups are enabled, and warnings fail the task. Tests cover sphere intersections (including misses and rays originating inside a sphere), zero-vector normalization, and the repeatable subpixel sample sequence.