ft (wip): texture/material overhaul

This commit is contained in:
2026-09-13 11:58:25 +02:00
parent 2800d911c3
commit 968c232388
11 changed files with 89 additions and 33 deletions

View File

@@ -2,16 +2,10 @@ use image::{DynamicImage, ImageReader};
use log::trace;
use crate::{
objects::{hit::Hit, materials::traits::Material},
ray::Ray,
objects::hit::Hit,
vec3::Vec3,
};
// TODO: overhaul texture implementation so we can support textures for arbitrary materials.
// Basically remove this struct, and instead make lambertian/metal/dielectric/take either a texture
// or a flat colour
// I think we can use an enum ColourSource with a function to fetch a specific colour depending on
// if we have a texture/flat colour. and yeah.
#[derive(Debug)]
pub struct Texture {
source: DynamicImage,
@@ -69,12 +63,9 @@ impl Texture {
b[self.stride * idx + 1],
)
}
}
impl Material for Texture {
fn scatter(&self, hit: &Hit, _ray: &Ray) -> Option<(Option<Ray>, Vec3)> {
pub fn colour_at(&self, hit: &Hit) -> Vec3 {
let (u, v) = hit.uv();
let col = self._at(u, 1. - v);
Some((None, col))
self._at(u, 1. - v)
}
}