Some more refactoring, more error correction. When will this end?

This commit is contained in:
pingu 2026-01-22 16:20:28 +00:00
parent 380b1c9f90
commit 14418472d5
57 changed files with 275 additions and 290 deletions

View file

@ -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,

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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};

View file

@ -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,

View file

@ -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,

View file

@ -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()
}
}

View file

@ -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 {

View file

@ -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<Float, 3>,
pub pixels: Array2D<RGBPixel>,
pub pixels: DeviceArray2D<RGBPixel>,
}
#[repr(C)]
@ -215,7 +215,7 @@ pub struct GBufferFilm {
pub base: FilmBase,
output_from_render: AnimatedTransform,
apply_inverse: bool,
pixels: Array2D<GBufferPixel>,
pixels: DeviceArray2D<GBufferPixel>,
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<SpectralPixel>,
pub pixels: DeviceArray2D<SpectralPixel>,
pub output_rgbf_from_sensor_rgb: SquareMatrix<Float, 3>,
pub bucket_sums: *mut f64,
pub weight_sums: *mut f64,

View file

@ -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<Float>,
pub f: DeviceArray2D<Float>,
}
impl FilterSampler {

View file

@ -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;

View file

@ -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)]

View file

@ -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<DeviceBilinearPatchMesh>,
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<DeviceBilinearPatchMesh> {
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<DeviceBilinearPatchMesh>, blp_index: i32) -> Self {
let mut bp = BilinearPatchShape {
mesh,
blp_index,

View file

@ -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<DeviceTriangleMesh>,
pub tri_index: i32,
}
@ -111,11 +112,11 @@ impl TriangleShape {
}
}
pub fn new(mesh: DeviceTriangleMesh, tri_index: i32) -> Self {
pub fn new(mesh: Ptr<DeviceTriangleMesh>, tri_index: i32) -> Self {
Self { mesh, tri_index }
}
pub fn get_mesh(&self) -> DeviceTriangleMesh {
pub fn get_mesh(&self) -> Ptr<DeviceTriangleMesh> {
self.mesh
}

View file

@ -83,6 +83,7 @@ pub struct GPUFloatImageTexture {
}
impl GPUFloatImageTexture {
#[allow(unused_variables)]
pub fn evaluate(&self, ctx: &TextureEvalContext) -> Float {
#[cfg(not(feature = "cuda"))]
{

View file

@ -22,16 +22,16 @@ impl<T> Interpolatable for T where
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct Array2D<T> {
pub struct DeviceArray2D<T> {
pub values: *mut T,
pub extent: Bounds2i,
pub stride: i32,
}
unsafe impl<T: Send> Send for Array2D<T> {}
unsafe impl<T: Sync> Sync for Array2D<T> {}
unsafe impl<T: Send> Send for DeviceArray2D<T> {}
unsafe impl<T: Sync> Sync for DeviceArray2D<T> {}
impl<T> Array2D<T> {
impl<T> DeviceArray2D<T> {
#[inline]
pub fn x_size(&self) -> u32 {
(self.extent.p_max.x() - self.extent.p_min.x()) as u32
@ -90,7 +90,7 @@ impl<T> Array2D<T> {
}
}
impl<T> Index<Point2i> for Array2D<T> {
impl<T> Index<Point2i> for DeviceArray2D<T> {
type Output = T;
#[inline(always)]
fn index(&self, p: Point2i) -> &Self::Output {
@ -98,20 +98,20 @@ impl<T> Index<Point2i> for Array2D<T> {
}
}
impl<T> IndexMut<Point2i> for Array2D<T> {
impl<T> IndexMut<Point2i> for DeviceArray2D<T> {
fn index_mut(&mut self, p: Point2i) -> &mut Self::Output {
self.get_mut(p)
}
}
impl<T> Index<(i32, i32)> for Array2D<T> {
impl<T> Index<(i32, i32)> for DeviceArray2D<T> {
type Output = T;
fn index(&self, (x, y): (i32, i32)) -> &Self::Output {
&self[Point2i::new(x, y)]
}
}
impl<T> IndexMut<(i32, i32)> for Array2D<T> {
impl<T> IndexMut<(i32, i32)> for DeviceArray2D<T> {
fn index_mut(&mut self, (x, y): (i32, i32)) -> &mut Self::Output {
&mut self[Point2i::new(x, y)]
}

View file

@ -16,7 +16,7 @@ impl<T: ?Sized> Copy for Ptr<T> {}
impl<T: ?Sized> PartialEq for Ptr<T> {
fn eq(&self, other: &Self) -> bool {
self.ptr == other.ptr
std::ptr::addr_eq(self.ptr, other.ptr)
}
}

View file

@ -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<f64>,
pub sum: DeviceArray2D<f64>,
}
impl DeviceSummedAreaTable {
// pub fn new(values: &Array2D<Float>) -> Self {
// let width = values.x_size();
// let height = values.y_size();
//
// let mut sum = Array2D::<f64>::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<Float>,
pub func: DeviceArray2D<Float>,
}
impl DeviceWindowedPiecewiseConstant2D {

View file

@ -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;

View file

@ -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<SpectralPixel>,
pixels: DeviceArray2D<SpectralPixel>,
bucket_sums: Vec<f64>,
weight_sums: Vec<f64>,
bucket_splats: Vec<AtomicFloat>,
@ -228,7 +228,7 @@ impl SpectralFilmHost {
bucket_splats.push(AtomicFloat::new(0.0));
}
let mut pixels = Array2D::<SpectralPixel>::new(base.pixel_bounds);
let mut pixels = DeviceArray2D::<SpectralPixel>::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(),

View file

@ -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<Filter, String>;
@ -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(

View file

@ -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<F>(&self, dxd_a: F, domain: Bounds2f) -> Array2D<Float>
pub fn get_sampling_distribution<F>(&self, dxd_a: F, domain: Bounds2f) -> DeviceArray2D<Float>
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<Float> {
pub fn get_sampling_distribution_uniform(&self) -> DeviceArray2D<Float> {
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)

View file

@ -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<Light, Error>;
) -> Result<Light>;
}
pub trait LightFactory {
@ -44,7 +43,7 @@ pub trait LightFactory {
alpha_tex: &FloatTexture,
colorspace: Option<&RGBColorSpace>,
camera_transform: CameraTransform,
) -> Result<Self, Error>;
) -> Result<Self>;
}
impl LightFactory for Light {
@ -59,7 +58,7 @@ impl LightFactory for Light {
alpha_tex: &FloatTexture,
colorspace: Option<&RGBColorSpace>,
camera_transform: CameraTransform,
) -> Result<Self, Error> {
) -> Result<Self> {
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)),
}
}
}

View file

@ -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<String, Material>,
loc: &FileLoc,
arena: &mut Arena,
) -> Result<Material, Error>;
) -> Result<Material>;
}
pub trait MaterialFactory {
@ -26,7 +26,7 @@ pub trait MaterialFactory {
named_materials: HashMap<String, Material>,
loc: FileLoc,
arena: &mut Arena,
) -> Result<Self, Error>;
) -> Result<Self>;
}
impl MaterialFactory for Material {
@ -37,7 +37,7 @@ impl MaterialFactory for Material {
named_materials: HashMap<String, Material>,
loc: FileLoc,
arena: &mut Arena,
) -> Result<Material, Error> {
) -> Result<Material> {
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)),
}
}
}

View file

@ -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};

View file

@ -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),

View file

@ -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;

View file

@ -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)>,

