Skip to content

fanzier/raydiancy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raydiancy: Ray Tracer

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).

Features

  • 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

Build instructions

  1. Install Rust if it's not already installed on your system.

  2. Clone:

    git clone https://github.com/fanzier/raydiancy.git
    cd raydiancy
  3. Build:

    cargo build --release
  4. Run:

    ./target/release/main

This renders a few example scenes and writes the output to ./output/.

Create your own scenes

The file src/bin/main.rs already contains a few example scenes. You can add your own ones as follows.

  1. 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).
  2. Add the line

    render!(my_scene);

    to the main function.

  3. Build and run the program as described above.

  4. The result is in output/my_scene.png:

    Rendered image for the above example

Examples

The following images are the output of the scenes defined in src/bin/main.rs.

Stanford bunny

Stanford bunny

Stanford dragon

Stanford dragon

Spheres and mirrors

Spheres and mirrors

About

Ray-tracer implemented in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages