1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! # rtwlib
//! This is a simple and raytracing library, designed for simple use and modification, based on the books"Ray Tracing in One Weekend" and "Ray Tracing: the next week" by Peter Shirley.
//! This isn't optimized for performance, so I would heavily reccomend only using it in situations where computation time isn't a concern.
//! # Get started
//! To render a scene, you need two things: a `Camera` and a scene, in the form of a `HittableList`.
//! The following code creates a scene and camera, and renders the scene to a Vec<u8> containing the RGB values of the pixels.
//! ```
//! use rtwlib::{camera::Camera, hittable::HittableList};
//!
//! fn main() {
//! let mut world = HittableList {
//! objects: Vec::new(),
//! };
//! let mut cam = Camera::new();
//!
//! let image_bytes = cam.render_to_bytes(world, |progress| println!("Progress: {}%", progress));
//! // Do something with the bytes
//! }a
//! ```
//! This is the bare minimum needed to render a scene, and will result in a sky background, as no objects have been added to the scene.
//! ## Adding objects to the scene
//! Any object that implements the `Hittable` trait can be added to the scene, the base crate only provides a `Sphere` object that can be used, but you can create your own objects by implementing the `Hittable` trait for your own objects.
//! Objects also need to have an associated material, to inform how light bounces should be calculated which can be any object that implements the `Material` trait, this can be
//! ```
//! fn main() {
//! let mut world = HittableList::new();
//!
//! let material = Rc::new(Lambertian::new(Color::new(0.3, 0.86, 0.1))); //create a new material with a vaugely green color
//! let sphere = Sphere::new(Point3::new(0., 0., -1.), 0.5, material); //create a new sphere at 0, 0, -1 with a radius of 0.5, using the material we just created
//!
//! world.add(sphere); //add the sphere to the world
//!
//! ...
//! //