a ray tracer with both CPU and GPU acceleration capabilities implemented in rust, just a fun project, do it for learning purpose
with
- Path tracing with Monte Carlo sampling
- Materials: Lambertian diffuse, metal, dielectric (glass)
- Camera with depth of field and adjustable field of view
- Cross-platform GPU acceleration using wgpu
- PPM image output format
- just your shitty laptop, that have GPU with Vulkan, Metal, or DirectX 12 support (if you dont have then use your poor cpu)
cargo build --releasecargo build --release --features gpucargo run --releasecargo run --release --features gpu -- --gpucargo run --release -- -o output.ppmcargo run --release --features gpu -- --gpu -o output.ppm--gpuor-g: Enable GPU acceleration (requires compilation with--features gpu)-oor--outputfollowed by a filename: Save the render to a PPM file
ofc GPU-accelerated version can be significantly faster than the CPU version, especially for high sample counts and complex scenes. Performance will vary based on your specific GPU.
You might want to adjust rendering parameters in main.rs for faster preview:
// Camera setup
let mut cam = Camera::new();
cam.aspect_ratio = 16.0 / 9.0;
cam.image_width = 1200;
cam.samples_per_pixel = 500; // Lower this to 100-200 for faster rendering
cam.max_depth = 50;
cam.vfov = 20.0;
cam.lookfrom = Point3::new(13.0, 2.0, 3.0);
cam.lookat = Point3::new(0.0, 0.0, 0.0);
cam.vup = Vec3::new(0.0, 1.0, 0.0);
cam.defocus_angle = 0.6;
cam.focus_dist = 10.0;
cam.use_gpu = use_gpu; // This is set from command-line args- CPU rendering is implemented in pure Rust
- GPU rendering is implemented using wgpu for cross-platform compatibility (Metal on macOS, Vulkan on Linux, DirectX 12 on Windows)
- The ray tracing algorithm is implemented as a compute shader in WGSL
