ft (wip): textures

This commit is contained in:
2026-05-12 18:20:06 +02:00
parent 383f739808
commit 6a1e50fb7a
13 changed files with 222 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{f32::consts::PI, sync::Arc};
use crate::{
objects::{materials::traits::Material, traits::Hittable},
@@ -45,8 +45,27 @@ impl Hittable for Circle {
let p = r.at(t);
if (p - self.center).length() < self.radius {
return Some(Hit::new(t, p, self.normal, self.material.clone(), self.normal.dot(&r.dir()) < 0.));
let uv = self.to_uv(&p);
return Some(Hit::new(
t,
p,
self.normal,
self.material.clone(),
self.normal.dot(&r.dir()) < 0.,
*uv.x(),
*uv.y(),
));
}
None
}
fn to_uv(&self, point: &Vec3) -> Vec3 {
let p = *point - self.center;
// TODO: add rotated texture support
return Vec3::new(
0.5 + p.y().atan2(*p.x()) / (2. * PI),
1. - (p.z() / self.radius).acos() / PI,
0.0,
);
}
}