Compare commits
2 Commits
bf980a28ec
...
a44e61c1f7
| Author | SHA1 | Date | |
|---|---|---|---|
| a44e61c1f7 | |||
| 17ad6e30db |
@@ -2,10 +2,10 @@
|
|||||||
"camera": {
|
"camera": {
|
||||||
"image_width": 1920,
|
"image_width": 1920,
|
||||||
"image_height": 1080,
|
"image_height": 1080,
|
||||||
"anti_alias_rate": 1,
|
"anti_alias_rate": 23,
|
||||||
"max_depth": 50,
|
"max_depth": 50,
|
||||||
"fov": 90.0,
|
"fov": 90.0,
|
||||||
"look_from": [0, 4, 15],
|
"look_from": [15, 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,6 +1,6 @@
|
|||||||
use std::{f32::consts::PI, sync::Arc};
|
use std::{f32::consts::PI, sync::Arc};
|
||||||
|
|
||||||
use log::{info, warn};
|
use log::info;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{hit::Hit, traits::Hittable},
|
objects::{hit::Hit, traits::Hittable},
|
||||||
|
|||||||
@@ -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},
|
vec3::Colour,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ 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;
|
||||||
|
|
||||||
@@ -19,7 +18,6 @@ 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,
|
||||||
@@ -30,12 +28,12 @@ impl Quad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn corner_spheres(&self) -> Vec<Sphere> {
|
pub fn corner_spheres(&self) -> Vec<Sphere> {
|
||||||
let mut out: Vec<Sphere> = vec![];
|
vec![
|
||||||
out.push(Sphere::new(self.p1, 1., self.material.clone()));
|
Sphere::new(self.p1, 1., self.material.clone()),
|
||||||
out.push(Sphere::new(self.p2, 1., self.material.clone()));
|
Sphere::new(self.p2, 1., self.material.clone()),
|
||||||
out.push(Sphere::new(self.p3, 1., self.material.clone()));
|
Sphere::new(self.p3, 1., self.material.clone()),
|
||||||
out.push(Sphere::new(self.p4, 1., self.material.clone()));
|
Sphere::new(self.p4, 1., self.material.clone()),
|
||||||
return out;
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hit(
|
pub fn hit(
|
||||||
@@ -52,7 +50,7 @@ impl Quad {
|
|||||||
if isct1.is_some() {
|
if isct1.is_some() {
|
||||||
return isct1;
|
return isct1;
|
||||||
}
|
}
|
||||||
return isct2;
|
isct2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +81,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
|
||||||
return self.normal;
|
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 {
|
||||||
return Some(Hit::new(t, p, normal, material, normal.dot(&-r.dir()) > 0.));
|
Some(Hit::new(t, p, normal, material, normal.dot(&-r.dir()) > 0.))
|
||||||
} else {
|
} else {
|
||||||
return None;
|
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
|
||||||
return self.normal;
|
self.normal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,22 +40,6 @@ 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,6 +1,5 @@
|
|||||||
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::{
|
||||||
|
|||||||
Reference in New Issue
Block a user