rt is a simple ray tracing project designed to build foundational understanding of rendering 3D scenes through ray tracing techniques. Below is the default scene rendered.
In this project, we implement:
- simple objects:
- 2D plane
- Cube
- Cylinder
- Sphere
- camera
- lights:
- directional
- point
- material:
- lambertian
- metal
- dielectric
- Texture:
- Solid Color
- Checked Box
- Gradient
- Image
We explore the following concepts:
- The mathematical foundations of ray tracing
- How geometric shapes are defined and rendered in 3D space
- The role of light, material, and texture in producing realistic images
This project is written entirely in Rust. To get started:
- Make sure Rust is installed.
- Clone the repository
Running the project with:
cargo run
will render a default scene and save the output to a file named output.ppm in the current directory.
To render your own scene, you will have to define your scene in main.rs fn main().
fn main() -> std::io::Result<()> {
let mut scene = Scene::new();
default_scene(&mut scene); // replace this with your scene setup
scene.render("output.ppm")?;
Ok(())
}Read about the basic types that you will be working with.
Read about the scene elements and how to set them up.
This project supports several command-line flags to customize rendering without modifying the source code.
Run your program with flags like this:
cargo run -- [FLAGS]| Flag | Description | Example |
|---|---|---|
-o <filename> |
Specify output filename instead of the default output.ppm |
-o result.ppm |
-s <scene_num> |
Select which scene to render. Valid values: 1 to 4. Defaults to scene 4. | -s 2 |
-r <width> <height> |
Set the resolution of the rendered image. Width and height must be positive integers. | -r 800 600 |
Render scene 2 with resolution 800x600 and save output as my_render.ppm:
cargo run -- -s 2 -r 800 600 -o my_render.ppmIf you omit any flags, the program uses default values:
- Scene 3 is rendered
- Resolution is whatever is set in the scene (or default)
- Output is saved to
output.ppm
