diff --git a/shared/src/bxdfs/complex.rs b/shared/src/bxdfs/complex.rs index 13328f8..aaf6eef 100644 --- a/shared/src/bxdfs/complex.rs +++ b/shared/src/bxdfs/complex.rs @@ -1,7 +1,5 @@ -use crate::core::bsdf::BSDF; -use crate::core::bxdf::{ - BSDFSample, BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode, -}; +use crate::core::bsdf::{BSDF, BSDFSample}; +use crate::core::bxdf::{BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode}; use crate::core::color::RGB; use crate::core::geometry::{ Normal3f, Point2f, Vector3f, abs_cos_theta, cos_theta, same_hemisphere, diff --git a/shared/src/bxdfs/conductor.rs b/shared/src/bxdfs/conductor.rs index e486c9b..6db1e8b 100644 --- a/shared/src/bxdfs/conductor.rs +++ b/shared/src/bxdfs/conductor.rs @@ -1,6 +1,5 @@ -use crate::core::bxdf::{ - BSDFSample, BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode, -}; +use crate::core::bsdf::BSDFSample; +use crate::core::bxdf::{BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode}; use crate::core::geometry::{ Normal3f, Point2f, Vector3f, VectorLike, abs_cos_theta, same_hemisphere, }; diff --git a/shared/src/bxdfs/dielectric.rs b/shared/src/bxdfs/dielectric.rs index 042396c..d5b3d9c 100644 --- a/shared/src/bxdfs/dielectric.rs +++ b/shared/src/bxdfs/dielectric.rs @@ -1,6 +1,5 @@ -use crate::core::bxdf::{ - BSDFSample, BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode, -}; +use crate::core::bsdf::BSDFSample; +use crate::core::bxdf::{BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode}; use crate::core::geometry::{ Normal3f, Point2f, Vector3f, VectorLike, abs_cos_theta, cos_theta, same_hemisphere, }; diff --git a/shared/src/bxdfs/diffuse.rs b/shared/src/bxdfs/diffuse.rs index e4743b2..213a42a 100644 --- a/shared/src/bxdfs/diffuse.rs +++ b/shared/src/bxdfs/diffuse.rs @@ -1,6 +1,5 @@ -use crate::core::bxdf::{ - BSDFSample, BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode, -}; +use crate::core::bsdf::BSDFSample; +use crate::core::bxdf::{BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode}; use crate::core::geometry::{Point2f, Vector3f, abs_cos_theta, same_hemisphere}; use crate::spectra::SampledSpectrum; use crate::utils::sampling::{cosine_hemisphere_pdf, sample_cosine_hemisphere}; diff --git a/shared/src/bxdfs/layered.rs b/shared/src/bxdfs/layered.rs index db2d6f7..65e9c37 100644 --- a/shared/src/bxdfs/layered.rs +++ b/shared/src/bxdfs/layered.rs @@ -1,9 +1,8 @@ use super::ConductorBxDF; use super::DielectricBxDF; use super::DiffuseBxDF; -use crate::core::bxdf::{ - BSDFSample, BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode, -}; +use crate::core::bsdf::BSDFSample; +use crate::core::bxdf::{BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode}; use crate::core::color::RGB; use crate::core::geometry::{ Frame, Normal3f, Point2f, Vector3f, VectorLike, abs_cos_theta, cos_theta, same_hemisphere, diff --git a/shared/src/bxdfs/measured.rs b/shared/src/bxdfs/measured.rs index 51add6d..2eae9af 100644 --- a/shared/src/bxdfs/measured.rs +++ b/shared/src/bxdfs/measured.rs @@ -1,6 +1,5 @@ -use crate::core::bxdf::{ - BSDFSample, BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode, -}; +use crate::core::bsdf::BSDFSample; +use crate::core::bxdf::{BxDFFlags, BxDFReflTransFlags, BxDFTrait, FArgs, TransportMode}; use crate::core::geometry::{ Point2f, Vector3f, VectorLike, abs_cos_theta, cos_theta, same_hemisphere, spherical_direction, spherical_theta, diff --git a/shared/src/core/bsdf.rs b/shared/src/core/bsdf.rs index 4377a4b..5b1415f 100644 --- a/shared/src/core/bsdf.rs +++ b/shared/src/core/bsdf.rs @@ -1,5 +1,5 @@ use crate::Float; -use crate::core::bxdf::{BSDFSample, BxDF, BxDFFlags, BxDFTrait, FArgs, TransportMode}; +use crate::core::bxdf::{BxDF, BxDFFlags, BxDFTrait, FArgs, TransportMode}; use crate::core::geometry::{Frame, Normal3f, Point2f, Vector3f, VectorLike}; use crate::spectra::SampledSpectrum; use crate::utils::Ptr; @@ -124,3 +124,67 @@ impl BSDF { } } } + +#[derive(Debug, Clone)] +pub struct BSDFSample { + pub f: SampledSpectrum, + pub wi: Vector3f, + pub pdf: Float, + pub flags: BxDFFlags, + pub eta: Float, + pub pdf_is_proportional: bool, +} + +impl Default for BSDFSample { + fn default() -> Self { + Self { + f: SampledSpectrum::default(), + wi: Vector3f::default(), + pdf: 0.0, + flags: BxDFFlags::empty(), + eta: 1.0, + pdf_is_proportional: false, + } + } +} + +impl BSDFSample { + pub fn new( + f: SampledSpectrum, + wi: Vector3f, + pdf: Float, + flags: BxDFFlags, + eta: Float, + pdf_is_proportional: bool, + ) -> Self { + Self { + f, + wi, + pdf, + flags, + eta, + pdf_is_proportional, + } + } + + #[inline] + pub fn is_reflective(&self) -> bool { + self.flags.is_reflective() + } + #[inline] + pub fn is_transmissive(&self) -> bool { + self.flags.is_transmissive() + } + #[inline] + pub fn is_diffuse(&self) -> bool { + self.flags.is_diffuse() + } + #[inline] + pub fn is_glossy(&self) -> bool { + self.flags.is_glossy() + } + #[inline] + pub fn is_specular(&self) -> bool { + self.flags.is_specular() + } +} diff --git a/shared/src/core/bxdf.rs b/shared/src/core/bxdf.rs index a56307e..d9434d5 100644 --- a/shared/src/core/bxdf.rs +++ b/shared/src/core/bxdf.rs @@ -1,4 +1,5 @@ use crate::bxdfs::*; +use crate::core::bsdf::BSDFSample; use crate::core::geometry::{Point2f, Vector3f, abs_cos_theta}; use crate::spectra::SampledSpectrum; use crate::utils::sampling::{sample_uniform_hemisphere, uniform_hemisphere_pdf}; @@ -82,70 +83,6 @@ impl Not for TransportMode { } } -#[derive(Debug, Clone)] -pub struct BSDFSample { - pub f: SampledSpectrum, - pub wi: Vector3f, - pub pdf: Float, - pub flags: BxDFFlags, - pub eta: Float, - pub pdf_is_proportional: bool, -} - -impl Default for BSDFSample { - fn default() -> Self { - Self { - f: SampledSpectrum::default(), - wi: Vector3f::default(), - pdf: 0.0, - flags: BxDFFlags::empty(), - eta: 1.0, - pdf_is_proportional: false, - } - } -} - -impl BSDFSample { - pub fn new( - f: SampledSpectrum, - wi: Vector3f, - pdf: Float, - flags: BxDFFlags, - eta: Float, - pdf_is_proportional: bool, - ) -> Self { - Self { - f, - wi, - pdf, - flags, - eta, - pdf_is_proportional, - } - } - - #[inline] - pub fn is_reflective(&self) -> bool { - self.flags.is_reflective() - } - #[inline] - pub fn is_transmissive(&self) -> bool { - self.flags.is_transmissive() - } - #[inline] - pub fn is_diffuse(&self) -> bool { - self.flags.is_diffuse() - } - #[inline] - pub fn is_glossy(&self) -> bool { - self.flags.is_glossy() - } - #[inline] - pub fn is_specular(&self) -> bool { - self.flags.is_specular() - } -} - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct FArgs { diff --git a/shared/src/core/film.rs b/shared/src/core/film.rs index f878065..e13e52b 100644 --- a/shared/src/core/film.rs +++ b/shared/src/core/film.rs @@ -13,7 +13,7 @@ use crate::spectra::{ ConstantSpectrum, DenselySampledSpectrum, LAMBDA_MAX, LAMBDA_MIN, N_SPECTRUM_SAMPLES, PiecewiseLinearSpectrum, RGBColorSpace, SampledSpectrum, SampledWavelengths, colorspace, }; -use crate::utils::containers::Array2D; +use crate::utils::containers::DeviceArray2D; use crate::utils::math::linear_least_squares; use crate::utils::math::{SquareMatrix, wrap_equal_area_square}; use crate::utils::sampling::VarianceEstimator; @@ -28,7 +28,7 @@ pub struct RGBFilm { pub write_fp16: bool, pub filter_integral: Float, pub output_rgbf_from_sensor_rgb: SquareMatrix, - pub pixels: Array2D, + pub pixels: DeviceArray2D, } #[repr(C)] @@ -215,7 +215,7 @@ pub struct GBufferFilm { pub base: FilmBase, output_from_render: AnimatedTransform, apply_inverse: bool, - pixels: Array2D, + pixels: DeviceArray2D, colorspace: RGBColorSpace, max_component_value: Float, write_fp16: bool, @@ -346,7 +346,7 @@ pub struct SpectralFilm { pub max_component_value: Float, pub write_fp16: bool, pub filter_integral: Float, - pub pixels: Array2D, + pub pixels: DeviceArray2D, pub output_rgbf_from_sensor_rgb: SquareMatrix, pub bucket_sums: *mut f64, pub weight_sums: *mut f64, diff --git a/shared/src/core/filter.rs b/shared/src/core/filter.rs index 854a4f9..4cf2b81 100644 --- a/shared/src/core/filter.rs +++ b/shared/src/core/filter.rs @@ -1,7 +1,7 @@ use crate::core::geometry::{Bounds2f, Bounds2i, Point2f, Point2i, Vector2f}; use crate::core::pbrt::Float; use crate::filters::*; -use crate::utils::containers::Array2D; +use crate::utils::containers::DeviceArray2D; use crate::utils::math::{gaussian, gaussian_integral, lerp, sample_tent, windowed_sinc}; use crate::utils::sampling::DevicePiecewiseConstant2D; use enum_dispatch::enum_dispatch; @@ -16,7 +16,7 @@ pub struct FilterSample { pub struct FilterSampler { pub domain: Bounds2f, pub distrib: DevicePiecewiseConstant2D, - pub f: Array2D, + pub f: DeviceArray2D, } impl FilterSampler { diff --git a/shared/src/core/image.rs b/shared/src/core/image.rs index 3f60c9d..7d3da0a 100644 --- a/shared/src/core/image.rs +++ b/shared/src/core/image.rs @@ -2,7 +2,7 @@ use crate::Float; use crate::core::color::{ColorEncoding, ColorEncodingTrait, LINEAR}; use crate::core::geometry::{Bounds2f, Point2f, Point2fi, Point2i}; use crate::utils::Ptr; -use crate::utils::containers::Array2D; +use crate::utils::containers::DeviceArray2D; use crate::utils::math::{f16_to_f32, lerp, square}; use core::hash; use half::f16; diff --git a/shared/src/core/sampler.rs b/shared/src/core/sampler.rs index 2127dba..5f9faef 100644 --- a/shared/src/core/sampler.rs +++ b/shared/src/core/sampler.rs @@ -3,7 +3,7 @@ use crate::core::geometry::{Bounds2f, Point2f, Point2i, Vector2f}; use crate::core::options::{PBRTOptions, get_options}; use crate::core::pbrt::{Float, ONE_MINUS_EPSILON, PI, PI_OVER_2, PI_OVER_4}; use crate::utils::Ptr; -use crate::utils::containers::Array2D; +use crate::utils::containers::DeviceArray2D; use crate::utils::math::{ BinaryPermuteScrambler, DeviceDigitPermutation, FastOwenScrambler, NoRandomizer, OwenScrambler, PRIME_TABLE_SIZE, Scrambler, clamp, encode_morton_2, inverse_radical_inverse, lerp, log2_int, @@ -80,7 +80,7 @@ impl SamplerTrait for IndependentSampler { } } -const MAX_HALTON_RESOLUTION: i32 = 128; +pub const MAX_HALTON_RESOLUTION: i32 = 128; #[repr(C)] #[derive(Debug, Default, Clone, PartialEq, Eq, Copy)] diff --git a/shared/src/shapes/bilinear.rs b/shared/src/shapes/bilinear.rs index d0754a0..53eb6b5 100644 --- a/shared/src/shapes/bilinear.rs +++ b/shared/src/shapes/bilinear.rs @@ -5,6 +5,7 @@ use crate::core::geometry::{ use crate::core::interaction::{Interaction, InteractionTrait, SurfaceInteraction}; use crate::core::pbrt::{Float, gamma}; use crate::core::shape::{Shape, ShapeIntersection, ShapeSample, ShapeSampleContext, ShapeTrait}; +use crate::utils::Ptr; use crate::utils::Transform; use crate::utils::math::{SquareMatrix, clamp, difference_of_products, lerp, quadratic}; use crate::utils::mesh::DeviceBilinearPatchMesh; @@ -46,15 +47,15 @@ impl BilinearIntersection { #[repr(C)] #[derive(Debug, Clone, Copy)] pub struct BilinearPatchShape { - pub mesh: DeviceBilinearPatchMesh, - pub blp_index: u32, + pub mesh: Ptr, + pub blp_index: i32, pub area: Float, pub rectangle: bool, } impl BilinearPatchShape { pub const MIN_SPHERICAL_SAMPLE_AREA: Float = 1e-4; - fn mesh(&self) -> DeviceBilinearPatchMesh { + fn mesh(&self) -> Ptr { self.mesh } @@ -117,7 +118,7 @@ impl BilinearPatchShape { } #[cfg(not(target_os = "cuda"))] - pub fn new(mesh: DeviceBilinearPatchMesh, blp_index: u32) -> Self { + pub fn new(mesh: Ptr, blp_index: i32) -> Self { let mut bp = BilinearPatchShape { mesh, blp_index, diff --git a/shared/src/shapes/triangle.rs b/shared/src/shapes/triangle.rs index 6058f96..951367a 100644 --- a/shared/src/shapes/triangle.rs +++ b/shared/src/shapes/triangle.rs @@ -9,6 +9,7 @@ use crate::core::interaction::{ }; use crate::core::pbrt::gamma; use crate::core::shape::{ShapeIntersection, ShapeSample, ShapeSampleContext, ShapeTrait}; +use crate::utils::Ptr; use crate::utils::math::{difference_of_products, square}; use crate::utils::mesh::DeviceTriangleMesh; use crate::utils::sampling::{ @@ -34,7 +35,7 @@ impl TriangleIntersection { #[repr(C)] #[derive(Clone, Copy, Debug)] pub struct TriangleShape { - pub mesh: DeviceTriangleMesh, + pub mesh: Ptr, pub tri_index: i32, } @@ -111,11 +112,11 @@ impl TriangleShape { } } - pub fn new(mesh: DeviceTriangleMesh, tri_index: i32) -> Self { + pub fn new(mesh: Ptr, tri_index: i32) -> Self { Self { mesh, tri_index } } - pub fn get_mesh(&self) -> DeviceTriangleMesh { + pub fn get_mesh(&self) -> Ptr { self.mesh } diff --git a/shared/src/textures/image.rs b/shared/src/textures/image.rs index e8ff30d..336f895 100644 --- a/shared/src/textures/image.rs +++ b/shared/src/textures/image.rs @@ -83,6 +83,7 @@ pub struct GPUFloatImageTexture { } impl GPUFloatImageTexture { + #[allow(unused_variables)] pub fn evaluate(&self, ctx: &TextureEvalContext) -> Float { #[cfg(not(feature = "cuda"))] { diff --git a/shared/src/utils/containers.rs b/shared/src/utils/containers.rs index 9d5ebe9..bcb2ffa 100644 --- a/shared/src/utils/containers.rs +++ b/shared/src/utils/containers.rs @@ -22,16 +22,16 @@ impl Interpolatable for T where #[repr(C)] #[derive(Debug, Clone, Copy)] -pub struct Array2D { +pub struct DeviceArray2D { pub values: *mut T, pub extent: Bounds2i, pub stride: i32, } -unsafe impl Send for Array2D {} -unsafe impl Sync for Array2D {} +unsafe impl Send for DeviceArray2D {} +unsafe impl Sync for DeviceArray2D {} -impl Array2D { +impl DeviceArray2D { #[inline] pub fn x_size(&self) -> u32 { (self.extent.p_max.x() - self.extent.p_min.x()) as u32 @@ -90,7 +90,7 @@ impl Array2D { } } -impl Index for Array2D { +impl Index for DeviceArray2D { type Output = T; #[inline(always)] fn index(&self, p: Point2i) -> &Self::Output { @@ -98,20 +98,20 @@ impl Index for Array2D { } } -impl IndexMut for Array2D { +impl IndexMut for DeviceArray2D { fn index_mut(&mut self, p: Point2i) -> &mut Self::Output { self.get_mut(p) } } -impl Index<(i32, i32)> for Array2D { +impl Index<(i32, i32)> for DeviceArray2D { type Output = T; fn index(&self, (x, y): (i32, i32)) -> &Self::Output { &self[Point2i::new(x, y)] } } -impl IndexMut<(i32, i32)> for Array2D { +impl IndexMut<(i32, i32)> for DeviceArray2D { fn index_mut(&mut self, (x, y): (i32, i32)) -> &mut Self::Output { &mut self[Point2i::new(x, y)] } diff --git a/shared/src/utils/ptr.rs b/shared/src/utils/ptr.rs index 37e6a31..88115c9 100644 --- a/shared/src/utils/ptr.rs +++ b/shared/src/utils/ptr.rs @@ -16,7 +16,7 @@ impl Copy for Ptr {} impl PartialEq for Ptr { fn eq(&self, other: &Self) -> bool { - self.ptr == other.ptr + std::ptr::addr_eq(self.ptr, other.ptr) } } diff --git a/shared/src/utils/sampling.rs b/shared/src/utils/sampling.rs index ff122e5..e88ce75 100644 --- a/shared/src/utils/sampling.rs +++ b/shared/src/utils/sampling.rs @@ -3,7 +3,7 @@ use crate::core::geometry::{ Bounds2f, Frame, Point2f, Point2i, Point3f, Vector2f, Vector2i, Vector3f, VectorLike, }; use crate::core::pbrt::{RARE_EVENT_CONDITION_MET, RARE_EVENT_TOTAL_CALLS}; -use crate::utils::containers::Array2D; +use crate::utils::containers::DeviceArray2D; use crate::utils::find_interval; use crate::utils::math::{ catmull_rom_weights, clamp, difference_of_products, evaluate_polynomial, lerp, logistic, @@ -821,38 +821,10 @@ impl DevicePiecewiseConstant2D { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DeviceSummedAreaTable { - pub sum: Array2D, + pub sum: DeviceArray2D, } impl DeviceSummedAreaTable { - // pub fn new(values: &Array2D) -> Self { - // let width = values.x_size(); - // let height = values.y_size(); - // - // let mut sum = Array2D::::new_with_dims(width, height); - // sum[(0, 0)] = values[(0, 0)] as f64; - // - // for x in 1..width { - // sum[(x, 0)] = values[(x as i32, 0)] as f64 + sum[(x - 1, 0)]; - // } - // - // for y in 1..height { - // sum[(0, y)] = values[(0, y as i32)] as f64 + sum[(0, y - 1)]; - // } - // - // for y in 1..height { - // for x in 1..width { - // let term = values[(x as i32, y as i32)] as f64; - // let left = sum[(x - 1, y)]; - // let up = sum[(x, y - 1)]; - // let diag = sum[(x - 1, y - 1)]; - // - // sum[(x, y)] = term + left + up - diag; - // } - // } - // - // Self { sum } - // } // pub fn integral(&self, extent: Bounds2f) -> Float { let s = self.lookup(extent.p_max.x(), extent.p_max.y()) @@ -902,7 +874,7 @@ impl DeviceSummedAreaTable { #[derive(Debug, Copy, Clone)] pub struct DeviceWindowedPiecewiseConstant2D { pub sat: DeviceSummedAreaTable, - pub func: Array2D, + pub func: DeviceArray2D, } impl DeviceWindowedPiecewiseConstant2D { diff --git a/src/core/color.rs b/src/core/color.rs index 470af75..624136a 100644 --- a/src/core/color.rs +++ b/src/core/color.rs @@ -1,7 +1,7 @@ use crate::utils::read_float_file; -use anyhow::Error; +use anyhow::Result; use shared::Float; -use shared::core::color::{Coeffs, RES, RGBToSpectrumTable}; +use shared::core::color::{RES, RGBToSpectrumTable}; use std::ops::Deref; use std::path::Path; diff --git a/src/core/film.rs b/src/core/film.rs index 0dd08f2..30b53ef 100644 --- a/src/core/film.rs +++ b/src/core/film.rs @@ -13,7 +13,7 @@ use shared::spectra::cie::SWATCHES_RAW; use shared::spectra::{ DenselySampledSpectrum, LAMBDA_MAX, LAMBDA_MIN, PiecewiseLinearSpectrum, RGBColorSpace, }; -use shared::utils::containers::Array2D; +use shared::utils::containers::DeviceArray2D; use shared::utils::math::{SquareMatrix, linear_least_squares}; use shared::utils::{AnimatedTransform, AtomicFloat}; use std::cmp::Ordering; @@ -196,7 +196,7 @@ pub trait PixelSensorHost { impl PixelSensorHost for PixelSensor {} struct SpectralFilmStorage { - pixels: Array2D, + pixels: DeviceArray2D, bucket_sums: Vec, weight_sums: Vec, bucket_splats: Vec, @@ -228,7 +228,7 @@ impl SpectralFilmHost { bucket_splats.push(AtomicFloat::new(0.0)); } - let mut pixels = Array2D::::new(base.pixel_bounds); + let mut pixels = DeviceArray2D::::new(base.pixel_bounds); let p_sums_base = bucket_sums.as_ptr() as *mut f64; let p_weights_base = weight_sums.as_ptr() as *mut f64; @@ -266,7 +266,7 @@ impl SpectralFilmHost { filter_integral: base.filter.integral(), output_rgbf_from_sensor_rgb: SquareMatrix::identity(), // Logic omitted - pixels: Array2D { + pixels: DeviceArray2D { values: storage.pixels.as_mut_ptr(), extent: base.pixel_bounds, stride: base.pixel_bounds.max.x - base.pixel_bounds.min.x, @@ -305,7 +305,7 @@ impl GBufferFilmHost { let sensor = unsafe { &*sensor_ptr }; let output_rgbf_from_sensor_rgb = colorspace.rgb_from_xyz * sensor.xyz_from_sensor_rgb; let filter_integral = base.filter.integral(); - let pixels = Array2D::new(base.pixel_bounds); + let pixels = DeviceArray2D::new(base.pixel_bounds); let device = GBufferFilm { base: base.clone(), diff --git a/src/core/filter.rs b/src/core/filter.rs index fbb8399..702f3b5 100644 --- a/src/core/filter.rs +++ b/src/core/filter.rs @@ -4,7 +4,7 @@ use shared::Float; use shared::core::filter::{Filter, FilterSampler}; use shared::core::geometry::{Bounds2f, Point2f, Vector2f}; use shared::filters::*; -use shared::utils::containers::Array2D; +use shared::utils::containers::DeviceArray2D; pub trait FilterFactory { fn create(name: &str, params: &ParameterDictionary, loc: &FileLoc) -> Result; @@ -71,7 +71,7 @@ impl CreateFilterSampler for FilterSampler { let nx = (32.0 * radius.x()) as usize; let ny = (32.0 * radius.y()) as usize; - let mut f = Array2D::new_with_dims(nx, ny); + let mut f = DeviceArray2D::new_with_dims(nx, ny); for y in 0..f.y_size() { for x in 0..f.x_size() { let p = domain.lerp(Point2f::new( diff --git a/src/core/image/mod.rs b/src/core/image/mod.rs index 4a2305c..c32a8ca 100644 --- a/src/core/image/mod.rs +++ b/src/core/image/mod.rs @@ -5,10 +5,11 @@ use shared::core::color::ColorEncoding; use shared::core::color::LINEAR; use shared::core::geometry::{Bounds2f, Point2f, Point2i}; use shared::core::image::{DeviceImage, ImageBase, PixelFormat, Pixels, WrapMode, WrapMode2D}; -use shared::utils::containers::Array2D; +use shared::utils::containers::DeviceArray2D; use shared::utils::math::square; use smallvec::{SmallVec, smallvec}; use std::ops::{Deref, DerefMut}; +use std::sync::Arc; pub mod io; pub mod metadata; @@ -469,14 +470,14 @@ impl Image { Self::from_storage(new_storage, res, new_names, self.encoding()) } - pub fn get_sampling_distribution(&self, dxd_a: F, domain: Bounds2f) -> Array2D + pub fn get_sampling_distribution(&self, dxd_a: F, domain: Bounds2f) -> DeviceArray2D where F: Fn(Point2f) -> Float + Sync + Send, { let width = self.resolution().x(); let height = self.resolution().y(); - let mut dist = Array2D::new_with_dims(width as usize, height as usize); + let mut dist = DeviceArray2D::new_with_dims(width as usize, height as usize); dist.values .par_chunks_mut(width as usize) @@ -499,7 +500,7 @@ impl Image { dist } - pub fn get_sampling_distribution_uniform(&self) -> Array2D { + pub fn get_sampling_distribution_uniform(&self) -> DeviceArray2D { let default_domain = Bounds2f::from_points(Point2f::new(0.0, 0.0), Point2f::new(1.0, 1.0)); self.get_sampling_distribution(|_| 1.0, default_domain) diff --git a/src/core/light.rs b/src/core/light.rs index 34d9c94..8e1b059 100644 --- a/src/core/light.rs +++ b/src/core/light.rs @@ -1,17 +1,16 @@ +use shared::core::light::Light; use crate::core::spectrum::SPECTRUM_CACHE; use crate::core::texture::FloatTexture; use crate::utils::containers::InternCache; use crate::utils::{Arena, FileLoc, ParameterDictionary}; -use log::error; +use anyhow::{Result, anyhow}; use shared::core::camera::CameraTransform; -use shared::core::light::Light; use shared::core::medium::Medium; use shared::core::shape::Shape; use shared::core::spectrum::Spectrum; use shared::lights::*; use shared::spectra::{DenselySampledSpectrum, RGBColorSpace}; use shared::utils::Transform; -use std::fmt::Error; pub fn lookup_spectrum(s: &Spectrum) -> DenselySampledSpectrum { let cache = SPECTRUM_CACHE.get_or_init(InternCache::new); @@ -29,7 +28,7 @@ pub trait CreateLight { shape: &Shape, alpha_text: &FloatTexture, colorspace: Option<&RGBColorSpace>, - ) -> Result; + ) -> Result; } pub trait LightFactory { @@ -44,7 +43,7 @@ pub trait LightFactory { alpha_tex: &FloatTexture, colorspace: Option<&RGBColorSpace>, camera_transform: CameraTransform, - ) -> Result; + ) -> Result; } impl LightFactory for Light { @@ -59,7 +58,7 @@ impl LightFactory for Light { alpha_tex: &FloatTexture, colorspace: Option<&RGBColorSpace>, camera_transform: CameraTransform, - ) -> Result { + ) -> Result { match name { "diffuse" => DiffuseAreaLight::create( name, @@ -130,7 +129,7 @@ impl LightFactory for Light { colorspace, loc, )?, - _ => Err(error!(loc, "unknown light type: \"{}\"", name)), + _ => Err(anyhow!(loc, "unknown light type: \"{}\"", name)), } } } diff --git a/src/core/material.rs b/src/core/material.rs index 908ade0..ea937c2 100644 --- a/src/core/material.rs +++ b/src/core/material.rs @@ -2,10 +2,10 @@ use crate::Arena; use crate::core::image::Image; use crate::utils::TextureParameterDictionary; use crate::utils::error::FileLoc; +use anyhow::{Result, anyhow}; use shared::core::material::Material; use shared::materials::*; use std::collections::HashMap; -use std::fmt::Error; use std::sync::Arc; pub trait CreateMaterial: Sized { @@ -15,7 +15,7 @@ pub trait CreateMaterial: Sized { named_materials: &HashMap, loc: &FileLoc, arena: &mut Arena, - ) -> Result; + ) -> Result; } pub trait MaterialFactory { @@ -26,7 +26,7 @@ pub trait MaterialFactory { named_materials: HashMap, loc: FileLoc, arena: &mut Arena, - ) -> Result; + ) -> Result; } impl MaterialFactory for Material { @@ -37,7 +37,7 @@ impl MaterialFactory for Material { named_materials: HashMap, loc: FileLoc, arena: &mut Arena, - ) -> Result { + ) -> Result { match name { "diffuse" => { DiffuseMaterial::create(parameters, normal_map, named_materials, loc, arena)? @@ -77,7 +77,7 @@ impl MaterialFactory for Material { } "mix" => MixMaterial::create(parameters, normal_map, named_materials, loc, arena)?, - _ => Err(format!("Material type '{}' unknown at {}", $name, $loc)), + _ => Err(anyhow!("Material type '{}' unknown at {}", $name, $loc)), } } } diff --git a/src/core/scene/builder.rs b/src/core/scene/builder.rs index 470960e..443c356 100644 --- a/src/core/scene/builder.rs +++ b/src/core/scene/builder.rs @@ -6,6 +6,7 @@ use crate::utils::parameters::{ParameterDictionary, ParsedParameterVector}; use crate::utils::parser::ParserTarget; use shared::Float; use shared::core::camera::CameraTransform; +use shared::core::geometry::Vector3f; use shared::core::options::RenderingCoordinateSystem; use shared::spectra::RGBColorSpace; use shared::utils::transform::{AnimatedTransform, Transform, look_at}; diff --git a/src/core/scene/entities.rs b/src/core/scene/entities.rs index 2f7abed..702b253 100644 --- a/src/core/scene/entities.rs +++ b/src/core/scene/entities.rs @@ -1,3 +1,8 @@ +use crate::utils::{FileLoc, ParameterDictionary}; +use shared::core::camera::CameraTransform; +use shared::utils::{AnimatedTransform, Transform}; +use std::sync::Arc; + #[derive(Clone, Debug)] pub enum MaterialRef { Index(usize), diff --git a/src/core/scene/scene.rs b/src/core/scene/scene.rs index 19c5d19..67db37b 100644 --- a/src/core/scene/scene.rs +++ b/src/core/scene/scene.rs @@ -6,7 +6,7 @@ use crate::core::material::MaterialFactory; use crate::core::texture::{FloatTexture, SpectrumTexture}; use crate::utils::arena::Arena; use crate::utils::error::FileLoc; -use crate::utils::parallel::{AsyncJob, run_async}; +use crate::utils::parallel::run_async; use crate::utils::parameters::{NamedTextures, ParameterDictionary, TextureParameterDictionary}; use crate::utils::{Upload, resolve_filename}; use parking_lot::Mutex; @@ -18,7 +18,7 @@ use shared::core::filter::Filter; use shared::core::light::Light; use shared::core::material::Material; use shared::core::medium::{Medium, MediumInterface}; -use shared::core::primitive::{GeometricPrimitive, Primitive, PrimitiveTrait, SimplePrimitive}; +use shared::core::primitive::{GeometricPrimitive, Primitive, SimplePrimitive}; use shared::core::sampler::Sampler; use shared::core::shape::Shape; use shared::core::texture::SpectrumType; diff --git a/src/core/scene/state.rs b/src/core/scene/state.rs index da140fd..d1e41b8 100644 --- a/src/core/scene/state.rs +++ b/src/core/scene/state.rs @@ -1,3 +1,12 @@ +use super::{SceneEntity, TextureSceneEntity}; +use crate::core::image::Image; +use crate::core::light::Light; +use crate::core::medium::Medium; +use crate::core::texture::{FloatTexture, SpectrumTexture}; +use crate::utils::parallel::AsyncJob; +use std::collections::{HashMap, HashSet}; +use std::sync::Arc; + #[derive(Default)] pub struct TextureState { pub serial_float_textures: Vec<(String, TextureSceneEntity)>, diff --git a/src/core/texture.rs b/src/core/texture.rs index a1316a9..f262cd6 100644 --- a/src/core/texture.rs +++ b/src/core/texture.rs @@ -37,7 +37,7 @@ pub enum FloatTexture { Checkerboard(FloatCheckerboardTexture), Dots(FloatDotsTexture), FBm(FBmTexture), - Ptex(FloatPtexTexture), + // Ptex(FloatPtexTexture), Windy(WindyTexture), Wrinkled(WrinkledTexture), } diff --git a/src/lights/diffuse.rs b/src/lights/diffuse.rs index 21f403f..ebd5851 100644 --- a/src/lights/diffuse.rs +++ b/src/lights/diffuse.rs @@ -7,10 +7,12 @@ use crate::core::texture::FloatTexture; use crate::utils::{Arena, FileLoc, ParameterDictionary, Upload, resolve_filename}; use anyhow::{Result, anyhow}; use shared::core::geometry::Point2i; +use shared::core::image::DeviceImage; use shared::core::light::{Light, LightBase, LightType}; use shared::core::medium::{Medium, MediumInterface}; use shared::core::shape::{Shape, ShapeTrait}; use shared::core::spectrum::Spectrum; +use shared::core::texture::GPUFloatTexture; use shared::core::texture::{SpectrumType, TextureEvalContext}; use shared::lights::DiffuseAreaLight; use shared::spectra::RGBColorSpace; diff --git a/src/lights/distant.rs b/src/lights/distant.rs index 3941254..0c86c26 100644 --- a/src/lights/distant.rs +++ b/src/lights/distant.rs @@ -2,8 +2,9 @@ use crate::core::light::{CreateLight, lookup_spectrum}; use crate::core::spectrum::spectrum_to_photometric; use crate::core::texture::FloatTexture; use crate::utils::{Arena, FileLoc, ParameterDictionary}; +use anyhow::Result; use shared::Float; -use shared::core::geometry::{Point3, Point3f, Vector3f, VectorLike}; +use shared::core::geometry::{Point3f, VectorLike}; use shared::core::light::{Light, LightBase, LightType}; use shared::core::medium::{Medium, MediumInterface}; use shared::core::shape::Shape; @@ -11,8 +12,7 @@ use shared::core::spectrum::Spectrum; use shared::core::texture::SpectrumType; use shared::lights::DistantLight; use shared::spectra::RGBColorSpace; -use shared::utils::Transform; -use std::fmt::Error; +use shared::utils::{Ptr, Transform}; pub trait CreateDistantLight { fn new(render_from_light: Transform, le: Spectrum, scale: Float) -> Self; @@ -46,7 +46,7 @@ impl CreateLight for DistantLight { _shape: &Shape, _alpha_text: &FloatTexture, colorspace: Option<&RGBColorSpace>, - ) -> Result { + ) -> Result { let l = parameters .get_one_spectrum( "L", diff --git a/src/lights/goniometric.rs b/src/lights/goniometric.rs index b60a148..11ab95d 100644 --- a/src/lights/goniometric.rs +++ b/src/lights/goniometric.rs @@ -6,10 +6,8 @@ use crate::core::spectrum::spectrum_to_photometric; use crate::core::texture::FloatTexture; use crate::utils::sampling::PiecewiseConstant2D; use crate::utils::{Arena, FileLoc, ParameterDictionary, resolve_filename}; -use anyhow::{Result, anyhow}; -use shared::core::color::ColorEncoding; +use anyhow::{anyhow, Result}; use shared::core::geometry::Point2i; -use shared::core::image::PixelFormat; use shared::core::light::{Light, LightBase, LightType}; use shared::core::medium::{Medium, MediumInterface}; use shared::core::shape::Shape; @@ -67,7 +65,7 @@ impl CreateLight for GoniometricLight { shape: &Shape, alpha_text: &FloatTexture, colorspace: Option<&RGBColorSpace>, - ) -> Result { + ) -> Result { let i = params .get_one_spectrum( "I", @@ -81,20 +79,21 @@ impl CreateLight for GoniometricLight { Ptr::null() } else { let im = Image::read(Path::new(&filename), None) - .map_err(|e| error!(loc, "could not load image '{}': {}", filename, e))?; + .map_err(|e| anyhow!(loc, "could not load image '{}': {}", filename, e))?; let loaded = im.image; let res = loaded.resolution(); if loaded.has_any_infinite_pixels() { - return Err(error!( + return Err(anyhow!( loc, - "image '{}' has infinite pixels, not suitable for light", filename + "image '{}' has infinite pixels, not suitable for light", + filename )); } if res.x != res.y { - return Err(error!( + return Err(anyhow!( loc, "image resolution ({}, {}) is non-square; unlikely to be an equal-area map", res.x, @@ -133,9 +132,10 @@ fn convert_to_luminance_image(image: &Image, filename: &str, loc: &FileLoc) -> R let y_desc = image.get_channel_desc(&["Y"]); match (rgb_desc, y_desc) { - (Ok(_), Ok(_)) => Err(error!( + (Ok(_), Ok(_)) => Err(anyhow!( loc, - "image '{}' has both RGB and Y channels; ambiguous", filename + "image '{}' has both RGB and Y channels; ambiguous", + filename )), (Ok(_), Err(_)) => { @@ -159,9 +159,10 @@ fn convert_to_luminance_image(image: &Image, filename: &str, loc: &FileLoc) -> R Ok(image.clone()) } - (Err(_), Err(_)) => Err(error!( + (Err(_), Err(_)) => Err(anyhow!( loc, - "image '{}' has neither RGB nor Y channels", filename + "image '{}' has neither RGB nor Y channels", + filename )), } } diff --git a/src/lights/infinite.rs b/src/lights/infinite.rs index 9e76ff7..9d6f1a1 100644 --- a/src/lights/infinite.rs +++ b/src/lights/infinite.rs @@ -1,23 +1,22 @@ use crate::Arena; use crate::core::image::{Image, ImageIO}; use crate::core::spectrum::spectrum_to_photometric; -use crate::spectra::{get_colorspace_context, get_spectra_context}; +use crate::spectra::get_spectra_context; use crate::utils::sampling::{PiecewiseConstant2D, WindowedPiecewiseConstant2D}; -use crate::utils::{FileLoc, ParameterDictionary, Upload, resolve_filename}; +use crate::utils::{FileLoc, ParameterDictionary, resolve_filename}; use anyhow::{Result, anyhow}; use rayon::iter::{IndexedParallelIterator, ParallelIterator}; use rayon::prelude::ParallelSliceMut; use shared::core::camera::CameraTransform; use shared::core::geometry::{Bounds2f, Frame, Point2f, Point2i, Point3f, VectorLike, cos_theta}; -use shared::core::image::{PixelFormat, WrapMode}; +use shared::core::image::{DeviceImage, PixelFormat, WrapMode}; use shared::core::light::{Light, LightBase, LightType}; use shared::core::medium::MediumInterface; use shared::core::spectrum::Spectrum; use shared::core::texture::SpectrumType; use shared::lights::{ImageInfiniteLight, PortalInfiniteLight, UniformInfiniteLight}; use shared::spectra::RGBColorSpace; -use shared::utils::hash::hash_float; use shared::utils::math::{equal_area_sphere_to_square, equal_area_square_to_sphere}; use shared::utils::{Ptr, Transform}; use shared::{Float, PI}; @@ -41,7 +40,7 @@ impl CreateImageInfiniteLight for ImageInfiniteLight { render_from_light: Transform, medium_interface: MediumInterface, scale: Float, - image: Arc, + image: Arc, image_color_space: Arc, ) -> Self { let base = LightBase::new( @@ -80,7 +79,7 @@ impl CreateImageInfiniteLight for ImageInfiniteLight { let distrib = PiecewiseConstant2D::new(&data, n_u, n_v); - let slice = d.as_mut_slice(); + let slice = distrib.as_mut_slice(); let average = slice.iter().sum::() / slice.len() as Float; let mut all_zero = true; @@ -111,13 +110,13 @@ impl CreateImageInfiniteLight for ImageInfiniteLight { #[derive(Debug)] struct InfinitePortalLightStorage { image: Image, - distribution: DeviceWindowedPiecewiseConstant2D, + distribution: WindowedPiecewiseConstant2D, image_color_space: RGBColorSpace, } #[derive(Clone, Debug)] pub struct PortalInfiniteLightHost { - pub view: PortalInfiniteLight, + pub device: PortalInfiniteLight, pub filename: String, _storage: Arc, } @@ -241,7 +240,7 @@ impl CreatePortalInfiniteLight for PortalInfiniteLight { Bounds2f::from_points(Point2f::new(0., 0.), Point2f::new(1., 1.)), ); - let distribution = DeviceWindowedPiecewiseConstant2D::new(d); + let distribution = WindowedPiecewiseConstant2D::new(d); PortalInfiniteLight { base, diff --git a/src/lights/point.rs b/src/lights/point.rs index 930b31a..9ebf218 100644 --- a/src/lights/point.rs +++ b/src/lights/point.rs @@ -2,6 +2,7 @@ use crate::core::light::{CreateLight, lookup_spectrum}; use crate::core::spectrum::spectrum_to_photometric; use crate::core::texture::FloatTexture; use crate::utils::{Arena, FileLoc, ParameterDictionary}; +use anyhow::Result; use shared::core::geometry::Point3f; use shared::core::light::{Light, LightBase, LightType}; use shared::core::medium::{Medium, MediumInterface}; @@ -10,9 +11,8 @@ use shared::core::spectrum::Spectrum; use shared::core::texture::SpectrumType; use shared::lights::PointLight; use shared::spectra::RGBColorSpace; -use shared::utils::Transform; +use shared::utils::{Ptr, Transform}; use shared::{Float, PI}; -use std::fmt::Error; pub trait CreatePointLight { fn new( @@ -51,7 +51,7 @@ impl CreateLight for PointLight { _shape: &Shape, _alpha: &FloatTexture, colorspace: Option<&RGBColorSpace>, - ) -> Result { + ) -> Result { let l = parameters .get_one_spectrum( "L", diff --git a/src/lights/projection.rs b/src/lights/projection.rs index f6340f2..41ec773 100644 --- a/src/lights/projection.rs +++ b/src/lights/projection.rs @@ -9,6 +9,7 @@ use shared::Float; use shared::core::geometry::{ Bounds2f, Point2f, Point2i, Point3f, Vector3f, VectorLike, cos_theta, }; +use shared::core::image::DeviceImage; use shared::core::light::{Light, LightBase, LightType}; use shared::core::medium::{Medium, MediumInterface}; use shared::core::shape::Shape; @@ -101,11 +102,11 @@ impl CreateLight for ProjectionLight { let filename = resolve_filename(¶meters.get_one_string("filename", "")); if filename.is_empty() { - return Err(error!(loc, "must provide filename for projection light")); + return Err(anyhow!(loc, "must provide filename for projection light")); } let im = Image::read(Path::new(&filename), None) - .map_err(|e| error!(loc, "could not load image '{}': {}", filename, e))?; + .map_err(|e| anyhow!(loc, "could not load image '{}': {}", filename, e))?; if im.image.has_any_infinite_pixels() { return Err(anyhow!( diff --git a/src/lights/sampler.rs b/src/lights/sampler.rs index 845282f..1e66946 100644 --- a/src/lights/sampler.rs +++ b/src/lights/sampler.rs @@ -1,7 +1,6 @@ use crate::utils::sampling::AliasTableHost; use shared::core::light::{Light, LightTrait}; use shared::spectra::{SampledSpectrum, SampledWavelengths}; -use shared::utils::sampling::AliasTable; use std::collections::HashMap; use std::sync::Arc; diff --git a/src/lights/spot.rs b/src/lights/spot.rs index 9a7abbb..051760d 100644 --- a/src/lights/spot.rs +++ b/src/lights/spot.rs @@ -3,6 +3,7 @@ use crate::core::light::{CreateLight, lookup_spectrum}; use crate::core::spectrum::spectrum_to_photometric; use crate::core::texture::FloatTexture; use crate::utils::{Arena, FileLoc, ParameterDictionary}; +use anyhow::Result; use shared::core::geometry::{Frame, Point3f, VectorLike}; use shared::core::light::{Light, LightBase, LightType}; use shared::core::medium::{Medium, MediumInterface}; @@ -11,10 +12,9 @@ use shared::core::spectrum::Spectrum; use shared::core::texture::SpectrumType; use shared::lights::SpotLight; use shared::spectra::RGBColorSpace; -use shared::utils::Transform; use shared::utils::math::radians; +use shared::utils::{Ptr, Transform}; use shared::{Float, PI}; -use std::fmt::Error; pub trait CreateSpotLight { fn new( @@ -30,7 +30,7 @@ pub trait CreateSpotLight { impl CreateSpotLight for SpotLight { fn new( render_from_light: Transform, - medium_interface: MediumInterface, + _medium_interface: MediumInterface, le: Spectrum, scale: shared::Float, cos_falloff_start: Float, @@ -63,7 +63,7 @@ impl CreateLight for SpotLight { _shape: &Shape, _alpha_tex: &FloatTexture, colorspace: Option<&RGBColorSpace>, - ) -> Result { + ) -> Result { let i = parameters .get_one_spectrum( "I", diff --git a/src/materials/complex.rs b/src/materials/complex.rs index 64782a4..61519ae 100644 --- a/src/materials/complex.rs +++ b/src/materials/complex.rs @@ -2,9 +2,10 @@ use crate::core::image::Image; use crate::core::material::CreateMaterial; use crate::spectra::get_colorspace_context; use crate::utils::{Arena, FileLoc, TextureParameterDictionary, Upload}; +use shared::bxdfs::HairBxDF; use shared::core::material::Material; use shared::core::spectrum::Spectrum; -use shared::core::texture::SpectrumType; +use shared::core::texture::{SpectrumTexture, SpectrumType}; use shared::materials::complex::*; use shared::spectra::RGBUnboundedSpectrum; // use shared::spectra::SampledWavelengths; @@ -35,7 +36,7 @@ impl CreateMaterial for HairMaterial { let stdcs = get_colorspace_context(); let default_rgb = HairBxDF::sigma_a_from_concentration(1.3, 0.0, stdcs); let spectrum = - Spectrum::RGBUnbounded(RGBUnboundedSpectrum::new(stdc.srgb, default_rgb)); + Spectrum::RGBUnbounded(RGBUnboundedSpectrum::new(stdcs.srgb, default_rgb)); let texture = SpectrumTexture::Constant(SpectrumConstantTexture::new(spectrum)); Some(Arc::new(texture)) } else { diff --git a/src/materials/conductor.rs b/src/materials/conductor.rs index 4dd783d..2522175 100644 --- a/src/materials/conductor.rs +++ b/src/materials/conductor.rs @@ -2,6 +2,7 @@ use crate::core::image::Image; use crate::core::material::CreateMaterial; // use crate::core::scattering::TrowbridgeReitzDistribution; use crate::utils::TextureParameterDictionary; +use anyhow::Result; use shared::core::material::Material; use shared::materials::ConductorMaterial; use std::sync::Arc; @@ -13,7 +14,7 @@ impl CreateMaterial for ConductorMaterial { _named_materials: &std::collections::HashMap, _loc: &crate::utils::FileLoc, _arena: &mut crate::Arena, - ) -> Result { + ) -> Result { todo!() } } diff --git a/src/materials/dielectric.rs b/src/materials/dielectric.rs index b3d3eaf..8db1f61 100644 --- a/src/materials/dielectric.rs +++ b/src/materials/dielectric.rs @@ -2,10 +2,10 @@ use crate::Arena; use crate::core::image::Image; use crate::core::material::CreateMaterial; use crate::utils::{FileLoc, TextureParameterDictionary}; +use anyhow::Result; use shared::core::material::Material; use shared::materials::{DielectricMaterial, ThinDielectricMaterial}; use std::collections::HashMap; -use std::fmt::Error; use std::sync::Arc; impl CreateMaterial for DielectricMaterial { @@ -15,7 +15,7 @@ impl CreateMaterial for DielectricMaterial { _named_materials: &HashMap, _loc: &FileLoc, _arena: &mut Arena, - ) -> Result { + ) -> Result { todo!() } } @@ -27,7 +27,7 @@ impl CreateMaterial for ThinDielectricMaterial { _named_materials: &HashMap, _loc: &FileLoc, _arena: &mut Arena, - ) -> Result { + ) -> Result { todo!() } } diff --git a/src/materials/diffuse.rs b/src/materials/diffuse.rs index 5e41f4b..15380dc 100644 --- a/src/materials/diffuse.rs +++ b/src/materials/diffuse.rs @@ -2,10 +2,10 @@ use crate::Arena; use crate::core::image::Image; use crate::core::material::CreateMaterial; use crate::utils::{FileLoc, TextureParameterDictionary}; +use anyhow::Result; use shared::core::material::Material; use shared::materials::{DiffuseMaterial, DiffuseTransmissionMaterial}; use std::collections::HashMap; -use std::fmt::Error; use std::sync::Arc; impl CreateMaterial for DiffuseMaterial { @@ -15,7 +15,7 @@ impl CreateMaterial for DiffuseMaterial { _named_materials: &HashMap, _loc: &FileLoc, _arena: &mut Arena, - ) -> Result { + ) -> Result { todo!() } } @@ -27,7 +27,7 @@ impl CreateMaterial for DiffuseTransmissionMaterial { _named_materials: &HashMap, _loc: &FileLoc, _arena: &mut Arena, - ) -> Result { + ) -> Result { todo!() } } diff --git a/src/materials/mix.rs b/src/materials/mix.rs index e318c98..fca91d1 100644 --- a/src/materials/mix.rs +++ b/src/materials/mix.rs @@ -1,23 +1,20 @@ -// use crate::core::image::Image; -// use crate::core::material::CreateMaterial; -// use shared::core::bsdf::BSDF; -// use shared::core::bssrdf::BSSRDF; -// use shared::core::material::{Material, MaterialEvalContext, MaterialTrait}; -// use shared::core::texture::{GPUFloatTexture, TextureEvaluator}; -// use shared::spectra::SampledWavelengths; -// use shared::utils::Ptr; use crate::core::image::Image; use crate::core::material::CreateMaterial; +use crate::utils::{Arena, FileLoc, TextureParameterDictionary}; +use anyhow::Result; +use shared::core::material::Material; use shared::materials::MixMaterial; +use std::collections::HashMap; +use std::sync::Arc; impl CreateMaterial for MixMaterial { fn create( - parameters: &crate::utils::TextureParameterDictionary, - normal_map: Option>, - named_materials: &std::collections::HashMap, - loc: &crate::utils::FileLoc, - arena: &mut crate::Arena, - ) -> Result { + _parameters: &TextureParameterDictionary, + _normal_map: Option>, + _named_materials: &HashMap, + _loc: &FileLoc, + _arena: &mut Arena, + ) -> Result { todo!() } } diff --git a/src/samplers/halton.rs b/src/samplers/halton.rs index 4ff8753..c35d8d3 100644 --- a/src/samplers/halton.rs +++ b/src/samplers/halton.rs @@ -1,10 +1,11 @@ use crate::Arena; use crate::core::sampler::CreateSampler; +use crate::utils::math::{DigitPermutation, compute_radical_inverse_permutations}; use crate::utils::{FileLoc, ParameterDictionary}; use anyhow::{Result, anyhow}; use shared::core::geometry::Point2i; use shared::core::options::get_options; -use shared::core::sampler::{HaltonSampler, RandomizeStrategy}; +use shared::core::sampler::{HaltonSampler, MAX_HALTON_RESOLUTION, RandomizeStrategy}; pub trait CreateHaltonSampler { fn new( @@ -22,7 +23,7 @@ impl CreateHaltonSampler for HaltonSampler { randomize: RandomizeStrategy, seed: u64, ) -> Self { - let digit_permutations = compute_radical_inverse_permutations(seed); + let (_, _digit_permutations) = compute_radical_inverse_permutations(seed); let mut base_scales = [0u64; 2]; let mut base_exponents = [0u64; 2]; let bases = [2, 3]; @@ -54,7 +55,7 @@ impl CreateHaltonSampler for HaltonSampler { Self { samples_per_pixel, randomize, - digit_permutations, + digit_permutations: Ptr::from(&digit_permutations), base_scales, base_exponents, mult_inverse, @@ -68,7 +69,7 @@ impl CreateSampler for HaltonSampler { fn create( params: &ParameterDictionary, full_res: Point2i, - _loc: &FileLoc, + loc: &FileLoc, _arena: &mut Arena, ) -> Result { let options = get_options(); diff --git a/src/samplers/independent.rs b/src/samplers/independent.rs index 64cdc1f..27e0c3d 100644 --- a/src/samplers/independent.rs +++ b/src/samplers/independent.rs @@ -5,7 +5,6 @@ use anyhow::Result; use shared::core::geometry::Point2i; use shared::core::options::get_options; use shared::core::sampler::IndependentSampler; -use std::fmt::Error; impl CreateSampler for IndependentSampler { fn create( diff --git a/src/samplers/sobol.rs b/src/samplers/sobol.rs index 2bd3340..e469e73 100644 --- a/src/samplers/sobol.rs +++ b/src/samplers/sobol.rs @@ -74,7 +74,7 @@ impl CreateSampler for ZSobolSampler { params: &ParameterDictionary, full_res: Point2i, loc: &FileLoc, - _arena: &mut Arena, + arena: &mut Arena, ) -> Result { let options = get_options(); let nsamp = options diff --git a/src/shapes/bilinear.rs b/src/shapes/bilinear.rs index a8a7330..eab7a74 100644 --- a/src/shapes/bilinear.rs +++ b/src/shapes/bilinear.rs @@ -5,11 +5,11 @@ use crate::shapes::mesh::BilinearPatchMesh; use crate::utils::sampling::PiecewiseConstant2D; use crate::utils::{Arena, FileLoc, ParameterDictionary}; use log::warn; -use shared::core::geometry::{Bounds2f, Point2f}; use shared::core::shape::Shape; use shared::shapes::BilinearPatchShape; -use shared::utils::Transform; +use shared::utils::{Ptr, Transform}; use std::collections::HashMap; +use std::path::Path; use std::sync::Arc; impl CreateShape for BilinearPatchShape { @@ -20,10 +20,10 @@ impl CreateShape for BilinearPatchShape { parameters: ParameterDictionary, _float_textures: HashMap, _loc: FileLoc, - arena: &mut Arena, + _arena: &mut Arena, ) -> Result, String> { let mut vertex_indices = parameters.get_int_array("indices"); - let mut p = parameters.get_point3f_array("P"); + let p = parameters.get_point3f_array("P"); let mut uv = parameters.get_point2f_array("uv"); let mut n = parameters.get_normal3f_array("N"); let mut face_indices = parameters.get_int_array("faceIndices"); @@ -64,7 +64,7 @@ impl CreateShape for BilinearPatchShape { n.clear(); } - for (i, &idx) in vertex_indices.iter().enumerate() { + for (_, &idx) in vertex_indices.iter().enumerate() { if idx < 0 || idx as usize >= p.len() { return Err(format!( "Bilinear patch mesh has out-of-bounds vertex index {} ({} \"P\" values were given). Discarding this mesh.", @@ -93,9 +93,9 @@ impl CreateShape for BilinearPatchShape { "\"emissionfilename\" is currently ignored for bilinear patches if \"uv\" coordinates have been provided--sorry!" ); } else { - match Image::read(Path::new(filename), None) { + match Image::read(Path::new(&filename), None) { Ok(mut im) => { - let img = im.image; + let mut img = im.image; img.flip_y(); image_dist = Some(PiecewiseConstant2D::from_image(&img)); } @@ -124,7 +124,7 @@ impl CreateShape for BilinearPatchShape { let n_patches = host_arc.device.n_patches; let mesh_ptr = Ptr::from(&host_arc.device); let mut shapes = Vec::with_capacity(n_patches as usize); - for i in 0..n_patches { + for i in 0..n_patches as i32 { shapes.push(Shape::BilinearPatch(BilinearPatchShape { mesh: mesh_ptr, blp_index: i, @@ -132,7 +132,7 @@ impl CreateShape for BilinearPatchShape { rectangle: false, })); } - arena.alloc(shapes); + // arena.alloc(shapes); Ok(shapes) } } diff --git a/src/shapes/curves.rs b/src/shapes/curves.rs index b8034d0..4481dfc 100644 --- a/src/shapes/curves.rs +++ b/src/shapes/curves.rs @@ -11,7 +11,6 @@ use shared::utils::math::lerp; use shared::utils::splines::{ cubic_bspline_to_bezier, elevate_quadratic_bezier_to_cubic, quadratic_bspline_to_bezier, }; -use std::sync::Arc; use log::warn; use std::collections::HashMap; diff --git a/src/shapes/mesh.rs b/src/shapes/mesh.rs index 2073697..b085770 100644 --- a/src/shapes/mesh.rs +++ b/src/shapes/mesh.rs @@ -181,7 +181,7 @@ impl BilinearPatchMesh { pub fn new( render_from_object: &Transform, reverse_orientation: bool, - vertex_indices: Vec, + vertex_indices: Vec, mut p: Vec, mut n: Vec, uv: Vec, diff --git a/src/shapes/triangle.rs b/src/shapes/triangle.rs index d4f0616..3f8a9b4 100644 --- a/src/shapes/triangle.rs +++ b/src/shapes/triangle.rs @@ -5,7 +5,7 @@ use crate::utils::{Arena, FileLoc, ParameterDictionary}; use log::warn; use shared::core::shape::Shape; use shared::shapes::TriangleShape; -use shared::utils::Transform; +use shared::utils::{Ptr, Transform}; use std::collections::HashMap; use std::sync::Arc; @@ -16,11 +16,11 @@ impl CreateShape for TriangleShape { reverse_orientation: bool, parameters: ParameterDictionary, _float_texture: HashMap, - loc: FileLoc, - arena: &mut Arena, + _loc: FileLoc, + _arena: &mut Arena, ) -> Result, String> { let mut vertex_indices = parameters.get_int_array("indices"); - let mut p = parameters.get_point3f_array("P"); + let p = parameters.get_point3f_array("P"); let mut uvs = parameters.get_point2f_array("uv"); let mut s = parameters.get_vector3f_array("S"); let mut n = parameters.get_normal3f_array("N"); @@ -62,7 +62,7 @@ impl CreateShape for TriangleShape { n.clear(); } - for (i, &index) in vertex_indices.iter().enumerate() { + for (_, &index) in vertex_indices.iter().enumerate() { // Check for negative indices (if keeping i32) or out of bounds if index < 0 || index as usize >= p.len() { return Err(format!( @@ -98,7 +98,7 @@ impl CreateShape for TriangleShape { let host_arc = Arc::new(host); let mut global_store = ALL_TRIANGLE_MESHES.lock(); - let mesh_index = global_store.len() as u32; + // let mesh_index = global_store.len() as u32; global_store.push(host_arc.clone()); drop(global_store); let n_patches = host_arc.device.n_triangles; @@ -111,7 +111,7 @@ impl CreateShape for TriangleShape { })); } - arena.alloc(shapes); + // arena.alloc(shapes); Ok(shapes) } } diff --git a/src/spectra/colorspace.rs b/src/spectra/colorspace.rs index beca3b4..cd8a80d 100644 --- a/src/spectra/colorspace.rs +++ b/src/spectra/colorspace.rs @@ -1,6 +1,9 @@ +use crate::spectra::get_spectra_context; + use super::DenselySampledSpectrumBuffer; use shared::core::color::{RGB, RGBToSpectrumTable, XYZ}; -use shared::core::geometry::Point2f; +use shared::core::geometry::{Point2f, Vector3f}; +use shared::core::spectrum::Spectrum; use shared::spectra::RGBColorSpace; use shared::utils::math::SquareMatrix; use shared::utils::ptr::Ptr; @@ -26,7 +29,8 @@ impl RGBColorSpaceData { illuminant: DenselySampledSpectrumBuffer, rgb_to_spectrum_table: Ptr, ) -> Self { - let w_xyz: XYZ = Spectrum::Dense(illuminant).to_xyz(); + let stdspec = get_spectra_context(); + let w_xyz: XYZ = Spectrum::Dense(*illuminant).to_xyz(&stdspec); let w = w_xyz.xy(); let r_xyz = XYZ::from_xyy(r, Some(1.0)); let g_xyz = XYZ::from_xyy(g, Some(1.0)); @@ -37,8 +41,7 @@ impl RGBColorSpaceData { [r_xyz.z(), g_xyz.z(), b_xyz.z()], ]; let rgb = SquareMatrix::new(rgb_values); - let c_vec: Vector3f = rgb.inverse().unwrap() * w_xyz; - let c = RGB::from(c); + let c: RGB = rgb.inverse().unwrap() * w_xyz; let xyz_from_rgb = rgb * SquareMatrix::diag(&[c.r, c.g, c.b]); let rgb_from_xyz = xyz_from_rgb .inverse() diff --git a/src/spectra/data.rs b/src/spectra/data.rs index dabfa22..83f44c4 100644 --- a/src/spectra/data.rs +++ b/src/spectra/data.rs @@ -1,7 +1,6 @@ use crate::spectra::{DenselySampledSpectrumBuffer, piecewise::PiecewiseLinearSpectrumBuffer}; use shared::Float; use shared::core::spectrum::Spectrum; -use shared::spectra::PiecewiseLinearSpectrum; use shared::spectra::cie::*; use std::collections::HashMap; use std::sync::LazyLock; diff --git a/src/spectra/mod.rs b/src/spectra/mod.rs index a021797..a819a30 100644 --- a/src/spectra/mod.rs +++ b/src/spectra/mod.rs @@ -1,12 +1,10 @@ use crate::globals::{ACES_TABLE, DCI_P3_TABLE, REC2020_TABLE, SRGB_TABLE}; use crate::spectra::colorspace::RGBColorSpaceData; -use shared::core::color::RGBToSpectrumTable; use shared::core::geometry::Point2f; use shared::core::spectrum::Spectrum; use shared::core::spectrum::StandardSpectra; -use shared::spectra::DeviceStandardColorSpaces; -use shared::spectra::RGBColorSpace; use shared::spectra::cie::{CIE_D65, CIE_X, CIE_Y, CIE_Z}; +use shared::utils::Ptr; use std::sync::Arc; use std::sync::LazyLock; @@ -64,7 +62,7 @@ pub static SRGB: LazyLock> = LazyLock::new(|| { let r = Point2f::new(0.64, 0.33); let g = Point2f::new(0.3, 0.6); let b = Point2f::new(0.15, 0.06); - let table = Ptr::from(SRGB_TABLE.clone()); + let table_ptr = Ptr::from(&SRGB_TABLE.clone()); Arc::new(RGBColorSpaceData::new(r, g, b, illum, table_ptr)) }); @@ -75,7 +73,7 @@ pub static DCI_P3: LazyLock> = LazyLock::new(|| { let g = Point2f::new(0.265, 0.690); let b = Point2f::new(0.150, 0.060); - let table_ptr = Ptr::from(DCI_P3_TABLE.clone()); + let table_ptr = Ptr::from(&DCI_P3_TABLE.clone()); Arc::new(RGBColorSpaceData::new(r, g, b, illum, table_ptr)) }); @@ -86,7 +84,7 @@ pub static REC2020: LazyLock> = LazyLock::new(|| { let g = Point2f::new(0.170, 0.797); let b = Point2f::new(0.131, 0.046); - let table_ptr = Ptr::from(REC2020_TABLE.clone()); + let table_ptr = Ptr::from(&REC2020_TABLE.clone()); Arc::new(RGBColorSpaceData::new(r, g, b, illum, table_ptr)) }); @@ -97,7 +95,7 @@ pub static ACES: LazyLock> = LazyLock::new(|| { let g = Point2f::new(0.0000, 1.0000); let b = Point2f::new(0.0001, -0.0770); - let table_ptr = Ptr::from(ACES_TABLE.clone()); + let table_ptr = Ptr::from(&ACES_TABLE.clone()); Arc::new(RGBColorSpaceData::new(r, g, b, illum, table_ptr)) }); diff --git a/src/textures/mix.rs b/src/textures/mix.rs index 9ec4c30..c10198f 100644 --- a/src/textures/mix.rs +++ b/src/textures/mix.rs @@ -1,5 +1,6 @@ -use crate::core::texture::FloatTexture; -use crate::core::texture::{FloatTextureTrait, SpectrumTextureTrait}; +use crate::core::texture::{ + FloatTexture, FloatTextureTrait, SpectrumTexture, SpectrumTextureTrait, +}; use crate::utils::{Arena, FileLoc, TextureParameterDictionary}; use shared::Float; use shared::core::geometry::{Vector3f, VectorLike}; diff --git a/src/utils/arena.rs b/src/utils/arena.rs index ecd116b..7abe412 100644 --- a/src/utils/arena.rs +++ b/src/utils/arena.rs @@ -1,7 +1,7 @@ use crate::core::image::Image; -use crate::core::texture::{FloatTexture, SpectrumTexture, get_texture_cache}; +use crate::core::texture::{FloatTexture, SpectrumTexture}; use crate::shapes::{BilinearPatchMesh, TriangleMesh}; -use crate::textures::CreateGPUSpectrumPtex; +use crate::utils::mipmap::MIPMap; use crate::utils::sampling::PiecewiseConstant2D; use shared::core::color::RGBToSpectrumTable; use shared::core::image::DeviceImage; @@ -247,7 +247,6 @@ impl Upload for FloatTexture { FloatTexture::FBm(tex) => GPUFloatTexture::FBm(tex.clone()), FloatTexture::Windy(tex) => GPUFloatTexture::Windy(tex.clone()), FloatTexture::Wrinkled(tex) => GPUFloatTexture::Wrinkled(tex.clone()), - FloatTexture::Constant(val) => GPUFloatTexture::Constant(*val), FloatTexture::Scaled(tex) => { let child_ptr = tex.tex.upload(arena); @@ -274,7 +273,7 @@ impl Upload for FloatTexture { FloatTexture::DirectionMix(tex) => { let tex1_ptr = tex.tex1.upload(arena); let tex2_ptr = tex.tex2.upload(arena); - let gpu_dmix = shared::textures::GPUFloatDirectionMixTexture { + let gpu_dmix = GPUFloatDirectionMixTexture { tex1: tex1_ptr, tex2: tex2_ptr, dir: tex.dir, @@ -285,16 +284,16 @@ impl Upload for FloatTexture { FloatTexture::Image(tex) => { let gpu_image_tex = GPUFloatImageTexture { mapping: tex.base.mapping, - tex_obj: image_ptr.offset as u64, + tex_obj: tex.base.mipmap.texture_object(), scale: tex.base.scale, invert: tex.base.invert, }; GPUFloatTexture::Image(gpu_image_tex) } - FloatTexture::Ptex(tex) => { - todo!("Implement Ptex buffer upload") - } + // FloatTexture::Ptex(tex) => { + // todo!("Implement Ptex buffer upload") + // } FloatTexture::Bilerp(tex) => GPUFloatTexture::Bilerp(tex.clone()), }; diff --git a/src/utils/containers.rs b/src/utils/containers.rs index 3e3a959..8211db2 100644 --- a/src/utils/containers.rs +++ b/src/utils/containers.rs @@ -1,6 +1,6 @@ use parking_lot::Mutex; use shared::core::geometry::{Bounds2i, Point2i}; -use shared::utils::containers::Array2D; +use shared::utils::containers::DeviceArray2D; use std::collections::HashSet; use std::hash::Hash; use std::ops::{Deref, DerefMut}; @@ -33,28 +33,29 @@ where } } -pub struct Array2DBuffer { - pub view: Array2D, +#[derive(Debug, Clone)] +pub struct Array2D { + pub view: DeviceArray2D, _storage: Vec, } -impl Deref for Array2DBuffer { - type Target = Array2D; +impl Deref for Array2D { + type Target = DeviceArray2D; fn deref(&self) -> &Self::Target { &self.view } } -impl DerefMut for Array2DBuffer { +impl DerefMut for Array2D { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.view } } -impl Array2DBuffer { +impl Array2D { fn from_vec(extent: Bounds2i, mut storage: Vec) -> Self { let width = extent.p_max.x() - extent.p_min.x(); - let view = Array2D { + let view = DeviceArray2D { extent, values: storage.as_mut_ptr(), stride: width, @@ -66,7 +67,7 @@ impl Array2DBuffer { } } -impl Array2DBuffer { +impl Array2D { pub fn new(extent: Bounds2i) -> Self { let n = extent.area() as usize; let storage = vec![T::default(); n]; diff --git a/src/utils/mipmap.rs b/src/utils/mipmap.rs index 867ca45..298536f 100644 --- a/src/utils/mipmap.rs +++ b/src/utils/mipmap.rs @@ -6,7 +6,6 @@ use shared::core::image::{WrapMode, WrapMode2D}; use shared::spectra::RGBColorSpace; use shared::utils::math::{lerp, safe_sqrt, square}; use std::path::Path; -use std::sync::OnceLock; use std::hash::{Hash, Hasher}; use std::ops::{Add, Mul, Sub}; diff --git a/src/utils/sampling.rs b/src/utils/sampling.rs index 0e7c148..d7dc739 100644 --- a/src/utils/sampling.rs +++ b/src/utils/sampling.rs @@ -1,5 +1,6 @@ use crate::core::image::Image; use crate::utils::Arena; +use crate::utils::containers::Array2D; use shared::Float; use shared::core::geometry::{Point2i, Vector2f, Vector2i}; use shared::utils::Ptr; @@ -447,23 +448,23 @@ impl std::ops::Deref for SummedAreaTable { impl SummedAreaTable { pub fn new(values: &Array2D) -> Self { - let width = values.x_size(); - let height = values.y_size(); + let width = values.x_size() as i32; + let height = values.y_size() as i32; - let mut sum = Array2D::::new_with_dims(width, height); + let mut sum = Array2D::::new_dims(width, height); sum[(0, 0)] = values[(0, 0)] as f64; for x in 1..width { - sum[(x, 0)] = values[(x as i32, 0)] as f64 + sum[(x - 1, 0)]; + sum[(x, 0)] = values[(x, 0)] as f64 + sum[(x - 1, 0)]; } for y in 1..height { - sum[(0, y)] = values[(0, y as i32)] as f64 + sum[(0, y - 1)]; + sum[(0, y)] = values[(0, y)] as f64 + sum[(0, y - 1)]; } for y in 1..height { for x in 1..width { - let term = values[(x as i32, y as i32)] as f64; + let term = values[(x, y)] as f64; let left = sum[(x - 1, y)]; let up = sum[(x, y - 1)]; let diag = sum[(x - 1, y - 1)]; @@ -472,7 +473,7 @@ impl SummedAreaTable { } } - let device = DeviceSummedAreaTable { sum }; + let device = DeviceSummedAreaTable { sum: *sum }; Self { device, sum } } } @@ -494,7 +495,7 @@ impl std::ops::Deref for WindowedPiecewiseConstant2D { impl WindowedPiecewiseConstant2D { pub fn new(func: Array2D) -> Self { let sat = *SummedAreaTable::new(&func); - let device = DeviceWindowedPiecewiseConstant2D { sat, func }; + let device = DeviceWindowedPiecewiseConstant2D { sat, func: *func }; Self { sat, func, device } }