Our Ray Tracer works with a scene where we render objects we can create objects on a given position. We use the add method on scene to add the objects to the scene.
For creating Object we have 4 types of object and 3 type of material for each object. The material are : Lambertian, Metal, Dielectric. We can also change the color of each objects.
let sphere = Sphere::new(
Vec3::new(0.0, 1.0, 0.0),
1.0,
Arc::new(Metal::new(Vec3::new(0.0, 0.250, 0.0), 0.3)))let cube = Cube::new(
Vec3::new(0.0, 1.0, 0.0),
Vec3::new(2.0, 1.0, 1.0) * 1.5,
Arc::new(Metal::new(Vec3::new(0.0, 0.302, 0.278), 0.3)),
)We can make a plane with texture and without texture
let checker = Arc::new(Lambertian::new_with_texture(CheckerTexture::new(
Vec3::new(0.2, 0.3, 0.1),
Vec3::new(0.9, 0.9, 0.9),
10.0,
)));
scene.add(Box::new(Plane::new(checker)));let cylinder = Cylinder::new(
Vec3::new(-1., 0.2, 2.0),
0.5,
1.0,
Arc::new(Metal::new(Vec3::new(0.0, 0.302, 0.278), 0.8)),
)scene.set_brightness(level);The camera has 5 parameters we can adjust to see the scene from a different perspectives.
- The position where from where we see (lookfrom)
- The position where we look at (lookat)
- The position of the camera on the y-axis
- Vertical field-of-view in degrees (vfov)
- The aspect ratio
let camera_setting = (
Vec3::new(13.0, 3.0, 1.0), //lookfrom
Vec3::new(0.0, 1.0, 0.0), //lookat
Vec3::new(0.0, 1.0, 0.0), // y-axis
20.0, // Vfov
3.0 / 2.0 ,
);
let mut scene = Scene::new(camera_setting);
scene.add(Box::new(OBJECT));