From 87afe4168d58b6daf242626ccfb1a3e974d7aec3 Mon Sep 17 00:00:00 2001 From: Wito Wiala Date: Tue, 1 Sep 2026 19:37:59 +0100 Subject: [PATCH] Might have just made a huge mistake --- shared/src/bxdfs/dielectric.rs | 9 +-- shared/src/bxdfs/diffuse.rs | 116 ++++++++++++++++++++++++++++- shared/src/core/bxdf.rs | 1 + shared/src/core/material.rs | 10 +-- shared/src/materials/coated.rs | 5 +- shared/src/materials/complex.rs | 6 +- shared/src/materials/conductor.rs | 6 +- shared/src/materials/dielectric.rs | 26 +++++-- shared/src/materials/diffuse.rs | 43 +++++++---- shared/src/materials/mix.rs | 2 +- src/core/interaction.rs | 10 +-- src/core/texture.rs | 24 ------ src/integrators/mod.rs | 5 +- src/integrators/path.rs | 13 ++-- src/integrators/pipeline.rs | 8 +- src/textures/bilerp.rs | 20 +---- src/textures/checkerboard.rs | 23 +----- src/textures/constant.rs | 23 +----- src/textures/dots.rs | 24 +----- src/textures/fbm.rs | 9 +-- src/textures/image.rs | 85 +++------------------ src/textures/marble.rs | 12 +-- src/textures/mix.rs | 43 ++--------- src/textures/scaled.rs | 26 +------ src/textures/windy.rs | 9 +-- src/textures/wrinkled.rs | 9 +-- src/wavefront/integrator.rs | 108 +++++++++++++++++++-------- 27 files changed, 315 insertions(+), 360 deletions(-) diff --git a/shared/src/bxdfs/dielectric.rs b/shared/src/bxdfs/dielectric.rs index 1a5098d..3b74b5a 100644 --- a/shared/src/bxdfs/dielectric.rs +++ b/shared/src/bxdfs/dielectric.rs @@ -1,10 +1,10 @@ use crate::core::bsdf::BSDFSample; use crate::core::bxdf::{BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode}; use crate::core::geometry::{ - abs_cos_theta, cos_theta, same_hemisphere, Normal3f, Point2f, Vector3f, VectorLike, + Normal3f, Point2f, Vector3f, VectorLike, abs_cos_theta, cos_theta, same_hemisphere, }; use crate::core::scattering::{ - fr_complex_from_spectrum, fr_dielectric, reflect, refract, TrowbridgeReitzDistribution, + TrowbridgeReitzDistribution, fr_complex_from_spectrum, fr_dielectric, reflect, refract, }; use crate::spectra::SampledSpectrum; use crate::utils::math::square; @@ -362,7 +362,6 @@ impl BxDFTrait for ThinDielectricBxDF { fn as_any(&self) -> &dyn Any { self } - fn regularize(&mut self) { - todo!() - } + + fn regularize(&mut self) {} } diff --git a/shared/src/bxdfs/diffuse.rs b/shared/src/bxdfs/diffuse.rs index 70e20a0..8342e62 100644 --- a/shared/src/bxdfs/diffuse.rs +++ b/shared/src/bxdfs/diffuse.rs @@ -73,4 +73,118 @@ impl BxDFTrait for DiffuseBxDF { #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct DiffuseTransmissionBxDF; +pub struct DiffuseTransmissionBxDF { + pub r: SampledSpectrum, + pub t: SampledSpectrum, +} + +impl DiffuseTransmissionBxDF { + pub fn new(r: SampledSpectrum, t: SampledSpectrum) -> Self { + Self { r, t } + } +} + +impl BxDFTrait for DiffuseTransmissionBxDF { + fn flags(&self) -> BxDFFlags { + let r_flags = if !self.r.is_black() { + BxDFFlags::DIFFUSE_REFLECTION + } else { + BxDFFlags::UNSET + }; + let t_flags = if !self.t.is_black() { + BxDFFlags::DIFFUSE_TRANSMISSION + } else { + BxDFFlags::UNSET + }; + + r_flags | t_flags + } + + fn f(&self, wo: Vector3f, wi: Vector3f, _mode: TransportMode) -> SampledSpectrum { + if !same_hemisphere(wo, wi) { + return self.r * INV_PI; + } + self.t * INV_PI + } + + fn sample_f(&self, wo: Vector3f, uc: Float, u: Point2f, f_args: FArgs) -> Option { + let reflection_flags = + BxDFReflTransFlags::from_bits_truncate(BxDFReflTransFlags::REFLECTION.bits()); + let transmission_flags = + BxDFReflTransFlags::from_bits_truncate(BxDFReflTransFlags::TRANSMISSION.bits()); + + let pr = if !f_args.sample_flags.contains(reflection_flags) { + 0. + } else { + self.r.max_component_value() + }; + + let pt = if !f_args.sample_flags.contains(transmission_flags) { + 0. + } else { + self.t.max_component_value() + }; + + if (pr == 0.) && (pt == 0.) { + return None; + } + + let mut wi = sample_cosine_hemisphere(u); + if wo.z() < 0. { + wi[2] *= -1.; + } + let pdf = cosine_hemisphere_pdf(abs_cos_theta(wi)) * pr / (pr + pt); + + let flags = if uc < pr / (pr + pt) { + BxDFFlags::DIFFUSE_REFLECTION + } else { + BxDFFlags::DIFFUSE_TRANSMISSION + }; + + let bsdf = BSDFSample { + f: self.r * INV_PI, + wi, + pdf, + flags, + ..Default::default() + }; + Some(bsdf) + } + + fn pdf(&self, wo: Vector3f, wi: Vector3f, f_args: FArgs) -> Float { + let reflection_flags = + BxDFReflTransFlags::from_bits_truncate(BxDFReflTransFlags::REFLECTION.bits()); + let transmission_flags = + BxDFReflTransFlags::from_bits_truncate(BxDFReflTransFlags::TRANSMISSION.bits()); + + let pr = if !f_args.sample_flags.contains(reflection_flags) { + 0. + } else { + self.r.max_component_value() + }; + + let pt = if !f_args.sample_flags.contains(transmission_flags) { + 0. + } else { + self.t.max_component_value() + }; + + if (pr == 0.) && (pt == 0.) { + return 0.; + } + + let cos_factor = cosine_hemisphere_pdf(abs_cos_theta(wi)); + + if same_hemisphere(wo, wi) { + return pr / (pr + pt) * cos_factor; + } else { + return pt / (pr + pt) * cos_factor; + } + } + + fn as_any(&self) -> &dyn Any { + self + } + + fn regularize(&mut self) {} +} diff --git a/shared/src/core/bxdf.rs b/shared/src/core/bxdf.rs index b73df2a..3b6e47d 100644 --- a/shared/src/core/bxdf.rs +++ b/shared/src/core/bxdf.rs @@ -146,6 +146,7 @@ pub trait BxDFTrait: Any { #[derive(Debug, Clone, Copy)] pub enum BxDF { Diffuse(DiffuseBxDF), + DiffuseTransmission(DiffuseTransmissionBxDF), Dielectric(DielectricBxDF), ThinDielectric(ThinDielectricBxDF), Conductor(ConductorBxDF), diff --git a/shared/src/core/material.rs b/shared/src/core/material.rs index 680d0fe..461ca18 100644 --- a/shared/src/core/material.rs +++ b/shared/src/core/material.rs @@ -2,6 +2,7 @@ use crate::materials::*; use core::ops::Deref; use enum_dispatch::enum_dispatch; +use crate::Float; use crate::bxdfs::{ CoatedConductorBxDF, CoatedDiffuseBxDF, ConductorBxDF, DielectricBxDF, DiffuseBxDF, }; @@ -13,15 +14,12 @@ use crate::core::image::{Image, WrapMode, WrapMode2D}; use crate::core::interaction::{Interaction, InteractionTrait, ShadingGeom, SurfaceInteraction}; use crate::core::scattering::TrowbridgeReitzDistribution; use crate::core::spectrum::{Spectrum, SpectrumTrait}; -use crate::core::texture::{ - FloatTexture, SpectrumTexture, TextureEvalContext, TextureEvaluator, -}; +use crate::core::texture::{FloatTexture, SpectrumTexture, TextureEvalContext, TextureEvaluator}; use crate::materials::*; use crate::spectra::{SampledSpectrum, SampledWavelengths}; +use crate::utils::Ptr; use crate::utils::hash::hash_float; use crate::utils::math::clamp; -use crate::utils::Ptr; -use crate::Float; #[repr(C)] #[derive(Clone, Debug, Copy)] @@ -162,7 +160,7 @@ pub trait MaterialTrait { &self, tex_eval: &T, ctx: &MaterialEvalContext, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, ) -> BSDF; fn get_bssrdf( diff --git a/shared/src/materials/coated.rs b/shared/src/materials/coated.rs index d9170ca..5cd9bb0 100644 --- a/shared/src/materials/coated.rs +++ b/shared/src/materials/coated.rs @@ -71,7 +71,7 @@ impl MaterialTrait for CoatedDiffuseMaterial { &self, tex_eval: &T, ctx: &MaterialEvalContext, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, ) -> BSDF { let r = SampledSpectrum::clamp( &tex_eval.evaluate_spectrum(&self.reflectance, ctx, lambda), @@ -220,7 +220,7 @@ impl MaterialTrait for CoatedConductorMaterial { &self, tex_eval: &T, ctx: &MaterialEvalContext, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, ) -> BSDF { let mut iurough = tex_eval.evaluate_float(&self.interface_uroughness, ctx); let mut ivrough = tex_eval.evaluate_float(&self.interface_vroughness, ctx); @@ -234,7 +234,6 @@ impl MaterialTrait for CoatedConductorMaterial { let mut ieta = self.interface_eta.evaluate(lambda[0]); if self.interface_eta.is_constant() { - let mut lambda = *lambda; lambda.terminate_secondary_inplace(); } diff --git a/shared/src/materials/complex.rs b/shared/src/materials/complex.rs index 94ca52a..facb411 100644 --- a/shared/src/materials/complex.rs +++ b/shared/src/materials/complex.rs @@ -60,7 +60,7 @@ impl MaterialTrait for HairMaterial { &self, _tex_eval: &T, _ctx: &MaterialEvalContext, - _lambda: &SampledWavelengths, + _lambda: &mut SampledWavelengths, ) -> BSDF { todo!() } @@ -103,7 +103,7 @@ impl MaterialTrait for MeasuredMaterial { &self, _tex_eval: &T, _ctx: &MaterialEvalContext, - _lambda: &SampledWavelengths, + _lambda: &mut SampledWavelengths, ) -> BSDF { // MeasuredBxDF::new(&self.brdf, lambda) todo!() @@ -157,7 +157,7 @@ impl MaterialTrait for SubsurfaceMaterial { &self, _tex_eval: &T, _ctx: &MaterialEvalContext, - _lambda: &SampledWavelengths, + _lambda: &mut SampledWavelengths, ) -> BSDF { todo!() } diff --git a/shared/src/materials/conductor.rs b/shared/src/materials/conductor.rs index 8d94d6c..a880259 100644 --- a/shared/src/materials/conductor.rs +++ b/shared/src/materials/conductor.rs @@ -10,8 +10,8 @@ use crate::core::scattering::TrowbridgeReitzDistribution; use crate::core::spectrum::{Spectrum, SpectrumTrait}; use crate::core::texture::{FloatTexture, SpectrumTexture, TextureEvaluator}; use crate::spectra::{SampledSpectrum, SampledWavelengths}; -use crate::utils::math::clamp; use crate::utils::Ptr; +use crate::utils::math::clamp; #[repr(C)] #[derive(Clone, Copy, Debug)] @@ -55,7 +55,7 @@ impl MaterialTrait for ConductorMaterial { &self, tex_eval: &T, ctx: &MaterialEvalContext, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, ) -> BSDF { let mut u_rough = tex_eval.evaluate_float(&self.u_roughness, ctx); let mut v_rough = tex_eval.evaluate_float(&self.v_roughness, ctx); @@ -88,7 +88,7 @@ impl MaterialTrait for ConductorMaterial { fn get_bssrdf( &self, - tex_eval: &T, + _tex_eval: &T, _ctx: &MaterialEvalContext, _lambda: &SampledWavelengths, ) -> Option { diff --git a/shared/src/materials/dielectric.rs b/shared/src/materials/dielectric.rs index 790f85d..e89eacb 100644 --- a/shared/src/materials/dielectric.rs +++ b/shared/src/materials/dielectric.rs @@ -1,5 +1,7 @@ +use crate::Ptr; use crate::bxdfs::{ CoatedConductorBxDF, CoatedDiffuseBxDF, ConductorBxDF, DielectricBxDF, DiffuseBxDF, HairBxDF, + ThinDielectricBxDF, }; use crate::core::bsdf::BSDF; use crate::core::bssrdf::BSSRDF; @@ -11,7 +13,6 @@ use crate::core::spectrum::{Spectrum, SpectrumTrait}; use crate::core::texture::{FloatTexture, SpectrumTexture, TextureEvaluator}; use crate::spectra::{SampledSpectrum, SampledWavelengths}; use crate::utils::math::clamp; -use crate::Ptr; #[repr(C)] #[derive(Clone, Copy, Debug)] @@ -29,11 +30,11 @@ impl MaterialTrait for DielectricMaterial { &self, tex_eval: &T, ctx: &MaterialEvalContext, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, ) -> BSDF { let mut sampled_eta = self.eta.evaluate(lambda[0]); if !self.eta.is_constant() { - lambda.terminate_secondary(); + lambda.terminate_secondary_inplace(); } if sampled_eta == 0.0 { @@ -92,18 +93,29 @@ impl MaterialTrait for ThinDielectricMaterial { fn get_bsdf( &self, _tex_eval: &T, - _ctx: &MaterialEvalContext, - _lambda: &SampledWavelengths, + ctx: &MaterialEvalContext, + lambda: &mut SampledWavelengths, ) -> BSDF { - todo!() + let sampled_eta = self.eta.evaluate(lambda[0]); + if !self.eta.is_constant() { + lambda.terminate_secondary_inplace(); + } + + if sampled_eta == 0. { + sampled_eta == 1.; + } + + let bxdf = BxDF::ThinDielectric(ThinDielectricBxDF::new(sampled_eta)); + BSDF::new(ctx.ns, ctx.dpdus, bxdf) } + fn get_bssrdf( &self, _tex_eval: &T, _ctx: &MaterialEvalContext, _lambda: &SampledWavelengths, ) -> Option { - todo!() + None } fn can_evaluate_textures(&self, _tex_eval: &dyn TextureEvaluator) -> bool { diff --git a/shared/src/materials/diffuse.rs b/shared/src/materials/diffuse.rs index e319c0d..54de613 100644 --- a/shared/src/materials/diffuse.rs +++ b/shared/src/materials/diffuse.rs @@ -1,5 +1,8 @@ +use crate::Float; +use crate::Ptr; use crate::bxdfs::{ - CoatedConductorBxDF, CoatedDiffuseBxDF, ConductorBxDF, DielectricBxDF, DiffuseBxDF, HairBxDF, + CoatedConductorBxDF, CoatedDiffuseBxDF, ConductorBxDF, DielectricBxDF, DiffuseBxDF, + DiffuseTransmissionBxDF, HairBxDF, }; use crate::core::bsdf::BSDF; use crate::core::bssrdf::BSSRDF; @@ -11,8 +14,6 @@ use crate::core::spectrum::{Spectrum, SpectrumTrait}; use crate::core::texture::{FloatTexture, SpectrumTexture, TextureEvaluator}; use crate::spectra::{SampledSpectrum, SampledWavelengths}; use crate::utils::math::clamp; -use crate::Float; -use crate::Ptr; #[repr(C)] #[derive(Clone, Copy, Debug)] @@ -27,7 +28,7 @@ impl MaterialTrait for DiffuseMaterial { &self, tex_eval: &T, ctx: &MaterialEvalContext, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, ) -> BSDF { let spec = tex_eval.evaluate_spectrum(&self.reflectance, ctx, lambda); let r = SampledSpectrum::clamp(&spec, 0., 1.); @@ -41,7 +42,7 @@ impl MaterialTrait for DiffuseMaterial { _ctx: &MaterialEvalContext, _lambda: &SampledWavelengths, ) -> Option { - todo!() + None } fn can_evaluate_textures(&self, tex_eval: &dyn TextureEvaluator) -> bool { @@ -64,21 +65,33 @@ impl MaterialTrait for DiffuseMaterial { #[repr(C)] #[derive(Clone, Copy, Debug)] pub struct DiffuseTransmissionMaterial { - pub image: Ptr, + pub normal_map: Ptr, pub displacement: Ptr, - pub reflectance: Ptr, - pub transmittance: Ptr, + pub reflectance: Ptr, + pub transmittance: Ptr, pub scale: Float, } impl MaterialTrait for DiffuseTransmissionMaterial { fn get_bsdf( &self, - _tex_eval: &T, - _ctx: &MaterialEvalContext, - _lambda: &SampledWavelengths, + tex_eval: &T, + ctx: &MaterialEvalContext, + lambda: &mut SampledWavelengths, ) -> BSDF { - todo!() + let r = SampledSpectrum::clamp( + &(self.scale * tex_eval.evaluate_spectrum(&self.reflectance, ctx, lambda)), + 0., + 1., + ); + let t = SampledSpectrum::clamp( + &(self.scale * tex_eval.evaluate_spectrum(&self.transmittance, ctx, lambda)), + 0., + 1., + ); + + let bxdf = BxDF::DiffuseTransmission(DiffuseTransmissionBxDF::new(r, t)); + BSDF::new(ctx.ns, ctx.dpdus, bxdf) } fn get_bssrdf( &self, @@ -86,15 +99,15 @@ impl MaterialTrait for DiffuseTransmissionMaterial { _ctx: &MaterialEvalContext, _lambda: &SampledWavelengths, ) -> Option { - todo!() + None } fn can_evaluate_textures(&self, tex_eval: &dyn TextureEvaluator) -> bool { - tex_eval.can_evaluate(&[self.reflectance, self.transmittance], &[]) + tex_eval.can_evaluate(&[], &[self.reflectance, self.transmittance]) } fn get_normal_map(&self) -> Option<&Image> { - self.image.get() + self.normal_map.get() } fn get_displacement(&self) -> Ptr { diff --git a/shared/src/materials/mix.rs b/shared/src/materials/mix.rs index c24edad..193268a 100644 --- a/shared/src/materials/mix.rs +++ b/shared/src/materials/mix.rs @@ -47,7 +47,7 @@ impl MaterialTrait for MixMaterial { &self, tex_eval: &T, ctx: &MaterialEvalContext, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, ) -> BSDF { if let Some(mat) = self.choose_material(tex_eval, ctx) { mat.get_bsdf(tex_eval, ctx, lambda) diff --git a/src/core/interaction.rs b/src/core/interaction.rs index 8d1bb8d..8d8ccdf 100644 --- a/src/core/interaction.rs +++ b/src/core/interaction.rs @@ -1,4 +1,5 @@ use crate::globals::get_options; +use shared::Ptr; use shared::bxdfs::DiffuseBxDF; use shared::core::bsdf::BSDF; use shared::core::bssrdf::BSSRDF; @@ -10,13 +11,12 @@ use shared::core::material::{Material, MaterialEvalContext, MaterialTrait}; use shared::core::sampler::{Sampler, SamplerTrait}; use shared::core::texture::UniversalTextureEvaluator; use shared::spectra::SampledWavelengths; -use shared::Ptr; pub trait InteractionGetter { fn get_bsdf( &mut self, r: &Ray, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, camera: &Camera, sampler: &mut Sampler, materials: &[Material], @@ -35,7 +35,7 @@ impl InteractionGetter for SurfaceInteraction { fn get_bsdf( &mut self, r: &Ray, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, camera: &Camera, sampler: &mut Sampler, materials: &[Material], @@ -98,7 +98,7 @@ impl InteractionGetter for MediumInteraction { fn get_bsdf( &mut self, _r: &Ray, - _lambda: &SampledWavelengths, + _lambda: &mut SampledWavelengths, _camera: &Camera, _sampler: &mut Sampler, _materials: &[Material], @@ -121,7 +121,7 @@ impl InteractionGetter for SimpleInteraction { fn get_bsdf( &mut self, _r: &Ray, - _lambda: &SampledWavelengths, + _lambda: &mut SampledWavelengths, _camera: &Camera, _sampler: &mut Sampler, _materials: &[Material], diff --git a/src/core/texture.rs b/src/core/texture.rs index 12d9379..7390666 100644 --- a/src/core/texture.rs +++ b/src/core/texture.rs @@ -22,18 +22,7 @@ use shared::Float; use std::collections::HashMap; use std::sync::{Arc, Mutex, OnceLock}; -#[enum_dispatch] -pub trait FloatTextureTrait { - fn evaluate(&self, ctx: &TextureEvalContext) -> Float; -} - -#[enum_dispatch] -pub trait SpectrumTextureTrait { - fn evaluate(&self, _ctx: &TextureEvalContext, _lambda: &SampledWavelengths) -> SampledSpectrum; -} - #[derive(Clone, Debug)] -#[enum_dispatch(FloatTextureTrait)] pub enum FloatTexture { Constant(FloatConstantTexture), Checkerboard(FloatCheckerboardTexture), @@ -56,12 +45,6 @@ impl Default for FloatTexture { } } -impl FloatTextureTrait for Arc { - fn evaluate(&self, ctx: &TextureEvalContext) -> Float { - self.as_ref().evaluate(ctx) - } -} - pub trait CreateFloatTexture { fn create( render_from_texture: Transform, @@ -101,7 +84,6 @@ impl FloatTexture { } #[derive(Clone, Debug)] -#[enum_dispatch(SpectrumTextureTrait)] pub enum SpectrumTexture { Constant(SpectrumConstantTexture), Checkerboard(SpectrumCheckerboardTexture), @@ -162,12 +144,6 @@ impl SpectrumTexture { } } -impl SpectrumTextureTrait for Arc { - fn evaluate(&self, ctx: &TextureEvalContext, lambda: &SampledWavelengths) -> SampledSpectrum { - self.as_ref().evaluate(ctx, lambda) - } -} - pub trait CreateTextureMapping { fn create( params: &TextureParameterDictionary, diff --git a/src/integrators/mod.rs b/src/integrators/mod.rs index a9ab2c0..40546e4 100644 --- a/src/integrators/mod.rs +++ b/src/integrators/mod.rs @@ -35,7 +35,7 @@ pub trait RayIntegratorTrait { fn li( &self, ray: Ray, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, sampler: &mut Sampler, visible_surface: bool, arena: &Arena, @@ -69,7 +69,8 @@ impl CreateIntegrator for PathIntegrator { let _max_depth = parameters.get_one_int("maxdepth", 5)?; let _regularize = parameters.get_one_bool("regularize", false)?; let light_sampler = create_light_sampler("power", &lights, arena); - let integrator = PathIntegrator::new(aggregate, lights, camera, light_sampler, config, materials); + let integrator = + PathIntegrator::new(aggregate, lights, camera, light_sampler, config, materials); Ok(integrator) } } diff --git a/src/integrators/path.rs b/src/integrators/path.rs index 8adccf8..856ebfd 100644 --- a/src/integrators/path.rs +++ b/src/integrators/path.rs @@ -1,10 +1,10 @@ +use super::RayIntegratorTrait; use super::base::IntegratorBase; use super::constants::*; use super::state::PathState; -use super::RayIntegratorTrait; -use crate::core::interaction::InteractionGetter; use crate::Arena; -use shared::core::bsdf::{BSDFSample, BSDF}; +use crate::core::interaction::InteractionGetter; +use shared::core::bsdf::{BSDF, BSDFSample}; use shared::core::bxdf::{BxDFFlags, FArgs, TransportMode}; use shared::core::camera::Camera; use shared::core::film::VisibleSurface; @@ -72,7 +72,6 @@ pub struct PathIntegrator { materials: Vec, } - impl PathIntegrator { pub fn new( aggregate: Arc, @@ -208,7 +207,7 @@ impl RayIntegratorTrait for PathIntegrator { fn li( &self, mut ray: Ray, - lambda: &SampledWavelengths, + lambda: &mut SampledWavelengths, sampler: &mut Sampler, want_visible: bool, _arena: &Arena, @@ -247,7 +246,9 @@ impl RayIntegratorTrait for PathIntegrator { } // Get BSDF - let Some(mut bsdf) = isect.get_bsdf(&ray, lambda, &self.camera, sampler, &self.materials) else { + let Some(mut bsdf) = + isect.get_bsdf(&ray, lambda, &self.camera, sampler, &self.materials) + else { state.specular_bounce = true; isect.skip_intersection(&mut ray, t_hit); continue; diff --git a/src/integrators/pipeline.rs b/src/integrators/pipeline.rs index eaf8877..1cf740a 100644 --- a/src/integrators/pipeline.rs +++ b/src/integrators/pipeline.rs @@ -1,5 +1,5 @@ -use super::base::IntegratorBase; use super::RayIntegratorTrait; +use super::base::IntegratorBase; use crate::core::camera::InitMetadata; use crate::core::film::FilmTrait; use crate::core::image::{HostImage, ImageIO, ImageMetadata}; @@ -7,12 +7,12 @@ use crate::globals::get_options; use crate::spectra::get_spectra_context; use crate::{Arena, PbrtProgress}; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; +use shared::Float; use shared::core::camera::{Camera, CameraTrait}; use shared::core::geometry::{Bounds2i, Point2i}; use shared::core::sampler::get_camera_sample; use shared::core::sampler::{Sampler, SamplerTrait}; use shared::spectra::SampledSpectrum; -use shared::Float; use std::io::Write; use std::path::Path; @@ -214,7 +214,7 @@ pub fn evaluate_pixel_sample( lu = 0.5; } - let lambda = camera.get_film().sample_wavelengths(lu); + let mut lambda = camera.get_film().sample_wavelengths(lu); let film = camera.get_film(); let filter = film.get_filter(); let camera_sample = get_camera_sample(sampler, pixel, filter); @@ -229,7 +229,7 @@ pub fn evaluate_pixel_sample( let initialize_visible_surface = film.uses_visible_surface(); let (mut l, visible_surface) = integrator.li( camera_ray.ray, - &lambda, + &mut lambda, sampler, initialize_visible_surface, arena, diff --git a/src/textures/bilerp.rs b/src/textures/bilerp.rs index 6e108fb..0f9592e 100644 --- a/src/textures/bilerp.rs +++ b/src/textures/bilerp.rs @@ -1,19 +1,18 @@ use crate::Arena; use crate::core::texture::{ - CreateFloatTexture, CreateSpectrumTexture, FloatTextureTrait, SpectrumTexture, - SpectrumTextureTrait, -}; + CreateFloatTexture, CreateSpectrumTexture, SpectrumTexture + }; use anyhow::Result; use shared::core::texture::{SpectrumType, TextureEvalContext}; use shared::{ spectra::{SampledSpectrum, SampledWavelengths}, textures::{FloatBilerpTexture, SpectrumBilerpTexture}, - utils::Transform, + utils::Transform }; use crate::{ core::texture::FloatTexture, - utils::{FileLoc, TextureParameterDictionary}, + utils::{FileLoc, TextureParameterDictionary} }; impl CreateFloatTexture for FloatBilerpTexture { @@ -27,12 +26,6 @@ impl CreateFloatTexture for FloatBilerpTexture { } } -impl FloatTextureTrait for FloatBilerpTexture { - fn evaluate(&self, _ctx: &TextureEvalContext) -> shared::Float { - todo!() - } -} - impl CreateSpectrumTexture for SpectrumBilerpTexture { fn create( _render_from_texture: Transform, @@ -44,8 +37,3 @@ impl CreateSpectrumTexture for SpectrumBilerpTexture { } } -impl SpectrumTextureTrait for SpectrumBilerpTexture { - fn evaluate(&self, _ctx: &TextureEvalContext, _lambda: &SampledWavelengths) -> SampledSpectrum { - todo!() - } -} diff --git a/src/textures/checkerboard.rs b/src/textures/checkerboard.rs index 632e9ec..a35701a 100644 --- a/src/textures/checkerboard.rs +++ b/src/textures/checkerboard.rs @@ -3,15 +3,13 @@ use anyhow::Result; use shared::{ core::texture::SpectrumType, textures::{FloatCheckerboardTexture, SpectrumCheckerboardTexture}, - utils::Transform, + utils::Transform }; use crate::{ core::texture::{ - CreateFloatTexture, CreateSpectrumTexture, FloatTexture, FloatTextureTrait, - SpectrumTexture, SpectrumTextureTrait, - }, - utils::{FileLoc, TextureParameterDictionary}, + CreateFloatTexture, CreateSpectrumTexture, FloatTexture, SpectrumTexture }, + utils::{FileLoc, TextureParameterDictionary} }; impl CreateFloatTexture for FloatCheckerboardTexture { @@ -25,12 +23,6 @@ impl CreateFloatTexture for FloatCheckerboardTexture { } } -impl FloatTextureTrait for FloatCheckerboardTexture { - fn evaluate(&self, _ctx: &shared::core::texture::TextureEvalContext) -> shared::Float { - todo!() - } -} - impl CreateSpectrumTexture for SpectrumCheckerboardTexture { fn create( _render_from_texture: Transform, @@ -42,12 +34,3 @@ impl CreateSpectrumTexture for SpectrumCheckerboardTexture { } } -impl SpectrumTextureTrait for SpectrumCheckerboardTexture { - fn evaluate( - &self, - _ctx: &shared::core::texture::TextureEvalContext, - _lambda: &shared::spectra::SampledWavelengths, - ) -> shared::spectra::SampledSpectrum { - todo!() - } -} diff --git a/src/textures/constant.rs b/src/textures/constant.rs index e6114cf..ff52234 100644 --- a/src/textures/constant.rs +++ b/src/textures/constant.rs @@ -3,15 +3,13 @@ use anyhow::Result; use shared::{ core::texture::{SpectrumType, TextureEvalContext}, textures::{FloatConstantTexture, SpectrumConstantTexture}, - utils::Transform, + utils::Transform }; use crate::{ core::texture::{ - CreateFloatTexture, CreateSpectrumTexture, FloatTexture, FloatTextureTrait, - SpectrumTexture, SpectrumTextureTrait, - }, - utils::{FileLoc, TextureParameterDictionary}, + CreateFloatTexture, CreateSpectrumTexture, FloatTexture, SpectrumTexture }, + utils::{FileLoc, TextureParameterDictionary} }; impl CreateFloatTexture for FloatConstantTexture { @@ -25,12 +23,6 @@ impl CreateFloatTexture for FloatConstantTexture { } } -impl FloatTextureTrait for FloatConstantTexture { - fn evaluate(&self, _ctx: &TextureEvalContext) -> shared::Float { - todo!() - } -} - impl CreateSpectrumTexture for SpectrumConstantTexture { fn create( _render_from_texture: Transform, @@ -42,12 +34,3 @@ impl CreateSpectrumTexture for SpectrumConstantTexture { } } -impl SpectrumTextureTrait for SpectrumConstantTexture { - fn evaluate( - &self, - _ctx: &TextureEvalContext, - _lambda: &shared::spectra::SampledWavelengths, - ) -> shared::spectra::SampledSpectrum { - todo!() - } -} diff --git a/src/textures/dots.rs b/src/textures/dots.rs index 641abb8..29f425b 100644 --- a/src/textures/dots.rs +++ b/src/textures/dots.rs @@ -3,23 +3,15 @@ use anyhow::Result; use shared::{ core::texture::SpectrumType, textures::{FloatDotsTexture, SpectrumDotsTexture}, - utils::Transform, + utils::Transform }; use crate::{ core::texture::{ - CreateFloatTexture, CreateSpectrumTexture, FloatTexture, FloatTextureTrait, - SpectrumTexture, SpectrumTextureTrait, - }, - utils::{FileLoc, TextureParameterDictionary}, + CreateFloatTexture, CreateSpectrumTexture, FloatTexture, SpectrumTexture }, + utils::{FileLoc, TextureParameterDictionary} }; -impl FloatTextureTrait for FloatDotsTexture { - fn evaluate(&self, _ctx: &shared::core::texture::TextureEvalContext) -> shared::Float { - todo!() - } -} - impl CreateFloatTexture for FloatDotsTexture { fn create( _render_from_texture: Transform, @@ -31,16 +23,6 @@ impl CreateFloatTexture for FloatDotsTexture { } } -impl SpectrumTextureTrait for SpectrumDotsTexture { - fn evaluate( - &self, - _ctx: &shared::core::texture::TextureEvalContext, - _lambda: &shared::spectra::SampledWavelengths, - ) -> shared::spectra::SampledSpectrum { - todo!() - } -} - impl CreateSpectrumTexture for SpectrumDotsTexture { fn create( _render_from_texture: Transform, diff --git a/src/textures/fbm.rs b/src/textures/fbm.rs index 2dc8ce8..2508c4a 100644 --- a/src/textures/fbm.rs +++ b/src/textures/fbm.rs @@ -4,8 +4,8 @@ use shared::core::texture::TextureEvalContext; use shared::{textures::FBmTexture, utils::Transform}; use crate::{ - core::texture::{CreateFloatTexture, FloatTexture, FloatTextureTrait}, - utils::{FileLoc, TextureParameterDictionary}, + core::texture::{CreateFloatTexture, FloatTexture }, + utils::{FileLoc, TextureParameterDictionary} }; impl CreateFloatTexture for FBmTexture { @@ -19,8 +19,3 @@ impl CreateFloatTexture for FBmTexture { } } -impl FloatTextureTrait for FBmTexture { - fn evaluate(&self, _ctx: &TextureEvalContext) -> shared::Float { - todo!() - } -} diff --git a/src/textures/image.rs b/src/textures/image.rs index 63eda11..3707041 100644 --- a/src/textures/image.rs +++ b/src/textures/image.rs @@ -1,8 +1,7 @@ use crate::core::texture::{get_texture_cache, CreateTextureMapping, TexInfo}; use crate::core::texture::{ - CreateFloatTexture, CreateSpectrumTexture, FloatTexture, FloatTextureTrait, SpectrumTexture, - SpectrumTextureTrait, -}; + CreateFloatTexture, CreateSpectrumTexture, FloatTexture, SpectrumTexture + }; use crate::utils::mipmap::{MIPMap, MIPMapFilterOptions}; use crate::utils::{resolve_filename, FileLoc, TextureParameterDictionary}; use crate::Arena; @@ -15,7 +14,7 @@ use shared::core::spectrum::SpectrumTrait; use shared::core::texture::{SpectrumType, TexCoord2D, TextureEvalContext, TextureMapping2D}; use shared::spectra::{ RGBAlbedoSpectrum, RGBIlluminantSpectrum, RGBUnboundedSpectrum, SampledSpectrum, - SampledWavelengths, + SampledWavelengths }; use shared::utils::Transform; use shared::Float; @@ -28,7 +27,7 @@ pub struct ImageTextureBase { pub filename: String, pub scale: Float, pub invert: bool, - pub mipmap: Arc, + pub mipmap: Arc } impl ImageTextureBase { @@ -45,7 +44,7 @@ impl ImageTextureBase { filename: filename.clone(), filter_options, wrap_mode, - encoding, + encoding }; let cache_mutex = get_texture_cache(); @@ -58,7 +57,7 @@ impl ImageTextureBase { filename, scale, invert, - mipmap: mipmap.clone(), + mipmap: mipmap.clone() }; } } @@ -79,7 +78,7 @@ impl ImageTextureBase { filename, scale, invert, - mipmap: stored_mipmap.clone(), + mipmap: stored_mipmap.clone() } } } @@ -97,7 +96,7 @@ impl ImageTextureBase { #[derive(Clone, Debug)] pub struct SpectrumImageTexture { pub base: ImageTextureBase, - pub spectrum_type: SpectrumType, + pub spectrum_type: SpectrumType } impl SpectrumImageTexture { @@ -124,52 +123,11 @@ impl SpectrumImageTexture { Self { base, - spectrum_type, + spectrum_type } } } -impl SpectrumTextureTrait for SpectrumImageTexture { - fn evaluate(&self, ctx: &TextureEvalContext, lambda: &SampledWavelengths) -> SampledSpectrum { - use std::sync::atomic::{AtomicU32, Ordering}; - static PATH_IMG_COUNT: AtomicU32 = AtomicU32::new(0); - let pn = PATH_IMG_COUNT.fetch_add(1, Ordering::Relaxed); - - let mut c = self.base.mapping.map(ctx); - c.st[1] = 1. - c.st[1]; - let dst0 = Vector2f::new(c.dsdx, c.dtdx); - let dst1 = Vector2f::new(c.dsdy, c.dtdy); - let raw_rgb = self.base.mipmap.filter::(c.st, dst0, dst1); - let rgb_unclamp = self.base.scale * raw_rgb; - let rgb = RGB::clamp_zero(&rgb_unclamp); - - if pn < 5 { - eprintln!("PATH_IMG[{pn}] scale={:.6} raw_rgb[0]={:.6} rgb_after_scale[0]={:.6} \ - st={:?} dst0={:?} dst1={:?} has_cs={}", - self.base.scale, raw_rgb[0], rgb_unclamp[0], - c.st, dst0, dst1, - self.base.mipmap.get_rgb_colorspace().is_some()); - } - - if let Some(cs) = self.base.mipmap.get_rgb_colorspace() { - match self.spectrum_type { - SpectrumType::Unbounded => { - return RGBUnboundedSpectrum::new(&cs, rgb).sample(lambda); - } - SpectrumType::Albedo => { - return RGBAlbedoSpectrum::new(&cs, rgb.clamp(0., 1.)).sample(lambda); - } - _ => return RGBIlluminantSpectrum::new(&cs, rgb).sample(lambda), - } - } - let result = SampledSpectrum::new(rgb[0]); - if pn < 5 { - eprintln!("PATH_IMG[{pn}] no-cs branch result[0]={:.6}", result[0]); - } - result - } -} - impl CreateSpectrumTexture for SpectrumImageTexture { fn create( render_from_texture: Transform, @@ -190,7 +148,7 @@ impl CreateSpectrumTexture for SpectrumImageTexture { "repeat" => WrapMode::Repeat, "clamp" => WrapMode::Clamp, "black" => WrapMode::Black, - _ => WrapMode::Repeat, + _ => WrapMode::Repeat }; let encoding = ColorEncoding::SRGB(SRGBEncoding); @@ -212,7 +170,7 @@ impl CreateSpectrumTexture for SpectrumImageTexture { #[derive(Debug, Clone)] pub struct FloatImageTexture { - pub base: ImageTextureBase, + pub base: ImageTextureBase } impl FloatImageTexture { @@ -234,26 +192,7 @@ impl FloatImageTexture { scale, invert, encoding, - ), - } - } -} - -impl FloatTextureTrait for FloatImageTexture { - fn evaluate(&self, ctx: &TextureEvalContext) -> Float { - let mut c: TexCoord2D = self.base.mapping.map(ctx); - c.st[1] = 1. - c.st[1]; - let v: Float = self.base.scale - * self.base.mipmap.filter::( - c.st, - Vector2f::new(c.dsdx, c.dtdx), - Vector2f::new(c.dsdy, c.dtdy), - ); - - if self.base.invert { - (1. - v).max(0.) - } else { - v + ) } } } diff --git a/src/textures/marble.rs b/src/textures/marble.rs index 32d1d0e..b5541ce 100644 --- a/src/textures/marble.rs +++ b/src/textures/marble.rs @@ -1,17 +1,7 @@ -use crate::core::texture::{CreateSpectrumTexture, SpectrumTexture, SpectrumTextureTrait}; +use crate::core::texture::{CreateSpectrumTexture, SpectrumTexture }; use shared::core::texture::SpectrumType; use shared::textures::MarbleTexture; -impl SpectrumTextureTrait for MarbleTexture { - fn evaluate( - &self, - _ctx: &shared::core::texture::TextureEvalContext, - _lambda: &shared::spectra::SampledWavelengths, - ) -> shared::spectra::SampledSpectrum { - todo!() - } -} - impl CreateSpectrumTexture for MarbleTexture { fn create( _render_from_texture: shared::utils::Transform, diff --git a/src/textures/mix.rs b/src/textures/mix.rs index a17c644..6944e26 100644 --- a/src/textures/mix.rs +++ b/src/textures/mix.rs @@ -1,6 +1,5 @@ use crate::core::texture::{ - CreateSpectrumTexture, FloatTexture, FloatTextureTrait, SpectrumTexture, SpectrumTextureTrait, -}; + CreateSpectrumTexture, FloatTexture, SpectrumTexture }; use crate::utils::{FileLoc, TextureParameterDictionary}; use crate::Arena; use anyhow::Result; @@ -15,7 +14,7 @@ use std::sync::Arc; pub struct FloatMixTexture { pub tex1: Arc, pub tex2: Arc, - pub amount: Arc, + pub amount: Arc } impl FloatMixTexture { @@ -41,26 +40,11 @@ impl FloatMixTexture { } } -impl FloatTextureTrait for FloatMixTexture { - fn evaluate(&self, ctx: &TextureEvalContext) -> Float { - let amt = self.amount.evaluate(ctx); - let mut t1 = 0.; - let mut t2 = 0.; - if amt != 1. { - t1 = self.tex1.evaluate(ctx); - } - if amt != 0. { - t2 = self.tex2.evaluate(ctx); - } - (1. - amt) * t1 + amt * t2 - } -} - #[derive(Clone, Debug)] pub struct FloatDirectionMixTexture { pub tex1: Arc, pub tex2: Arc, - pub dir: Vector3f, + pub dir: Vector3f } impl FloatDirectionMixTexture { @@ -83,17 +67,11 @@ impl FloatDirectionMixTexture { } } -impl FloatTextureTrait for FloatDirectionMixTexture { - fn evaluate(&self, _ctx: &TextureEvalContext) -> Float { - todo!() - } -} - #[derive(Clone, Debug)] pub struct SpectrumMixTexture { pub tex1: Arc, pub tex2: Arc, - pub amount: Arc, + pub amount: Arc } impl CreateSpectrumTexture for SpectrumMixTexture { @@ -107,17 +85,11 @@ impl CreateSpectrumTexture for SpectrumMixTexture { } } -impl SpectrumTextureTrait for SpectrumMixTexture { - fn evaluate(&self, _ctx: &TextureEvalContext, _lambda: &SampledWavelengths) -> SampledSpectrum { - todo!() - } -} - #[derive(Clone, Debug)] pub struct SpectrumDirectionMixTexture { pub tex1: Arc, pub tex2: Arc, - pub dir: Vector3f, + pub dir: Vector3f } impl CreateSpectrumTexture for SpectrumDirectionMixTexture { @@ -131,8 +103,3 @@ impl CreateSpectrumTexture for SpectrumDirectionMixTexture { } } -impl SpectrumTextureTrait for SpectrumDirectionMixTexture { - fn evaluate(&self, _ctx: &TextureEvalContext, _lambda: &SampledWavelengths) -> SampledSpectrum { - todo!() - } -} diff --git a/src/textures/scaled.rs b/src/textures/scaled.rs index 97c25de..e40d3a5 100644 --- a/src/textures/scaled.rs +++ b/src/textures/scaled.rs @@ -1,5 +1,4 @@ use crate::core::texture::{CreateSpectrumTexture, FloatTexture, SpectrumTexture}; -use crate::core::texture::{FloatTextureTrait, SpectrumTextureTrait}; use crate::utils::{FileLoc, TextureParameterDictionary}; use crate::Arena; use anyhow::Result; @@ -13,7 +12,7 @@ use std::sync::Arc; #[derive(Clone, Debug)] pub struct FloatScaledTexture { pub tex: Arc, - pub scale: Arc, + pub scale: Arc } impl FloatScaledTexture { @@ -52,20 +51,10 @@ impl FloatScaledTexture { } } -impl FloatTextureTrait for FloatScaledTexture { - fn evaluate(&self, ctx: &TextureEvalContext) -> Float { - let sc = self.scale.evaluate(ctx); - if sc == 0. { - return 0.; - } - self.tex.evaluate(ctx) - } -} - #[derive(Clone, Debug)] pub struct SpectrumScaledTexture { pub tex: Arc, - pub scale: Arc, + pub scale: Arc } impl CreateSpectrumTexture for SpectrumScaledTexture { @@ -95,17 +84,8 @@ impl CreateSpectrumTexture for SpectrumScaledTexture { Ok(SpectrumTexture::Scaled(SpectrumScaledTexture { tex, - scale, + scale })) } } -impl SpectrumTextureTrait for SpectrumScaledTexture { - fn evaluate(&self, ctx: &TextureEvalContext, lambda: &SampledWavelengths) -> SampledSpectrum { - let sc = self.scale.evaluate(ctx); - if sc == 0. { - return SampledSpectrum::new(0.); - } - self.tex.evaluate(ctx, lambda) * sc - } -} diff --git a/src/textures/windy.rs b/src/textures/windy.rs index 62762c5..7f9c728 100644 --- a/src/textures/windy.rs +++ b/src/textures/windy.rs @@ -3,8 +3,8 @@ use anyhow::Result; use shared::{textures::WindyTexture, utils::Transform}; use crate::{ - core::texture::{CreateFloatTexture, FloatTexture, FloatTextureTrait}, - utils::{FileLoc, TextureParameterDictionary}, + core::texture::{CreateFloatTexture, FloatTexture }, + utils::{FileLoc, TextureParameterDictionary} }; impl CreateFloatTexture for WindyTexture { @@ -18,8 +18,3 @@ impl CreateFloatTexture for WindyTexture { } } -impl FloatTextureTrait for WindyTexture { - fn evaluate(&self, _ctx: &shared::core::texture::TextureEvalContext) -> shared::Float { - todo!() - } -} diff --git a/src/textures/wrinkled.rs b/src/textures/wrinkled.rs index 9929d08..e68a152 100644 --- a/src/textures/wrinkled.rs +++ b/src/textures/wrinkled.rs @@ -3,8 +3,8 @@ use anyhow::Result; use shared::{textures::WrinkledTexture, utils::Transform}; use crate::{ - core::texture::{CreateFloatTexture, FloatTexture, FloatTextureTrait}, - utils::{FileLoc, TextureParameterDictionary}, + core::texture::{CreateFloatTexture, FloatTexture }, + utils::{FileLoc, TextureParameterDictionary} }; impl CreateFloatTexture for WrinkledTexture { @@ -18,8 +18,3 @@ impl CreateFloatTexture for WrinkledTexture { } } -impl FloatTextureTrait for WrinkledTexture { - fn evaluate(&self, _ctx: &shared::core::texture::TextureEvalContext) -> shared::Float { - todo!() - } -} diff --git a/src/wavefront/integrator.rs b/src/wavefront/integrator.rs index d3b9d09..92b1228 100644 --- a/src/wavefront/integrator.rs +++ b/src/wavefront/integrator.rs @@ -1,11 +1,12 @@ use super::CpuAggregate; -use crate::globals::get_options; -use crate::lights::sampler::create_light_sampler; use crate::Arena; use crate::ParameterDictionary; use crate::PbrtProgress; +use crate::globals::get_options; +use crate::lights::sampler::create_light_sampler; use log::debug; use rayon::prelude::*; +use shared::core::LightIdx; use shared::core::bxdf::{FArgs, TransportMode}; use shared::core::camera::{Camera, CameraTrait}; use shared::core::film::VisibleSurface; @@ -18,24 +19,23 @@ use shared::core::interaction::InteractionTrait; use shared::core::light::{Light, LightSampleContext, LightTrait}; use shared::core::material::{Material, MaterialEvalContext, MaterialTrait}; use shared::core::primitive::{Primitive, PrimitiveTrait}; -use shared::core::sampler::{get_camera_sample, CameraSample, Sampler, SamplerTrait}; +use shared::core::sampler::{CameraSample, Sampler, SamplerTrait, get_camera_sample}; use shared::core::texture::{BasicTextureEvaluator, TextureEvalContext, UniversalTextureEvaluator}; -use shared::core::LightIdx; use shared::lights::sampler::{LightSampler, LightSamplerTrait}; use shared::spectra::{SampledSpectrum, SampledWavelengths}; +use shared::textures::image::{ + DIAG_IMG_COUNT, DIAG_IMG_PIXEL0_BITS, DIAG_IMG_RESULT0_BITS, DIAG_IMG_RGB0_BITS, + DIAG_IMG_SCALE_BITS, +}; use shared::utils::math::square; use shared::utils::sampling::power_heuristic; use shared::utils::soa::{SoA, SoAAllocator, WorkQueue}; use shared::wavefront::workitems::*; use shared::wavefront::{WavefrontAggregate, WavefrontPathIntegrator, WavefrontRenderer}; -use shared::{gvec, gvec_from_slice, GVec, Ptr, SHADOW_EPSILON}; -use shared::textures::image::{ - DIAG_IMG_COUNT, DIAG_IMG_SCALE_BITS, DIAG_IMG_PIXEL0_BITS, - DIAG_IMG_RGB0_BITS, DIAG_IMG_RESULT0_BITS, -}; +use shared::{GVec, Ptr, SHADOW_EPSILON, gvec, gvec_from_slice}; use std::ops::{Deref, DerefMut}; -use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicU32, Ordering}; static DIAG_EVAL_ENTER: AtomicU32 = AtomicU32::new(0); static DIAG_BSDF_EMPTY: AtomicU32 = AtomicU32::new(0); @@ -232,23 +232,39 @@ impl CpuWavefrontRenderer { eprintln!("=== DIAG s=0 y0={} depth={} ===", y0, depth); eprintln!(" eval_enter={}", DIAG_EVAL_ENTER.load(Ordering::Relaxed)); eprintln!(" bsdf_empty={}", DIAG_BSDF_EMPTY.load(Ordering::Relaxed)); - eprintln!(" non_specular_skip={}", DIAG_NON_SPECULAR_SKIP.load(Ordering::Relaxed)); - eprintln!(" sample_light_none={}", DIAG_SAMPLE_LIGHT_NONE.load(Ordering::Relaxed)); - eprintln!(" sample_li_none={}", DIAG_SAMPLE_LI_NONE.load(Ordering::Relaxed)); + eprintln!( + " non_specular_skip={}", + DIAG_NON_SPECULAR_SKIP.load(Ordering::Relaxed) + ); + eprintln!( + " sample_light_none={}", + DIAG_SAMPLE_LIGHT_NONE.load(Ordering::Relaxed) + ); + eprintln!( + " sample_li_none={}", + DIAG_SAMPLE_LI_NONE.load(Ordering::Relaxed) + ); eprintln!(" ls_l_black={}", DIAG_LS_L_BLACK.load(Ordering::Relaxed)); eprintln!(" ls_pdf_zero={}", DIAG_LS_PDF_ZERO.load(Ordering::Relaxed)); eprintln!(" f_none={}", DIAG_F_NONE.load(Ordering::Relaxed)); eprintln!(" f_black={}", DIAG_F_BLACK.load(Ordering::Relaxed)); eprintln!(" shadow_push={}", DIAG_SHADOW_PUSH.load(Ordering::Relaxed)); - eprintln!(" shadow_unoccluded={}", super::aggregate::DIAG_SHADOW_UNOCCLUDED.load(Ordering::Relaxed)); + eprintln!( + " shadow_unoccluded={}", + super::aggregate::DIAG_SHADOW_UNOCCLUDED.load(Ordering::Relaxed) + ); let img_n = DIAG_IMG_COUNT.load(Ordering::Relaxed); if img_n > 0 { let scale = f32::from_bits(DIAG_IMG_SCALE_BITS.load(Ordering::Relaxed)); - let pixel0 = f32::from_bits(DIAG_IMG_PIXEL0_BITS.load(Ordering::Relaxed)); + let pixel0 = + f32::from_bits(DIAG_IMG_PIXEL0_BITS.load(Ordering::Relaxed)); let rgb0 = f32::from_bits(DIAG_IMG_RGB0_BITS.load(Ordering::Relaxed)); - let result0 = f32::from_bits(DIAG_IMG_RESULT0_BITS.load(Ordering::Relaxed)); - eprintln!(" img_tex_calls={} scale={:.6} pixel0={:.6} rgb0_pre_scale={:.6} result[0]={:.6}", - img_n, scale, pixel0, rgb0, result0); + let result0 = + f32::from_bits(DIAG_IMG_RESULT0_BITS.load(Ordering::Relaxed)); + eprintln!( + " img_tex_calls={} scale={:.6} pixel0={:.6} rgb0_pre_scale={:.6} result[0]={:.6}", + img_n, scale, pixel0, rgb0, result0 + ); } } } @@ -263,15 +279,27 @@ impl CpuWavefrontRenderer { eprintln!("=== NEE DIAG COUNTS ==="); eprintln!("eval_enter={}", DIAG_EVAL_ENTER.load(Ordering::Relaxed)); eprintln!("bsdf_empty={}", DIAG_BSDF_EMPTY.load(Ordering::Relaxed)); - eprintln!("non_specular_skip={}", DIAG_NON_SPECULAR_SKIP.load(Ordering::Relaxed)); - eprintln!("sample_light_none={}", DIAG_SAMPLE_LIGHT_NONE.load(Ordering::Relaxed)); - eprintln!("sample_li_none={}", DIAG_SAMPLE_LI_NONE.load(Ordering::Relaxed)); + eprintln!( + "non_specular_skip={}", + DIAG_NON_SPECULAR_SKIP.load(Ordering::Relaxed) + ); + eprintln!( + "sample_light_none={}", + DIAG_SAMPLE_LIGHT_NONE.load(Ordering::Relaxed) + ); + eprintln!( + "sample_li_none={}", + DIAG_SAMPLE_LI_NONE.load(Ordering::Relaxed) + ); eprintln!("ls_l_black={}", DIAG_LS_L_BLACK.load(Ordering::Relaxed)); eprintln!("ls_pdf_zero={}", DIAG_LS_PDF_ZERO.load(Ordering::Relaxed)); eprintln!("f_none={}", DIAG_F_NONE.load(Ordering::Relaxed)); eprintln!("f_black={}", DIAG_F_BLACK.load(Ordering::Relaxed)); eprintln!("shadow_push={}", DIAG_SHADOW_PUSH.load(Ordering::Relaxed)); - eprintln!("shadow_unoccluded={}", super::aggregate::DIAG_SHADOW_UNOCCLUDED.load(Ordering::Relaxed)); + eprintln!( + "shadow_unoccluded={}", + super::aggregate::DIAG_SHADOW_UNOCCLUDED.load(Ordering::Relaxed) + ); } fn generate_camera_rays( @@ -464,11 +492,19 @@ impl CpuWavefrontRenderer { dpdu={:?} dpdv={:?} \ dpdus={:?} dpdvs={:?} \ uv={:?} material={:?} area_light={:?} face_index={}", - w.pixel_index, w.depth, - w.p, w.n, w.ns, - w.dpdu, w.dpdv, - w.dpdus, w.dpdvs, - w.uv, w.material, w.area_light, w.face_index, + w.pixel_index, + w.depth, + w.p, + w.n, + w.ns, + w.dpdu, + w.dpdv, + w.dpdus, + w.dpdvs, + w.uv, + w.material, + w.area_light, + w.face_index, ); } DIAG_EVAL_ENTER.fetch_add(1, Ordering::Relaxed); @@ -500,12 +536,12 @@ impl CpuWavefrontRenderer { dpdus: w.dpdus, }; - let lambda = w.lambda; + let mut lambda = w.lambda; let mut bsdf = if use_universal { - material.get_bsdf(&UniversalTextureEvaluator, &ctx, &lambda) + material.get_bsdf(&UniversalTextureEvaluator, &ctx, &mut lambda) } else { - material.get_bsdf(&BasicTextureEvaluator, &ctx, &lambda) + material.get_bsdf(&BasicTextureEvaluator, &ctx, &mut lambda) }; if lambda.secondary_terminated() { @@ -658,8 +694,16 @@ impl CpuWavefrontRenderer { "NEE_D0[{n}] pixel={:?} ls.l={:?} ls.pdf={:.6} f={:?} \ beta={:?} light_pdf={:.6} bsdf_pdf={:.6} \ r_u={:?} r_l={:?} l_d={:?}", - w.pixel_index, ls.l, ls.pdf, f, beta, - light_pdf, bsdf_pdf, r_u, r_l, l_d + w.pixel_index, + ls.l, + ls.pdf, + f, + beta, + light_pdf, + bsdf_pdf, + r_u, + r_l, + l_d ); } }