View file

@ -37,7 +37,7 @@ pub enum FloatTexture {
Checkerboard(FloatCheckerboardTexture),
Dots(FloatDotsTexture),
FBm(FBmTexture),
Ptex(FloatPtexTexture),
// Ptex(FloatPtexTexture),
Windy(WindyTexture),
Wrinkled(WrinkledTexture),
}

View file

@ -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;

View file

@ -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<Light, Error> {
) -> Result<Light> {
let l = parameters
.get_one_spectrum(
"L",

View file

@ -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<Light, Error> {
) -> Result<Light> {
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
)),
}
}

View file

@ -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>,
image: Arc<DeviceImage>,
image_color_space: Arc<RGBColorSpace>,
) -> 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::<Float>() / 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<InfinitePortalLightStorage>,
}
@ -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,

View file

@ -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<Light, Error> {
) -> Result<Light> {
let l = parameters
.get_one_spectrum(
"L",

View file

@ -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(&parameters.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!(

View file

@ -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;

View file

@ -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<Light, Error> {
) -> Result<Light> {
let i = parameters
.get_one_spectrum(
"I",

View file

@ -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 {

View file

@ -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<String, shared::core::material::Material>,
_loc: &crate::utils::FileLoc,
_arena: &mut crate::Arena,
) -> Result<Material, std::fmt::Error> {
) -> Result<Material> {
todo!()
}
}

View file

@ -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<String, Material>,
_loc: &FileLoc,
_arena: &mut Arena,
) -> Result<Material, Error> {
) -> Result<Material> {
todo!()
}
}
@ -27,7 +27,7 @@ impl CreateMaterial for ThinDielectricMaterial {
_named_materials: &HashMap<String, Material>,
_loc: &FileLoc,
_arena: &mut Arena,
) -> Result<Material, Error> {
) -> Result<Material> {
todo!()
}
}

View file

@ -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<String, Material>,
_loc: &FileLoc,
_arena: &mut Arena,
) -> Result<Material, Error> {
) -> Result<Material> {
todo!()
}
}
@ -27,7 +27,7 @@ impl CreateMaterial for DiffuseTransmissionMaterial {
_named_materials: &HashMap<String, Material>,
_loc: &FileLoc,
_arena: &mut Arena,
) -> Result<Material, Error> {
) -> Result<Material> {
todo!()
}
}

