Compare commits
0
Commits
No files matched your search
+2
-2
@@ -2,10 +2,10 @@
|
|||||||
"camera": {
|
"camera": {
|
||||||
"image_width": 1920,
|
"image_width": 1920,
|
||||||
"image_height": 1080,
|
"image_height": 1080,
|
||||||
"anti_alias_rate": 23,
|
"anti_alias_rate": 1,
|
||||||
"max_depth": 50,
|
"max_depth": 50,
|
||||||
"fov": 90.0,
|
"fov": 90.0,
|
||||||
"look_from": [15, 4, 15],
|
"look_from": [0, 4, 15],
|
||||||
"look_at": [0.0, 0.0, 0.0],
|
"look_at": [0.0, 0.0, 0.0],
|
||||||
"vup": [0.0, 1.0, 0.0],
|
"vup": [0.0, 1.0, 0.0],
|
||||||
"defocus_angle": 0,
|
"defocus_angle": 0,
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
use std::{f32::consts::PI, sync::Arc};
|
use std::{f32::consts::PI, sync::Arc};
|
||||||
|
|
||||||
use log::info;
|
use log::{info, warn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{hit::Hit, traits::Hittable},
|
objects::{hit::Hit, traits::Hittable},
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ impl Hittable for Cube {
|
|||||||
Hit::hit_list(&self.faces, r)
|
Hit::hit_list(&self.faces, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normal_at(&self, _p: &Vec3) -> Vec3 {
|
fn normal_at(&self, p: &Vec3) -> Vec3 {
|
||||||
// TODO: normal calc for cube
|
// TODO: normal calc for cube
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use serde::Deserialize;
|
|||||||
use crate::{
|
use crate::{
|
||||||
objects::{hit::Hit, materials::traits::Material},
|
objects::{hit::Hit, materials::traits::Material},
|
||||||
ray::Ray,
|
ray::Ray,
|
||||||
vec3::Colour,
|
vec3::{Colour, Vec3},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|||||||
+10
-8
@@ -4,6 +4,7 @@ use crate::objects::traits::Hittable;
|
|||||||
use crate::objects::triangle::Triangle;
|
use crate::objects::triangle::Triangle;
|
||||||
use crate::ray::Ray;
|
use crate::ray::Ray;
|
||||||
use crate::{objects::materials::traits::Material, vec3::Vec3};
|
use crate::{objects::materials::traits::Material, vec3::Vec3};
|
||||||
|
use log::{info, warn};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ pub struct Quad {
|
|||||||
|
|
||||||
impl Quad {
|
impl Quad {
|
||||||
pub fn new(p1: Vec3, p2: Vec3, p3: Vec3, p4: Vec3, material: Arc<dyn Material>) -> Self {
|
pub fn new(p1: Vec3, p2: Vec3, p3: Vec3, p4: Vec3, material: Arc<dyn Material>) -> Self {
|
||||||
|
warn!("quad normal {}", (p2 - p1).cross(&(p4 - p1)).get_unit());
|
||||||
Self {
|
Self {
|
||||||
p1,
|
p1,
|
||||||
p2,
|
p2,
|
||||||
@@ -28,12 +30,12 @@ impl Quad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn corner_spheres(&self) -> Vec<Sphere> {
|
pub fn corner_spheres(&self) -> Vec<Sphere> {
|
||||||
vec![
|
let mut out: Vec<Sphere> = vec![];
|
||||||
Sphere::new(self.p1, 1., self.material.clone()),
|
out.push(Sphere::new(self.p1, 1., self.material.clone()));
|
||||||
Sphere::new(self.p2, 1., self.material.clone()),
|
out.push(Sphere::new(self.p2, 1., self.material.clone()));
|
||||||
Sphere::new(self.p3, 1., self.material.clone()),
|
out.push(Sphere::new(self.p3, 1., self.material.clone()));
|
||||||
Sphere::new(self.p4, 1., self.material.clone()),
|
out.push(Sphere::new(self.p4, 1., self.material.clone()));
|
||||||
]
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hit(
|
pub fn hit(
|
||||||
@@ -50,7 +52,7 @@ impl Quad {
|
|||||||
if isct1.is_some() {
|
if isct1.is_some() {
|
||||||
return isct1;
|
return isct1;
|
||||||
}
|
}
|
||||||
isct2
|
return isct2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +83,6 @@ impl Hittable for Quad {
|
|||||||
|
|
||||||
fn normal_at(&self, _p: &Vec3) -> Vec3 {
|
fn normal_at(&self, _p: &Vec3) -> Vec3 {
|
||||||
// FIXME: might cause ownership issues
|
// FIXME: might cause ownership issues
|
||||||
self.normal
|
return self.normal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,9 +54,9 @@ impl Triangle {
|
|||||||
|
|
||||||
let diff = (a4 - a1 - a2 - a3).abs();
|
let diff = (a4 - a1 - a2 - a3).abs();
|
||||||
if diff < 0.001 {
|
if diff < 0.001 {
|
||||||
Some(Hit::new(t, p, normal, material, normal.dot(&-r.dir()) > 0.))
|
return Some(Hit::new(t, p, normal, material, normal.dot(&-r.dir()) > 0.));
|
||||||
} else {
|
} else {
|
||||||
None
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,6 +86,6 @@ impl Hittable for Triangle {
|
|||||||
|
|
||||||
fn normal_at(&self, _p: &Vec3) -> Vec3 {
|
fn normal_at(&self, _p: &Vec3) -> Vec3 {
|
||||||
// FIXME: might cause ownership issues
|
// FIXME: might cause ownership issues
|
||||||
self.normal
|
return self.normal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,22 @@ impl Debug for Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Scene {
|
impl Scene {
|
||||||
|
pub fn new(image_width: u32, image_height: u32) -> Self {
|
||||||
|
Self {
|
||||||
|
camera: Camera::new(image_width, image_height),
|
||||||
|
materials: vec![],
|
||||||
|
objects: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn camera(&mut self) -> &mut Camera {
|
||||||
|
&mut self.camera
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_hittable(&mut self, hittable: Arc<dyn Hittable>) {
|
||||||
|
self.objects.push(hittable);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn render(&mut self) {
|
pub fn render(&mut self) {
|
||||||
self.camera.render(&self.objects);
|
self.camera.render(&self.objects);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use core::f32::math::sqrt;
|
use core::f32::math::sqrt;
|
||||||
use is_close::default;
|
use is_close::default;
|
||||||
|
use log::warn;
|
||||||
use rand::RngExt;
|
use rand::RngExt;
|
||||||
use serde::{Deserialize, Serialize, Serializer};
|
use serde::{Deserialize, Serialize, Serializer};
|
||||||
use std::{
|
use std::{
|
||||||
|
|||||||