From f19c8cc40c5caf8abb4f04aaf9f91ec3a8c1ccbc Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Mon, 13 Mar 2023 22:00:44 +0100 Subject: =?UTF-8?q?=F0=9F=93=B8=20Add=20Camera=20defocus=20blur=20+=20Othe?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Just wanted to add defocus blur but ended up changing a bunch of other this as well. - Moved scenes to a separate folder. - Updated readme with more pretty images. - Add interface for loading scenes. There is currently one for yaml and another if you want a slightly random scene. - Add image action to decide what to do with the final image once its rendered. Currently supports just showing the buffer until you press the render buffer again and saving the image as `png`. - When you use nix shell you will be dropped in the proper folder so you can just do cargo build etc without having to do `cd`. --- racer-tracer/src/util.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'racer-tracer/src/util.rs') diff --git a/racer-tracer/src/util.rs b/racer-tracer/src/util.rs index 2f04567..5fb2d36 100644 --- a/racer-tracer/src/util.rs +++ b/racer-tracer/src/util.rs @@ -1,6 +1,7 @@ use rand::Rng; -// For later use +use crate::vec3::Vec3; + pub fn degrees_to_radians(degrees: f64) -> f64 { degrees * std::f64::consts::PI / 180.0 } @@ -10,8 +11,23 @@ pub fn random_double() -> f64 { rng.gen::() } -// For later use pub fn random_double_range(min: f64, max: f64) -> f64 { let mut rng = rand::thread_rng(); rng.gen_range(min..max) } + +pub fn random_in_unit_disk() -> Vec3 { + // TODO: This feels not nice + loop { + let p = Vec3::new( + random_double_range(-1.0, 1.0), + random_double_range(-1.0, 1.0), + 0.0, + ); + if p.length_squared() >= 1.0 { + continue; + } + + return p; + } +} -- cgit v1.2.3