Fixed selective antialiasing
This commit is contained in:
parent
a830e47ae9
commit
64f46fb251
1 changed files with 18 additions and 21 deletions
39
src/main.rs
39
src/main.rs
|
@ -69,9 +69,9 @@ fn main() {
|
|||
let aspect_ratio = 10.0 / 7.5; //16.0 / 9.0;
|
||||
let image_width = 400;
|
||||
let image_height = (image_width as f64 / aspect_ratio) as u32;
|
||||
let samples_per_pixel = 50_u32;
|
||||
let samples_per_pixel = 100_u32;
|
||||
let max_depth = 50;
|
||||
let antialiasing_threshold = 0.3; // at what diff between two colors will a pixel be antialiased
|
||||
let antialiasing_threshold = 0.2; // at what diff between two colors will a pixel be antialiased
|
||||
|
||||
let vfov = 40.0;
|
||||
let lookfrom = Point3::new(2.0, 0.8, 3.0);
|
||||
|
@ -81,7 +81,7 @@ fn main() {
|
|||
let aperture = 0.0; // disable depth of field
|
||||
|
||||
// limit rayon multithreading thread count
|
||||
let thread_count = 4; // if 0, for each logical cpu core a thread wil be created
|
||||
let thread_count = 0; // if 0, for each logical cpu core a thread wil be created
|
||||
if thread_count > 0 {
|
||||
env::set_var("RAYON_NUM_THREADS", thread_count.to_string());
|
||||
}
|
||||
|
@ -196,21 +196,18 @@ fn main() {
|
|||
for i in 0..image_width {
|
||||
if samples_per_pixel > 0 && antialiasing[j as usize][i as usize] {
|
||||
let mut pixel_color = Color::null();
|
||||
|
||||
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);
|
||||
dbg!(ray_color(&r, &world, max_depth));
|
||||
pixel_color += ray_color(&r, &world, max_depth);
|
||||
let v = (image_height as f64- 1.0 -(j as f64 + utility::random_f64())) / (image_height - 1) as f64;
|
||||
let new_pixel_color = ray_color(&cam.get_ray(u, v), &world, max_depth);
|
||||
pixel_color += new_pixel_color;
|
||||
}
|
||||
// Correct antialiasing gamma
|
||||
pixel_color = Color::new(
|
||||
pixel_color.x() / samples_per_pixel as f64,
|
||||
pixel_color.y() / samples_per_pixel as f64,
|
||||
pixel_color.z() / samples_per_pixel as f64,
|
||||
);
|
||||
println!("x: {}, y: {}, z: {}", pixel_color.x(), pixel_color.y(), pixel_color.z());
|
||||
colors.push(pixel_color);
|
||||
let fin_color = (1.0/samples_per_pixel as f64) * pixel_color;
|
||||
//println!("x: {}, y: {}, z: {}", pixel_color.x(), pixel_color.y(), pixel_color.z());
|
||||
|
||||
colors.push(fin_color);
|
||||
} else {
|
||||
colors.push(color_lines[j as usize][i as usize]);
|
||||
}
|
||||
|
@ -259,20 +256,20 @@ fn from_obj(path: &str) -> HittableList {
|
|||
14.0 / 255.0,
|
||||
)));
|
||||
world.add(Box::<Sphere>::new(Sphere::new(
|
||||
Point3::new(0.0, -5005.0, 0.0),
|
||||
Point3::new(-500.0, -5005.0, -500.0),
|
||||
5000.0,
|
||||
material_ground.clone(),
|
||||
)));
|
||||
*/
|
||||
|
||||
//let material = Arc::new(Lambertian::new(&Color::new(
|
||||
// 77.0 / 255.0,
|
||||
// 77.0 / 255.0,
|
||||
// 118.0 / 255.0,
|
||||
//)));
|
||||
let material = Arc::new(Lambertian::new(&Color::new(
|
||||
77.0 / 255.0,
|
||||
77.0 / 255.0,
|
||||
118.0 / 255.0,
|
||||
)));
|
||||
//let material = Arc::new(Dielectric::new(2.0));
|
||||
//let material = Arc::new(Metal::new(&Color::new(0.9, 0.9, 0.7), 1.0));
|
||||
let material = Arc::new(Rainbow::new());
|
||||
//let material = Arc::new(Rainbow::new());
|
||||
|
||||
let cornell_box = tobj::load_obj(path, &tobj::OFFLINE_RENDERING_LOAD_OPTIONS);
|
||||
let (models, materials) = cornell_box.expect("Failed to load OBJ file");
|
||||
|
|
Loading…
Reference in a new issue