diff --git a/ray-tracing-egui/src/render.rs b/ray-tracing-egui/src/render.rs index cdc006a..c2ec26a 100644 --- a/ray-tracing-egui/src/render.rs +++ b/ray-tracing-egui/src/render.rs @@ -23,6 +23,7 @@ use vulkano::{ type DynRenderer = dyn ClassicalRenderer + Sync>, BasicCamera> + Sync; +#[allow(clippy::type_complexity)] pub const RENDERER: [(&str, fn(u32, u32) -> Box); 5] = [ ("Depth", |w, h| { Box::new(DepthRenderer::new(w, h)) as Box diff --git a/ray-tracing-material/src/iridescent.rs b/ray-tracing-material/src/iridescent.rs index 945ee16..a40363c 100644 --- a/ray-tracing-material/src/iridescent.rs +++ b/ray-tracing-material/src/iridescent.rs @@ -47,7 +47,7 @@ impl Iridescent { let imag = (num_imag * denom_real - num_real * denom_imag) / (denom_real * denom_real + denom_imag * denom_imag); - // if !real.is_normal() || !imag.is_normal() { + // if real.is_nan() || imag.is_nan() { // dbg!( // l, theta1, theta2, s_polaized, r12, phi, num_real, num_imag, denom_real, // denom_imag, real, imag @@ -57,13 +57,13 @@ impl Iridescent { real * real + imag * imag } - pub fn abs_C_squared(&self, l: f32, theta1: f32, theta2: f32, s_polaized: bool) -> f32 { + pub fn abs_c_squared(&self, l: f32, theta1: f32, theta2: f32, s_polaized: bool) -> f32 { let local_abs_r_1_squared = self.abs_r_1_squared(l, theta1, theta2, s_polaized); local_abs_r_1_squared / (1.0 - local_abs_r_1_squared) } - fn cos_K_Delta(&self, l: f32, theta1: f32, theta2: f32, s_polaized: bool) -> f32 { + fn cos_k_delta(&self, l: f32, theta1: f32, theta2: f32, s_polaized: bool) -> f32 { let k1z = 2.0 * f32::consts::PI * self.n1 * theta1.cos() / l; let k2z = 2.0 * f32::consts::PI * self.n2 * theta2.cos() / l; @@ -81,11 +81,11 @@ impl Iridescent { fn reflectance(&self, l: f32, theta1: f32, s_polaized: bool) -> f32 { let theta2 = f32::asin(f32::sin(theta1) * self.n1 / self.n2); - let local_cos_k_delta = self.cos_K_Delta(l, theta1, theta2, s_polaized); + let local_cos_k_delta = self.cos_k_delta(l, theta1, theta2, s_polaized); - let local_c_squred = self.abs_C_squared(l, theta1, theta2, s_polaized); + let local_c_squred = self.abs_c_squared(l, theta1, theta2, s_polaized); - // if !local_c_squred.is_normal() || !local_cos_k_delta.is_normal() { + // if local_c_squred.is_nan() || local_cos_k_delta.is_nan() { // dbg!(( // l, // theta1, @@ -96,12 +96,14 @@ impl Iridescent { // )); // } - if local_cos_k_delta.abs() < 1.0 { + if local_c_squred.is_infinite() { + 1.0 + } else if local_cos_k_delta.abs() < 1.0 { let k_delta = f32::acos(local_cos_k_delta); let u = f32::sin(k_delta) / f32::sin(self.n * k_delta); - // if !k_delta.is_normal() || !u.is_normal() { + // if k_delta.is_nan() || u.is_nan() || r.is_nan() { // dbg!(( // l, // theta1, @@ -111,6 +113,7 @@ impl Iridescent { // s_polaized, // k_delta, // u, + // r // )); // } @@ -122,7 +125,7 @@ impl Iridescent { let u = f32::sinh(imk_delta) / f32::sinh(self.n * imk_delta); - // if !imk_delta.is_normal() || !u.is_normal() { + // if imk_delta.is_nan() || u.is_nan() || r.is_nan() { // dbg!(( // l, // theta1, @@ -131,7 +134,8 @@ impl Iridescent { // local_c_squred, // s_polaized, // imk_delta, - // u + // u, + // r // )); // } @@ -139,7 +143,7 @@ impl Iridescent { } else { let u = 1.0 / self.n; - // if !u.is_normal() { + // if u.is_nan() || r.is_nan() { // dbg!(( // l, // theta1, @@ -147,7 +151,8 @@ impl Iridescent { // local_cos_k_delta, // local_c_squred, // s_polaized, - // u + // u, + // r // )); // } @@ -189,13 +194,13 @@ impl Iridescent { let r = self.averaged_reflectance(l, theta1); - // if !r.is_normal() { + // if r.is_nan() { // dbg!((theta1, l, r)); // } let color = Self::color_matching_function(l); - // if !color.r().is_normal() || !color.g().is_normal() || !color.b().is_normal() { + // if color.r().is_nan() || color.g().is_nan() || color.b().is_nan() { // dbg!(color); // } diff --git a/ray-tracing-scene/src/acceleration_structure/mod.rs b/ray-tracing-scene/src/acceleration_structure/mod.rs index 4bf44b2..9064988 100644 --- a/ray-tracing-scene/src/acceleration_structure/mod.rs +++ b/ray-tracing-scene/src/acceleration_structure/mod.rs @@ -83,7 +83,7 @@ impl, R: Rng> Scene for AccelerationStructureSc let material = &self.materials[i as usize]; - let light_pdf = if let Some(l) = &material.light { + let light_pdf = if let Some(_l) = &material.light { 0.0 } else { 0.0 diff --git a/ray-tracing-scene/src/examples/basic_cornell.rs b/ray-tracing-scene/src/examples/basic_cornell.rs index 0c9dd9d..5d648ba 100644 --- a/ray-tracing-scene/src/examples/basic_cornell.rs +++ b/ray-tracing-scene/src/examples/basic_cornell.rs @@ -19,6 +19,12 @@ impl BasicCornell { } } +impl Default for BasicCornell { + fn default() -> Self { + Self::new() + } +} + impl ExampleScene for BasicCornell { fn get_scene(&self) -> Box + Sync> { let s = self.scene.get_or_init(|| { diff --git a/ray-tracing-scene/src/examples/cornell2.rs b/ray-tracing-scene/src/examples/cornell2.rs index 5536df1..8145f87 100644 --- a/ray-tracing-scene/src/examples/cornell2.rs +++ b/ray-tracing-scene/src/examples/cornell2.rs @@ -22,6 +22,12 @@ impl Cornell2 { } } +impl Default for Cornell2 { + fn default() -> Self { + Self::new() + } +} + impl ExampleScene for Cornell2 { fn get_scene(&self) -> Box + Sync> { let s = self.scene.get_or_init(|| { diff --git a/ray-tracing-scene/src/examples/mis_test.rs b/ray-tracing-scene/src/examples/mis_test.rs index 3a6695a..bf7d11d 100644 --- a/ray-tracing-scene/src/examples/mis_test.rs +++ b/ray-tracing-scene/src/examples/mis_test.rs @@ -1,15 +1,11 @@ -use std::cell::OnceCell; - -use crate::triangle_bvh::{BVHMaterial, Triangle, TriangleBVH}; - use super::ExampleScene; - +use crate::triangle_bvh::{BVHMaterial, Triangle, TriangleBVH}; use ray_tracing_core::{light::AreaLight, prelude::*, scene::Scene}; use ray_tracing_material::{ - diffuse::DiffuseMaterial, microfacet::{BeckmannDistribution, Microfacet}, mirror::Mirror, }; +use std::cell::OnceCell; pub struct MISTest { scene: OnceCell>, @@ -67,6 +63,12 @@ impl MISTest { } } +impl Default for MISTest { + fn default() -> Self { + Self::new() + } +} + impl ExampleScene for MISTest { fn get_scene(&self) -> Box + Sync> { let s = self.scene.get_or_init(move || { diff --git a/ray-tracing-scene/src/examples/mod.rs b/ray-tracing-scene/src/examples/mod.rs index 2371ac9..f7b0dcd 100644 --- a/ray-tracing-scene/src/examples/mod.rs +++ b/ray-tracing-scene/src/examples/mod.rs @@ -33,6 +33,11 @@ pub fn example_scenes() -> HashMap<&'static str, Box() -> HashMap<&'static str, Box { scene: OnceCell>, diff --git a/ray-tracing-scene/src/examples/stanford_dragon.rs b/ray-tracing-scene/src/examples/stanford_dragon.rs index 80179d5..ccc14a8 100644 --- a/ray-tracing-scene/src/examples/stanford_dragon.rs +++ b/ray-tracing-scene/src/examples/stanford_dragon.rs @@ -1,15 +1,11 @@ -use rand::Rng; -use ray_tracing_core::{light::AreaLight, prelude::*, scene::Scene}; -use ray_tracing_material::{ - microfacet::{BeckmannDistribution, Microfacet}, - oren_nayar::OrenNayar, -}; -use std::cell::{Cell, OnceCell}; - use crate::{ parse_obj::ObjData, triangle_bvh::{BVHMaterial, Triangle, TriangleBVH}, }; +use rand::Rng; +use ray_tracing_core::{light::AreaLight, prelude::*, scene::Scene}; +use ray_tracing_material::oren_nayar::OrenNayar; +use std::cell::{Cell, OnceCell}; use super::ExampleScene; diff --git a/ray-tracing-scene/src/examples/stanford_dragon_as.rs b/ray-tracing-scene/src/examples/stanford_dragon_as.rs index 5e5a600..7be3517 100644 --- a/ray-tracing-scene/src/examples/stanford_dragon_as.rs +++ b/ray-tracing-scene/src/examples/stanford_dragon_as.rs @@ -28,6 +28,12 @@ impl StanfordDragon { } } +impl Default for StanfordDragon { + fn default() -> Self { + Self::new() + } +} + impl ExampleScene for StanfordDragon { fn get_scene(&self) -> Box + Sync> { let s = self.scene.get_or_init(|| { diff --git a/ray-tracing-tev/src/main.rs b/ray-tracing-tev/src/main.rs index 63fe4dc..cc5b4bb 100644 --- a/ray-tracing-tev/src/main.rs +++ b/ray-tracing-tev/src/main.rs @@ -51,9 +51,13 @@ fn render_image< for _ in 0..samples_per_pixel { let r = renderer.render_pixel(scene, camera, x, y, &mut rng) / (samples_per_pixel as Float); - c[0] += r.r(); - c[1] += r.g(); - c[2] += r.b(); + if r.r().is_nan() || r.g().is_nan() || r.b().is_nan() { + eprintln!("NAN x: {:?}, y: {:?}, r: {:?}", x, y, r); + } else { + c[0] += r.r(); + c[1] += r.g(); + c[2] += r.b(); + } } }); println!("Rendered \"{}\" in {:?}", name.as_ref(), start.elapsed());