Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd72c24
commit 20f089f
Showing
8 changed files
with
212 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use glam::DVec3; | ||
use raytracer::{ | ||
camera::Camera, | ||
material::Material, | ||
shapes::{quad::Quad, sphere::Sphere}, | ||
textures::Texture, | ||
}; | ||
use std::{io, path::Path}; | ||
|
||
fn main() -> io::Result<()> { | ||
let mut world = vec![]; | ||
|
||
// Materials | ||
let red = Material::Lambertian { | ||
albedo: DVec3::new(0.65, 0.05, 0.05).into(), | ||
}; | ||
let white = Material::Lambertian { | ||
albedo: DVec3::new(0.73, 0.73, 0.73).into(), | ||
}; | ||
let green = Material::Lambertian { | ||
albedo: DVec3::new(0.12, 0.45, 0.15).into(), | ||
}; | ||
let light = Material::DiffuseLight( | ||
DVec3::new(15., 15., 15.).into(), | ||
); | ||
|
||
world.push(Quad::new( | ||
DVec3::new(555., 0., 0.), | ||
DVec3::new(0., 555., 0.), | ||
DVec3::new(0., 0., 555.), | ||
green, | ||
)); | ||
world.push(Quad::new( | ||
DVec3::new(0., 0., 0.), | ||
DVec3::new(0., 555., 0.), | ||
DVec3::new(0., 0., 555.), | ||
red, | ||
)); | ||
world.push(Quad::new( | ||
DVec3::new(343., 554., 332.), | ||
DVec3::new(-130., 0., 0.), | ||
DVec3::new(0., 0., -105.), | ||
light, | ||
)); | ||
world.push(Quad::new( | ||
DVec3::new(0., 0., 0.), | ||
DVec3::new(555., 0., 0.), | ||
DVec3::new(0., 0., 555.), | ||
white.clone(), | ||
)); | ||
world.push(Quad::new( | ||
DVec3::new(555., 555., 555.), | ||
DVec3::new(-555., 0., 0.), | ||
DVec3::new(0., 0., -555.), | ||
white.clone(), | ||
)); | ||
world.push(Quad::new( | ||
DVec3::new(0., 0., 555.), | ||
DVec3::new(555., 0., 0.), | ||
DVec3::new(0., 555., 0.), | ||
white, | ||
)); | ||
|
||
let camera = Camera::init() | ||
.image_width(800) | ||
.aspect_ratio(1.) | ||
.look_from(DVec3::new(278., 278., -800.)) | ||
.look_at(DVec3::new(278., 278., 0.)) | ||
.vup(DVec3::Y) | ||
.focus_dist(10.0) | ||
.defocus_angle(0.0) | ||
.samples_per_pixel(500) | ||
.max_depth(50) | ||
.vfov(40.) | ||
.background(DVec3::ZERO) | ||
.build(); | ||
|
||
let filename = Path::new(file!()) | ||
.file_name() | ||
.and_then(|s| s.to_str()) | ||
.unwrap() | ||
.trim_end_matches(".rs"); | ||
camera.render_to_disk(filename, world)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use glam::DVec3; | ||
use noise::Perlin; | ||
use raytracer::{ | ||
camera::Camera, | ||
material::Material, | ||
shapes::{quad::Quad, sphere::Sphere, Shapes}, | ||
textures::Texture, | ||
}; | ||
use std::{io, path::Path}; | ||
|
||
fn main() -> io::Result<()> { | ||
let mut world = vec![]; | ||
|
||
// let perlin = Perlin::new(1); | ||
// let pertext = Texture::PerlinNoise(perlin, 2.); | ||
let perlin = Perlin::new(1); | ||
let pertext = Texture::Turbulence(perlin); | ||
|
||
world.push(Shapes::Sphere(Sphere::new( | ||
DVec3::new(0., -1000., 0.), | ||
1000., | ||
Material::Lambertian { | ||
albedo: pertext.clone(), | ||
}, | ||
))); | ||
world.push(Shapes::Sphere(Sphere::new( | ||
DVec3::new(0., 2., 0.), | ||
2., | ||
Material::Lambertian { albedo: pertext }, | ||
))); | ||
|
||
let difflight = Material::DiffuseLight( | ||
DVec3::new(4., 4., 4.).into(), | ||
); | ||
|
||
// Quads | ||
world.push(Shapes::Quad(Quad::new( | ||
DVec3::new(3., 1., -2.), | ||
DVec3::new(2., 0., 0.), | ||
DVec3::new(0., 2., 0.), | ||
difflight, | ||
))); | ||
|
||
let camera = Camera::init() | ||
.image_width(800) | ||
.aspect_ratio(16. / 9.) | ||
.look_from(DVec3::new(23., 3., 6.)) | ||
.look_at(DVec3::new(0., 2., 0.)) | ||
.vup(DVec3::Y) | ||
.focus_dist(10.0) | ||
.defocus_angle(0.0) | ||
.samples_per_pixel(500) | ||
.max_depth(50) | ||
.vfov(20.) | ||
.background(DVec3::ZERO) | ||
.build(); | ||
|
||
let filename = Path::new(file!()) | ||
.file_name() | ||
.and_then(|s| s.to_str()) | ||
.unwrap() | ||
.trim_end_matches(".rs"); | ||
camera.render_to_disk(filename, world)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters