Compare commits

...

2 Commits

Author SHA1 Message Date
71985a6c34 fx: cmt 2026-05-13 14:17:53 +02:00
b4b214ebf7 fx: debug statement 2026-05-13 13:52:57 +02:00
3 changed files with 34 additions and 19 deletions

View File

@@ -6,27 +6,28 @@
"camera": {
"anti_alias_rate": 2,
"fov": 50.0,
"look_from": [-2, 4, 5],
"look_at": [-2, 0.0, 0.0],
"vup": [0.0, 1.0, 0.0], "defocus_angle": 0, "focus_dist": 15.68
"look_from": [-3, 4, 10],
"look_at": [-3, 0.0, -10.0],
"vup": [0.0, 1.0, 0.0],
"defocus_angle": 0,
"focus_dist": 15.68
},
"materials": [
{ "type": "lambertian", "albedo": [0.2, 0.2, 0.2], "prob": 0.8 },
{ "type": "lambertian", "albedo": [0.9, 0.9, 0.0], "prob": 1.0, "fuzz": 0.1 },
{ "type": "dielectric", "refraction_index": 1.5},
{ "type": "normal"},
{"type": "texture", "source": "./textures/earthmap1k.png"},
{"type": "texture", "source": "./textures/yellow.png"}
{"type": "texture", "source": "./textures/bluegrid.png"}
],
"objects": [
{ "type": "sphere", "center": [0.0, 0.0, -1.2], "radius": 0.9, "material": 5},
{ "type": "sphere", "center": [-2, 0, -1], "radius": 0.8, "material": 4},
{ "type": "triangle", "p1": [0, 0, -4], "p2": [4, 0, -4], "p3": [2, 2, -4], "material": 5},
{ "type": "triangle", "p1": [-2, 2, -4], "p2": [2, 2, -4], "p3": [0, 4, -4], "material": 4},
{ "type": "sphere", "center": [0.0, 0.0, -1.2], "radius": 0.9, "material": 2},
{ "type": "sphere", "center": [-2, 0, -1], "radius": 0.8, "material": 1},
{ "type": "triangle", "p1": [0, 0, -4], "p2": [4, 0, -4], "p3": [2, 2, -4], "material": 2},
{ "type": "triangle", "p1": [-2, 2, -4], "p2": [2, 2, -4], "p3": [0, 4, -4], "material": 1},
{ "type": "quad", "p1": [-20, -1, -20], "p2": [20, -1, -20], "p3": [20, 20, -20], "p4": [-20, 20, -20], "material": 0},
{ "type": "quad", "p1": [-20, -1, 20], "p2": [-20, -1, -20], "p3": [-20, 20, -20], "p4": [-20, 20, 20], "material": 0},
{ "type": "quad", "p1": [-20, -1, 20], "p2": [20, -1, 20], "p3": [20, -1, -20], "p4": [-20, -1, -20], "material": 0},
{ "type": "quad", "p1": [20, -1, 20], "p2": [20, -1, -20], "p3": [20, 20, -20], "p4": [20, 20, 20], "material": 0}
{ "type": "quad", "p1": [20, -1, 20], "p2": [20, -1, -20], "p3": [20, 20, -20], "p4": [20, 20, 20], "material": 0},
{ "type": "quad", "p1": [-4, 3, -4], "p2": [-1, 3, -4], "p3": [-1, 6, -4], "p4": [-4, 6, -4], "material": 1},
{ "type": "quad", "p1": [-8, 3, -4], "p2": [-5, 3, -4], "p3": [-5, 6, -4], "p4": [-8, 6, -4], "material": 2}
]
}

View File

@@ -1,5 +1,5 @@
use image::{DynamicImage, ImageReader};
use log::info;
use log::trace;
use crate::{
objects::{hit::Hit, materials::traits::Material},
@@ -18,8 +18,15 @@ pub struct Texture {
impl Texture {
pub fn new(texture: &str) -> Self {
let img = ImageReader::open(texture).unwrap().decode().unwrap(); // FIXME: unwraps
info!("{} * {} = {} bytes", img.width(), img.height(), img.as_bytes().len());
let stride = match img.color() { // TODO: support other types of image
trace!(
"texture '{}' is {} by {} pixels, with {} bytes total",
texture,
img.width(),
img.height(),
img.as_bytes().len()
);
let stride = match img.color() {
// TODO: support other types of image
image::ColorType::L8 => todo!(),
image::ColorType::La8 => todo!(),
image::ColorType::Rgb8 => 3,
@@ -48,10 +55,14 @@ impl Texture {
}
fn _at(&self, u: f32, v: f32) -> Vec3 {
let b = self.source.as_bytes();
let b = self.source.as_bytes();
let idx = self._idx(u, v);
Vec3::from_u8(b[self.stride * idx], b[self.stride * idx + 2], b[self.stride * idx + 1])
Vec3::from_u8(
b[self.stride * idx],
b[self.stride * idx + 2],
b[self.stride * idx + 1],
)
}
}

View File

@@ -57,9 +57,10 @@ impl Debug for Quad {
}
}
// FIXME: texture mapping does not work properly for quads
impl Hittable for Quad {
fn hit(&self, r: &Ray) -> Option<Hit> {
Quad::hit(
let hit = Quad::hit(
self.p1,
self.p2,
self.p3,
@@ -67,7 +68,9 @@ impl Hittable for Quad {
self.material.clone(),
self.normal,
r,
)
);
return hit
}
fn to_uv(&self, point: &Vec3) -> Vec3 {