Raydiancy is a ray tracer written in Rust. This is a side project that I work on for fun (and initially to learn Rust). It's still in its early stages but already usable (see Examples).
- supported object types
- spheres
- triangles
- planes
- triangle meshes
- importing 3D models from .obj files (only limited support so far)
- supported lighting
- Phong model (ambient, diffuse, specular)
- shadows
- reflections (e.g. mirrors)
- refractions (e.g. glass)
- bounding volume hierarchies (space partitioning for faster rendering)
- alpha channel (transparent background)
- super-sampling for anti-aliasing
- textures
- parallel rendering
- Monte-Carlo ray tracing
-
Install Rust if it's not already installed on your system.
-
Clone:
git clone https://github.com/fanzier/raydiancy.git cd raydiancy
-
Build:
cargo build --release
-
Run:
./target/release/main
This renders a few example scenes and writes the output to ./output/
.
The file src/bin/main.rs
already contains a few example scenes.
You can add your own ones as follows.
-
Write a function that returns your scene, for example:
fn my_scene() -> Scene { Scene { camera: Camera { pos: Vec3::new(10.0, 10.0, 10.0), look_at: Vec3::zero(), up: Vec3::new(0.0, 1.0, 0.0), horizontal_fov: 120_f64.to_radians(), aspect_ratio: 1.0, width: 360, height: 360 }, objects: vec![Box::new( Sphere { center: Vec3::zero(), radius: 8.0, material: color_material(Color::new(0.0, 0.0, 1.0)) })], ambient_color: white(), lights: vec![LightSource { pos: Vec3::new(0.0, 10.0, 10.0), col: white() }] } }
This scene includes
- a blue sphere of radius 8 at the origin of the coordinate system and
- a white light at coordinates (10, 10, 10).
-
Add the line
render!(my_scene);
to the main function.
-
Build and run the program as described above.
-
The result is in
output/my_scene.png
:
The following images are the output of the scenes defined in
src/bin/main.rs
.