ft: 13: optional defocus blur

This commit is contained in:
2026-04-29 01:17:00 +02:00
parent 076bcc7155
commit 2358f8e093
6 changed files with 111 additions and 14 deletions

View File

@@ -17,8 +17,8 @@ pub struct Vec3 {
pub type Colour = Vec3;
impl Vec3 {
pub fn new(r: f32, g: f32, b: f32) -> Self {
Self { x: r, y: g, z: b }
pub fn new(x: f32, y: f32, z: f32) -> Self {
Self { x, y, z }
}
pub fn nil() -> Self {
@@ -47,6 +47,16 @@ impl Vec3 {
}
}
pub fn random_in_unit_disk() -> Self {
loop {
let mut p = Vec3::random();
p.z = 0.;
if p.length_squared() < 1. {
return p;
}
}
}
pub fn random_unit_hemisphere(n: &Self) -> Self {
let v = Self::random_unit();
if n.dot(&v) > 0.0 {
@@ -340,6 +350,19 @@ impl Mul<&Vec3> for f32 {
}
}
impl Mul<Vec3> for &f32 {
type Output = Vec3;
fn mul(self, rhs: Vec3) -> Self::Output {
Vec3 {
x: rhs.x * self,
y: rhs.y * self,
z: rhs.z * self,
}
}
}
impl MulAssign<Vec3> for Vec3 {
fn mul_assign(&mut self, rhs: Self) {
*self = Self {