Compare commits

...

2 Commits

Author SHA1 Message Date
fa02334c78 Merge branch 'master' of https://git.z.xinu.tv/wathiede/raytracers
Some checks failed
continuous-integration/drone/push Build is failing
2019-10-12 16:16:38 -07:00
ccffa690ba Add pixel counting. 2019-10-12 16:16:26 -07:00

View File

@ -1,4 +1,3 @@
use std;
use std::fmt; use std::fmt;
use std::io; use std::io;
use std::io::Write; use std::io::Write;
@ -6,12 +5,15 @@ use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::str; use std::str;
use std::sync; use std::sync;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::sync::mpsc::sync_channel; use std::sync::mpsc::sync_channel;
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use std::sync::mpsc::SyncSender; use std::sync::mpsc::SyncSender;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
use std::thread; use std::thread;
use std::time;
use image; use image;
use image::RgbImage; use image::RgbImage;
@ -245,6 +247,9 @@ enum Response {
pixels: Vec<Vec3>, pixels: Vec<Vec3>,
}, },
} }
static PIXEL_COUNT: AtomicUsize = AtomicUsize::new(0);
fn render_pixel(scene: &Scene, x: usize, y: usize) -> Vec3 { fn render_pixel(scene: &Scene, x: usize, y: usize) -> Vec3 {
let mut pixel: Vec3 = Default::default(); let mut pixel: Vec3 = Default::default();
for _ in 0..scene.subsamples { for _ in 0..scene.subsamples {
@ -253,6 +258,7 @@ fn render_pixel(scene: &Scene, x: usize, y: usize) -> Vec3 {
pixel = pixel / scene.subsamples as f32; pixel = pixel / scene.subsamples as f32;
// Gamma correct, use gamma 2 correction, which is 1/gamma where gamma=2 which is 1/2 or // Gamma correct, use gamma 2 correction, which is 1/gamma where gamma=2 which is 1/2 or
// sqrt. // sqrt.
PIXEL_COUNT.fetch_add(1, Ordering::SeqCst);
Vec3::new(pixel[0].sqrt(), pixel[1].sqrt(), pixel[2].sqrt()) Vec3::new(pixel[0].sqrt(), pixel[1].sqrt(), pixel[2].sqrt())
} }
@ -322,7 +328,29 @@ pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::i
drop(pixel_req_tx); drop(pixel_req_tx);
}); });
thread::spawn(move || {
let mut last_time = time::Instant::now();
let mut last_pixel_count = PIXEL_COUNT.load(Ordering::SeqCst);
loop {
let sleep_time = time::Duration::from_secs(1);
thread::sleep(sleep_time);
let now = time::Instant::now();
let mut pixel_count = PIXEL_COUNT.load(Ordering::SeqCst);
let time_diff = now - last_time;
let pixel_diff = pixel_count - last_pixel_count;
info!(
"Woke up {}s passed, {} pixels rendered {} p/s",
time_diff.as_secs_f64(),
pixel_count,
pixel_diff as u64 / time_diff.as_secs()
);
last_time = now;
last_pixel_count = pixel_count;
}
});
println!("Rendering with {} subsamples", scene.subsamples); println!("Rendering with {} subsamples", scene.subsamples);
info!("PIXEL_COUNT {} ", PIXEL_COUNT.load(Ordering::SeqCst));
let mut img = RgbImage::new(scene.width as u32, scene.height as u32); let mut img = RgbImage::new(scene.width as u32, scene.height as u32);
let total = scene.width * scene.height; let total = scene.width * scene.height;
let mut cur_pixel = 0; let mut cur_pixel = 0;