summaryrefslogtreecommitdiff
path: root/racer-tracer/src/util.rs
diff options
context:
space:
mode:
authorSakarias Johansson <sakarias.johansson@goodbyekansas.com>2023-03-13 22:00:44 +0100
committerSakarias Johansson <sakarias.johansson@goodbyekansas.com>2023-03-13 22:23:18 +0100
commitf19c8cc40c5caf8abb4f04aaf9f91ec3a8c1ccbc (patch)
treea54a074ece82eafd8793cd0fb68a1b938286c923 /racer-tracer/src/util.rs
parent3cabf77da8b9681ed9683fe92c23054d6f49d848 (diff)
downloadracer-tracer-f19c8cc40c5caf8abb4f04aaf9f91ec3a8c1ccbc.tar.gz
racer-tracer-f19c8cc40c5caf8abb4f04aaf9f91ec3a8c1ccbc.tar.xz
racer-tracer-f19c8cc40c5caf8abb4f04aaf9f91ec3a8c1ccbc.zip
📸 Add Camera defocus blur + Other
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`.
Diffstat (limited to 'racer-tracer/src/util.rs')
-rw-r--r--racer-tracer/src/util.rs20
1 files changed, 18 insertions, 2 deletions
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::<f64>()
}
-// 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;
+ }
+}