This commit is contained in:
2026-09-13 15:18:05 +02:00
parent 92e77564dd
commit 5c6bf98f3e
13 changed files with 25 additions and 20 deletions

View File

@@ -1,4 +1,3 @@
use crate::{ray::Ray, util::deg_to_rad, vec3::Vec3}; use crate::{ray::Ray, util::deg_to_rad, vec3::Vec3};
#[derive(Debug)] #[derive(Debug)]

View File

@@ -1,11 +1,11 @@
#![feature(core_float_math)] #![feature(core_float_math)]
mod util;
mod camera; mod camera;
mod objects; mod objects;
mod ray; mod ray;
mod raytracer; mod raytracer;
mod scenes; mod scenes;
mod util;
mod vec3; mod vec3;
use std::{env, fs}; use std::{env, fs};

View File

@@ -1,6 +1,6 @@
pub mod colour_source;
pub mod dielectric; pub mod dielectric;
pub mod lambertian; pub mod lambertian;
pub mod normal; pub mod normal;
pub mod traits;
pub mod texture; pub mod texture;
pub mod colour_source; pub mod traits;

View File

@@ -1,10 +1,7 @@
use image::{DynamicImage, ImageReader}; use image::{DynamicImage, ImageReader};
use log::trace; use log::trace;
use crate::{ use crate::{objects::hit::Hit, vec3::Vec3};
objects::hit::Hit,
vec3::Vec3,
};
#[derive(Debug)] #[derive(Debug)]
pub struct Texture { pub struct Texture {
@@ -47,7 +44,7 @@ impl Texture {
} }
fn _idx(&self, u: f32, v: f32) -> usize { fn _idx(&self, u: f32, v: f32) -> usize {
let x: usize = (u * ((self.width - 1) as f32)) as usize; let x: usize = (u * ((self.width - 1) as f32)) as usize;
let y: usize = (v * ((self.height - 1) as f32)) as usize; let y: usize = (v * ((self.height - 1) as f32)) as usize;
y * self.width as usize + x y * self.width as usize + x

View File

@@ -1,6 +1,6 @@
use crate::{objects::hit::Hit, ray::Ray, vec3::Colour}; use crate::{objects::hit::Hit, ray::Ray, vec3::Colour};
use std::fmt::Debug; use std::fmt::Debug;
pub trait Material: Debug + Send + Sync{ pub trait Material: Debug + Send + Sync {
fn scatter(&self, hit: &Hit, ray: &Ray) -> Option<(Option<Ray>, Colour)>; fn scatter(&self, hit: &Hit, ray: &Ray) -> Option<(Option<Ray>, Colour)>;
} }

View File

@@ -0,0 +1 @@

View File

@@ -3,11 +3,11 @@ use std::f32::consts::PI;
use std::fmt::{self, Debug}; use std::fmt::{self, Debug};
use std::sync::Arc; use std::sync::Arc;
use crate::Vec3;
use crate::objects::hit::Hit; use crate::objects::hit::Hit;
use crate::objects::materials::traits::Material; use crate::objects::materials::traits::Material;
use crate::objects::traits::Hittable; use crate::objects::traits::Hittable;
use crate::ray::Ray; use crate::ray::Ray;
use crate::Vec3;
pub struct Sphere { pub struct Sphere {
center: Vec3, center: Vec3,

View File

@@ -1,10 +1,10 @@
use std::fmt::Debug; use std::fmt::Debug;
use crate::Ray;
use crate::objects::hit::Hit; use crate::objects::hit::Hit;
use crate::vec3::Vec3; use crate::vec3::Vec3;
use crate::Ray;
pub trait Hittable: Debug + Send + Sync { pub trait Hittable: Debug + Send + Sync {
fn to_uv(&self, point: &Vec3) -> Vec3; fn to_uv(&self, point: &Vec3) -> Vec3;
fn hit(&self, r: &Ray) -> Option<Hit>; fn hit(&self, r: &Ray) -> Option<Hit>;
} }

View File

@@ -1,4 +1,4 @@
use image::{ExtendedColorType, ImageEncoder, codecs::png::PngEncoder}; use image::{codecs::png::PngEncoder, ExtendedColorType, ImageEncoder};
use log::{error, info, trace}; use log::{error, info, trace};
use rayon::iter::IntoParallelIterator; use rayon::iter::IntoParallelIterator;
use rayon::prelude::*; use rayon::prelude::*;

View File

@@ -1,4 +1,4 @@
pub mod raw_camera;
pub mod material_def;
pub mod hittable_def; pub mod hittable_def;
pub mod material_def;
pub mod raw_camera;
pub mod scene; pub mod scene;

View File

@@ -2,8 +2,13 @@ use std::sync::Arc;
use serde::Deserialize; use serde::Deserialize;
use crate::objects::materials::{dielectric::Dielectric, lambertian::{Lambertian, Metal}, normal::Normal, texture::Texture, traits::Material}; use crate::objects::materials::{
dielectric::Dielectric,
lambertian::{Lambertian, Metal},
normal::Normal,
texture::Texture,
traits::Material,
};
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")] #[serde(tag = "type", rename_all = "lowercase")]

View File

@@ -3,4 +3,3 @@ use std::f32::consts::PI;
pub(crate) fn deg_to_rad(deg: f32) -> f32 { pub(crate) fn deg_to_rad(deg: f32) -> f32 {
deg * PI / 180. deg * PI / 180.
} }

View File

@@ -67,7 +67,11 @@ impl Vec3 {
pub fn random_unit_hemisphere(n: &Self) -> Self { pub fn random_unit_hemisphere(n: &Self) -> Self {
let v = Self::random_unit(); let v = Self::random_unit();
if n.dot(&v) > 0.0 { v } else { -v } if n.dot(&v) > 0.0 {
v
} else {
-v
}
} }
pub fn x(&self) -> &f32 { pub fn x(&self) -> &f32 {