View file

@ -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<std::sync::Arc<Image>>,
named_materials: &std::collections::HashMap<String, Material>,
loc: &crate::utils::FileLoc,
arena: &mut crate::Arena,
) -> Result<Material, std::fmt::Error> {
_parameters: &TextureParameterDictionary,
_normal_map: Option<Arc<Image>>,
_named_materials: &HashMap<String, Material>,
_loc: &FileLoc,
_arena: &mut Arena,
) -> Result<Material> {
todo!()
}
}

View file

@ -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<Self> {
let options = get_options();

View file

@ -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(

View file

@ -74,7 +74,7 @@ impl CreateSampler for ZSobolSampler {
params: &ParameterDictionary,
full_res: Point2i,
loc: &FileLoc,
_arena: &mut Arena,
arena: &mut Arena,
) -> Result<Self> {
let options = get_options();
let nsamp = options

View file

@ -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<String, FloatTexture>,
_loc: FileLoc,
arena: &mut Arena,
_arena: &mut Arena,
) -> Result<Vec<Shape>, 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)
}
}

View file

@ -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;

View file

@ -181,7 +181,7 @@ impl BilinearPatchMesh {
pub fn new(
render_from_object: &Transform,
reverse_orientation: bool,
vertex_indices: Vec<ui2>,
vertex_indices: Vec<i32>,
mut p: Vec<Point3f>,
mut n: Vec<Normal3f>,
uv: Vec<Point2f>,

View file

@ -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<String, FloatTexture>,
loc: FileLoc,
arena: &mut Arena,
_loc: FileLoc,
_arena: &mut Arena,
) -> Result<Vec<Shape>, 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)
}
}

View file

@ -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<RGBToSpectrumTable>,
) -> 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()

View file

@ -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;

View file

@ -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<Arc<RGBColorSpaceData>> = 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<Arc<RGBColorSpaceData>> = 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<Arc<RGBColorSpaceData>> = 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<Arc<RGBColorSpaceData>> = 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))
});

View file

@ -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};

View file

@ -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()),
};

View file

@ -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<T> {
pub view: Array2D<T>,
#[derive(Debug, Clone)]
pub struct Array2D<T> {
pub view: DeviceArray2D<T>,
_storage: Vec<T>,
}
impl<T> Deref for Array2DBuffer<T> {
type Target = Array2D<T>;
impl<T> Deref for Array2D<T> {
type Target = DeviceArray2D<T>;
fn deref(&self) -> &Self::Target {
&self.view
}
}
impl<T> DerefMut for Array2DBuffer<T> {
impl<T> DerefMut for Array2D<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.view
}
}
impl<T> Array2DBuffer<T> {
impl<T> Array2D<T> {
fn from_vec(extent: Bounds2i, mut storage: Vec<T>) -> 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<T> Array2DBuffer<T> {
}
}
impl<T: Default + Clone> Array2DBuffer<T> {
impl<T: Default + Clone> Array2D<T> {
pub fn new(extent: Bounds2i) -> Self {
let n = extent.area() as usize;
let storage = vec![T::default(); n];

View file

@ -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};

View file

@ -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<Float>) -> 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::<f64>::new_with_dims(width, height);
let mut sum = Array2D::<f64>::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<Float>) -> Self {
let sat = *SummedAreaTable::new(&func);
let device = DeviceWindowedPiecewiseConstant2D { sat, func };
let device = DeviceWindowedPiecewiseConstant2D { sat, func: *func };
Self { sat, func, device }
}