feat(plane): add a special checkerboard plane

This commit is contained in:
2024-11-20 13:42:25 +01:00
parent c3d6d80fd7
commit 61b5437561
2 changed files with 85 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
use lispers::raytracer::{
camera::Camera,
plane::Plane,
plane::Checkerboard,
scene::Scene,
sphere::Sphere,
types::{Color, Light, Material, Point3, Vector3},
@@ -12,10 +12,10 @@ use std::time::Instant;
fn main() {
let mut scene = Scene::new();
scene.set_ambient(Color::new(0.2, 0.2, 0.2));
scene.set_ambient(Color::new(0.1, 0.1, 0.1));
scene.add_light(Light {
position: Point3::new(4.0, 7.0, 10.0),
position: Point3::new(5.0, 7.0, 10.0),
color: Color::new(1.0, 1.0, 1.0),
});
scene.add_light(Light {
@@ -23,16 +23,25 @@ fn main() {
color: Color::new(1.0, 1.0, 1.0),
});
scene.add_object(Arc::new(Plane::new(
scene.add_object(Arc::new(Checkerboard::new(
Point3::new(0.0, -1.0, 0.0),
Vector3::new(0.0, 1.0, 0.0),
Material::new(
Color::new(0.5, 0.5, 0.5),
Color::new(0.5, 0.5, 0.5),
Color::new(1.0, 1.0, 1.0),
Color::new(1.0, 1.0, 1.0),
Color::new(0.0, 0.0, 0.0),
0.0,
0.6,
0.5,
),
Material::new(
Color::new(0.0, 0.0, 0.0),
Color::new(0.0, 0.0, 0.0),
Color::new(0.0, 0.0, 0.0),
0.0,
0.5,
),
0.3,
Vector3::new(0.0, 0.0, 1.0),
)));
scene.add_object(Arc::new(Sphere::new(
@@ -76,14 +85,14 @@ fn main() {
Point3::new(-1.0, -0.5, 0.0),
Vector3::new(0.0, 1.0, 0.0),
60.0,
4 * 256,
3 * 256,
4 * 512,
3 * 512,
);
let fname = "demo-scene.png";
print!("Rendering demo scene...");
let start = Instant::now();
match camera.render(&scene, 5, 3).save(fname) {
match camera.render(&scene, 10, 4).save(fname) {
Ok(_) => {
println!(" finished ({}s) ", start.elapsed().as_secs_f32());
println!("Image saved to {}", fname)