Compare commits
2 commits
ca7300a52b
...
48bbd5f2f0
Author | SHA1 | Date | |
---|---|---|---|
48bbd5f2f0 | |||
6576d38eaa |
4 changed files with 22 additions and 152 deletions
124
Cargo.lock
generated
124
Cargo.lock
generated
|
@ -59,51 +59,6 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
"lazy_static",
|
||||
"memoffset",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deflate"
|
||||
version = "1.0.0"
|
||||
|
@ -113,12 +68,6 @@ dependencies = [
|
|||
"adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.6"
|
||||
|
@ -130,15 +79,6 @@ dependencies = [
|
|||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "image"
|
||||
version = "0.24.2"
|
||||
|
@ -157,30 +97,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "jpeg-decoder"
|
||||
version = "0.2.6"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9478aa10f73e7528198d75109c8be5cd7d15fb530238040148d5f9a22d4c5b3b"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
checksum = "be7ef4b99870f0c9f2fc2f20dbef72707e2bcca675bb9196734cf433e999b0c5"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.126"
|
||||
version = "0.2.125"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
|
@ -232,16 +157,6 @@ dependencies = [
|
|||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.17.5"
|
||||
|
@ -290,45 +205,14 @@ dependencies = [
|
|||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"crossbeam-deque",
|
||||
"either",
|
||||
"rayon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f"
|
||||
dependencies = [
|
||||
"crossbeam-channel",
|
||||
"crossbeam-deque",
|
||||
"crossbeam-utils",
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "renderer"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"image",
|
||||
"rand",
|
||||
"rayon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
|
|
|
@ -8,4 +8,3 @@ edition = "2021"
|
|||
[dependencies]
|
||||
image = { version = "0.24.2", default-features = false, features = ["jpeg", "png", "pnm"] }
|
||||
rand = "0.8.5"
|
||||
rayon = "1.5.2"
|
|
@ -1,16 +1,15 @@
|
|||
use super::HitRecord;
|
||||
use super::Hittable;
|
||||
use super::Ray;
|
||||
use super::Arc;
|
||||
|
||||
pub struct HittableList {
|
||||
objects: Vec<Arc<dyn Hittable>>,
|
||||
objects: Vec<Box<dyn Hittable>>,
|
||||
}
|
||||
|
||||
impl HittableList {
|
||||
pub fn new() -> Self {
|
||||
HittableList {
|
||||
objects: Vec::<Arc<dyn Hittable>>::new(),
|
||||
objects: Vec::<Box<dyn Hittable>>::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,16 +17,10 @@ impl HittableList {
|
|||
self.objects.clear();
|
||||
}
|
||||
|
||||
pub fn add(&mut self, obj: Arc<dyn Hittable>) {
|
||||
pub fn add(&mut self, obj: Box<dyn Hittable>) {
|
||||
self.objects.push(obj);
|
||||
}
|
||||
|
||||
pub fn clone(&self) -> Self {
|
||||
HittableList {
|
||||
objects : self.objects.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hit(&self, r: &Ray, t_min: f64, t_max: f64, rec: &mut HitRecord) -> bool {
|
||||
let mut hit_anything = false;
|
||||
let mut closest_so_far = t_max;
|
||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -9,7 +9,6 @@ mod utility;
|
|||
mod vec3;
|
||||
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
//use std::fs::File;
|
||||
//use std::io::BufWriter;
|
||||
//use std::io::Write;
|
||||
|
@ -17,7 +16,6 @@ use camera::Camera;
|
|||
use hittable::{HitRecord, Hittable, Sphere};
|
||||
use hittable_list::HittableList;
|
||||
use image::{Rgb, RgbImage};
|
||||
use rayon::prelude::*;
|
||||
use ray::Ray;
|
||||
use vec3::{Color, Point3, Vec3};
|
||||
|
||||
|
@ -44,23 +42,23 @@ fn main() {
|
|||
|
||||
// World
|
||||
let mut world = HittableList::new();
|
||||
world.add(Arc::<Sphere>::new(Sphere::new(
|
||||
world.add(Box::<Sphere>::new(Sphere::new(
|
||||
Point3::new(0.0, 0.0, -1.0),
|
||||
0.5,
|
||||
)));
|
||||
world.add(Arc::<Sphere>::new(Sphere::new(
|
||||
world.add(Box::<Sphere>::new(Sphere::new(
|
||||
Point3::new(0.0, -100.5, -150.0),
|
||||
100.0,
|
||||
)));
|
||||
world.add(Arc::<Sphere>::new(Sphere::new(
|
||||
world.add(Box::<Sphere>::new(Sphere::new(
|
||||
Point3::new(1.0, 0.0, -1.5),
|
||||
0.3,
|
||||
)));
|
||||
world.add(Arc::<Sphere>::new(Sphere::new(
|
||||
world.add(Box::<Sphere>::new(Sphere::new(
|
||||
Point3::new(1.0, 1.1, -1.5),
|
||||
0.3,
|
||||
)));
|
||||
world.add(Arc::<Sphere>::new(Sphere::new(
|
||||
world.add(Box::<Sphere>::new(Sphere::new(
|
||||
Point3::new(-1.0, 1.1, -1.5),
|
||||
0.3,
|
||||
)));
|
||||
|
@ -68,7 +66,7 @@ fn main() {
|
|||
/*
|
||||
for i in -15..15 {
|
||||
for j in -15..15 {
|
||||
world.add(Arc::<Sphere>::new(Sphere::new(Point3::new(j as f64/6.0 as f64, i as f64/6.0 as f64, -1.5), 0.05)));
|
||||
world.add(Box::<Sphere>::new(Sphere::new(Point3::new(j as f64/6.0 as f64, i as f64/6.0 as f64, -1.5), 0.05)));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
@ -87,23 +85,15 @@ fn main() {
|
|||
//let mut file = BufWriter::new(File::create(default_file).unwrap());
|
||||
//writeln!(&mut file, "P3\n{image_width} {image_height}\n255\n").unwrap();
|
||||
|
||||
//TODO: // world in vec umwandeln
|
||||
|
||||
for j in (0..image_height).rev() {
|
||||
eprint!("\rScanlines remaining: {j:5}");
|
||||
(0..image_width).into_par_iter().for_each(|i| pixel_color_calc(&mut image, &cam, &world.clone(), j, i, image_width, image_height, samples_per_pixel));
|
||||
}
|
||||
image.save(default_file).unwrap();
|
||||
eprintln!("\nDone!");
|
||||
}
|
||||
|
||||
fn pixel_color_calc(image: &mut RgbImage, cam: &Camera, world: &HittableList, j: u32, i: u32, image_width: u32, image_height: u32, samples_per_pixel: u32) {
|
||||
let mut pixel_color = Color::new(0.0, 0.0, 0.0);
|
||||
for i in 0..image_width {
|
||||
let mut pixel_color = Color::new(0.0, 0.0, 0.0);
|
||||
for _ in 0..samples_per_pixel {
|
||||
let u = (i as f64 + utility::random_f64()) / (image_width - 1) as f64;
|
||||
let v = (j as f64 + utility::random_f64()) / (image_height - 1) as f64;
|
||||
let r = cam.get_ray(u, v);
|
||||
pixel_color += ray_color(&r, &world);
|
||||
pixel_color += ray_color(&r, &mut world);
|
||||
}
|
||||
|
||||
//color::write_color(&mut file, &pixel_color);
|
||||
|
@ -114,4 +104,8 @@ fn pixel_color_calc(image: &mut RgbImage, cam: &Camera, world: &HittableList, j:
|
|||
image_height - j - 1,
|
||||
samples_per_pixel,
|
||||
);
|
||||
}
|
||||
}
|
||||
image.save(default_file).unwrap();
|
||||
eprintln!("\nDone!");
|
||||
}
|
Loading…
Reference in a new issue