Implementing arena based memory allocation
This commit is contained in:
parent
0ef563d1a5
commit
f94c5d78c7
73 changed files with 953 additions and 672 deletions
|
|
@ -19,7 +19,7 @@ use crate::spectra::{
|
|||
N_SPECTRUM_SAMPLES, RGBColorSpace, RGBUnboundedSpectrum, SampledSpectrum, SampledWavelengths,
|
||||
StandardColorSpaces,
|
||||
};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::hash::hash_buffer;
|
||||
use crate::utils::math::{
|
||||
clamp, fast_exp, i0, lerp, log_i0, radians, safe_acos, safe_asin, safe_sqrt, sample_discrete,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crate::core::geometry::{
|
|||
use crate::core::scattering::reflect;
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::math::square;
|
||||
use crate::utils::ptr::{Ptr, Slice};
|
||||
use crate::utils::ptr::{DevicePtr, Slice};
|
||||
use crate::utils::sampling::{PiecewiseLinear2D, cosine_hemisphere_pdf, sample_cosine_hemisphere};
|
||||
use crate::{Float, INV_PI, PI, PI_OVER_2};
|
||||
use core::any::Any;
|
||||
|
|
@ -28,7 +28,7 @@ pub struct MeasuredBxDFData {
|
|||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct MeasuredBxDF {
|
||||
pub brdf: Ptr<MeasuredBxDFData>,
|
||||
pub brdf: DevicePtr<MeasuredBxDFData>,
|
||||
pub lambda: SampledWavelengths,
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ unsafe impl Sync for MeasuredBxDF {}
|
|||
impl MeasuredBxDF {
|
||||
pub fn new(brdf: &MeasuredBxDFData, lambda: &SampledWavelengths) -> Self {
|
||||
Self {
|
||||
brdf: Ptr::from(brdf),
|
||||
brdf: DevicePtr::from(brdf),
|
||||
lambda: *lambda,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::core::film::Film;
|
|||
use crate::core::geometry::{
|
||||
Bounds2f, Normal3f, Point2f, Point2i, Point3f, Ray, Vector2f, Vector2i, Vector3f, VectorLike,
|
||||
};
|
||||
use crate::core::image::{Image, PixelFormat};
|
||||
use crate::core::image::{DeviceImage, PixelFormat};
|
||||
use crate::core::medium::Medium;
|
||||
use crate::core::pbrt::Float;
|
||||
use crate::core::sampler::CameraSample;
|
||||
|
|
@ -37,7 +37,7 @@ pub struct RealisticCamera {
|
|||
base: CameraBase,
|
||||
focus_distance: Float,
|
||||
set_aperture_diameter: Float,
|
||||
aperture_image: *const Image,
|
||||
aperture_image: *const DeviceImage,
|
||||
element_interfaces: *const LensElementInterface,
|
||||
n_elements: usize,
|
||||
physical_extent: Bounds2f,
|
||||
|
|
@ -51,7 +51,7 @@ impl RealisticCamera {
|
|||
lens_params: &[Float],
|
||||
focus_distance: Float,
|
||||
set_aperture_diameter: Float,
|
||||
aperture_image: Option<Image>,
|
||||
aperture_image: Option<DeviceImage>,
|
||||
) -> Self {
|
||||
let film_ptr = base.film;
|
||||
if film_ptr.is_null() {
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@ use crate::Float;
|
|||
use crate::core::bxdf::{BSDFSample, BxDF, BxDFFlags, BxDFTrait, FArgs, TransportMode};
|
||||
use crate::core::geometry::{Frame, Normal3f, Point2f, Vector3f, VectorLike};
|
||||
use crate::spectra::SampledSpectrum;
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Debug, Default)]
|
||||
pub struct BSDF {
|
||||
bxdf: Ptr<BxDF>,
|
||||
bxdf: DevicePtr<BxDF>,
|
||||
shading_frame: Frame,
|
||||
}
|
||||
|
||||
impl BSDF {
|
||||
pub fn new(ns: Normal3f, dpdus: Vector3f, bxdf: Ptr<BxDF>) -> Self {
|
||||
pub fn new(ns: Normal3f, dpdus: Vector3f, bxdf: DevicePtr<BxDF>) -> Self {
|
||||
Self {
|
||||
bxdf,
|
||||
shading_frame: Frame::new(dpdus.normalize(), Vector3f::from(ns)),
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ use crate::core::geometry::{Frame, Normal3f, Point2f, Point3f, Point3fi, Vector3
|
|||
use crate::core::interaction::{InteractionBase, ShadingGeom, SurfaceInteraction};
|
||||
use crate::core::shape::Shape;
|
||||
use crate::spectra::{N_SPECTRUM_SAMPLES, SampledSpectrum};
|
||||
use crate::utils::ArenaPtr;
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::math::{catmull_rom_weights, square};
|
||||
use crate::utils::sampling::sample_catmull_rom_2d;
|
||||
use crate::utils::{Ptr, ptr::Slice};
|
||||
use crate::utils::{DevicePtr, ptr::Slice};
|
||||
use crate::{Float, PI};
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use std::sync::Arc;
|
||||
|
|
@ -78,15 +78,15 @@ impl From<&SubsurfaceInteraction> for SurfaceInteraction {
|
|||
dndv: Normal3f::zero(),
|
||||
},
|
||||
face_index: 0,
|
||||
area_light: Ptr::null(),
|
||||
material: Ptr::null(),
|
||||
area_light: DevicePtr::null(),
|
||||
material: DevicePtr::null(),
|
||||
dpdx: Vector3f::zero(),
|
||||
dpdy: Vector3f::zero(),
|
||||
dudx: 0.,
|
||||
dvdx: 0.,
|
||||
dudy: 0.,
|
||||
dvdy: 0.,
|
||||
shape: Ptr::from(&Shape::default()),
|
||||
shape: DevicePtr::from(&Shape::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -96,11 +96,11 @@ impl From<&SubsurfaceInteraction> for SurfaceInteraction {
|
|||
pub struct BSSRDFTable {
|
||||
pub n_rho_samples: u32,
|
||||
pub n_radius_samples: u32,
|
||||
pub rho_samples: Ptr<Float>,
|
||||
pub radius_samples: Ptr<Float>,
|
||||
pub profile: Ptr<Float>,
|
||||
pub rho_eff: Ptr<Float>,
|
||||
pub profile_cdf: Ptr<Float>,
|
||||
pub rho_samples: DevicePtr<Float>,
|
||||
pub radius_samples: DevicePtr<Float>,
|
||||
pub profile: DevicePtr<Float>,
|
||||
pub rho_eff: DevicePtr<Float>,
|
||||
pub profile_cdf: DevicePtr<Float>,
|
||||
}
|
||||
|
||||
impl BSSRDFTable {
|
||||
|
|
@ -165,7 +165,7 @@ pub struct TabulatedBSSRDF {
|
|||
eta: Float,
|
||||
sigma_t: SampledSpectrum,
|
||||
rho: SampledSpectrum,
|
||||
table: Ptr<BSSRDFTable>,
|
||||
table: DevicePtr<BSSRDFTable>,
|
||||
}
|
||||
|
||||
impl TabulatedBSSRDF {
|
||||
|
|
@ -187,7 +187,7 @@ impl TabulatedBSSRDF {
|
|||
eta,
|
||||
sigma_t,
|
||||
rho,
|
||||
table: Ptr::from(table),
|
||||
table: DevicePtr::from(table),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::core::pbrt::Float;
|
|||
use crate::core::sampler::CameraSample;
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::math::lerp;
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
use crate::utils::transform::{AnimatedTransform, Transform};
|
||||
|
||||
use enum_dispatch::enum_dispatch;
|
||||
|
|
@ -113,8 +113,8 @@ pub struct CameraBase {
|
|||
pub min_pos_differential_y: Vector3f,
|
||||
pub min_dir_differential_x: Vector3f,
|
||||
pub min_dir_differential_y: Vector3f,
|
||||
pub film: Ptr<Film>,
|
||||
pub medium: Ptr<Medium>,
|
||||
pub film: DevicePtr<Film>,
|
||||
pub medium: DevicePtr<Medium>,
|
||||
}
|
||||
|
||||
#[enum_dispatch(CameraTrait)]
|
||||
|
|
@ -232,13 +232,13 @@ pub trait CameraTrait {
|
|||
Point3f::new(0., 0., 0.) + self.base().min_pos_differential_x,
|
||||
Vector3f::new(0., 0., 1.) + self.base().min_dir_differential_x,
|
||||
None,
|
||||
&Ptr::default(),
|
||||
&DevicePtr::default(),
|
||||
);
|
||||
let y_ray = Ray::new(
|
||||
Point3f::new(0., 0., 0.) + self.base().min_pos_differential_y,
|
||||
Vector3f::new(0., 0., 1.) + self.base().min_dir_differential_y,
|
||||
None,
|
||||
&Ptr::default(),
|
||||
&DevicePtr::default(),
|
||||
);
|
||||
let n_down = Vector3f::from(n_down_z);
|
||||
let tx = -(n_down.dot(y_ray.o.into())) / n_down.dot(x_ray.d);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::core::geometry::{
|
|||
Bounds2f, Bounds2fi, Bounds2i, Normal3f, Point2f, Point2i, Point3f, Tuple, Vector2f, Vector2fi,
|
||||
Vector2i, Vector3f,
|
||||
};
|
||||
use crate::core::image::{Image, PixelFormat};
|
||||
use crate::core::image::{DeviceImage, PixelFormat};
|
||||
use crate::core::interaction::SurfaceInteraction;
|
||||
use crate::core::pbrt::Float;
|
||||
use crate::core::spectrum::{Spectrum, SpectrumTrait, StandardSpectra};
|
||||
|
|
@ -17,7 +17,7 @@ use crate::utils::AtomicFloat;
|
|||
use crate::utils::containers::Array2D;
|
||||
use crate::utils::math::linear_least_squares;
|
||||
use crate::utils::math::{SquareMatrix, wrap_equal_area_square};
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
use crate::utils::sampling::VarianceEstimator;
|
||||
use crate::utils::transform::AnimatedTransform;
|
||||
|
||||
|
|
@ -472,7 +472,7 @@ impl PixelSensor {
|
|||
|
||||
pub fn new_with_white_balance(
|
||||
output_colorspace: &RGBColorSpace,
|
||||
sensor_illum: Ptr<Spectrum>,
|
||||
sensor_illum: DevicePtr<Spectrum>,
|
||||
imaging_ratio: Float,
|
||||
spectra: *const StandardSpectra,
|
||||
) -> Self {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::core::pbrt::Float;
|
|||
use crate::filters::*;
|
||||
use crate::utils::containers::Array2D;
|
||||
use crate::utils::math::{gaussian, gaussian_integral, lerp, sample_tent, windowed_sinc};
|
||||
use crate::utils::sampling::PiecewiseConstant2D;
|
||||
use crate::utils::sampling::DevicePiecewiseConstant2D;
|
||||
use enum_dispatch::enum_dispatch;
|
||||
|
||||
pub struct FilterSample {
|
||||
|
|
@ -15,7 +15,7 @@ pub struct FilterSample {
|
|||
#[derive(Clone, Debug, Copy)]
|
||||
pub struct FilterSampler {
|
||||
pub domain: Bounds2f,
|
||||
pub distrib: PiecewiseConstant2D,
|
||||
pub distrib: DevicePiecewiseConstant2D,
|
||||
pub f: Array2D<Float>,
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ impl FilterSampler {
|
|||
f[(x as i32, y as i32)] = func(p);
|
||||
}
|
||||
}
|
||||
let distrib = PiecewiseConstant2D::new_with_bounds(&f, domain);
|
||||
let distrib = DevicePiecewiseConstant2D::new_with_bounds(&f, domain);
|
||||
Self { domain, f, distrib }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use super::{Normal3f, Point3f, Point3fi, Vector3f, VectorLike};
|
|||
use crate::core::medium::Medium;
|
||||
use crate::core::pbrt::Float;
|
||||
use crate::utils::math::{next_float_down, next_float_up};
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
|
@ -10,7 +10,7 @@ pub struct Ray {
|
|||
pub o: Point3f,
|
||||
pub d: Vector3f,
|
||||
pub time: Float,
|
||||
pub medium: Ptr<Medium>,
|
||||
pub medium: DevicePtr<Medium>,
|
||||
// We do this instead of creating a trait for Rayable or some gnarly thing like that
|
||||
pub has_differentials: bool,
|
||||
pub differential: RayDifferential,
|
||||
|
|
@ -21,7 +21,7 @@ impl Default for Ray {
|
|||
Self {
|
||||
o: Point3f::new(0.0, 0.0, 0.0),
|
||||
d: Vector3f::new(0.0, 0.0, 0.0),
|
||||
medium: Ptr::null(),
|
||||
medium: DevicePtr::null(),
|
||||
time: 0.0,
|
||||
has_differentials: false,
|
||||
differential: RayDifferential::default(),
|
||||
|
|
@ -35,7 +35,7 @@ impl Ray {
|
|||
o,
|
||||
d,
|
||||
time: time.unwrap_or_else(|| Self::default().time),
|
||||
medium: Ptr::from(medium),
|
||||
medium: DevicePtr::from(medium),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ impl Ray {
|
|||
o: origin,
|
||||
d,
|
||||
time,
|
||||
medium: Ptr::null(),
|
||||
medium: DevicePtr::null(),
|
||||
has_differentials: false,
|
||||
differential: RayDifferential::default(),
|
||||
}
|
||||
|
|
@ -99,7 +99,7 @@ impl Ray {
|
|||
o: pf,
|
||||
d,
|
||||
time,
|
||||
medium: Ptr::null(),
|
||||
medium: DevicePtr::null(),
|
||||
has_differentials: false,
|
||||
differential: RayDifferential::default(),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,87 +66,75 @@ pub enum Pixels {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Image {
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct ImageBase {
|
||||
pub format: PixelFormat,
|
||||
pub pixels: Pixels,
|
||||
pub encoding: ColorEncoding,
|
||||
pub resolution: Point2i,
|
||||
pub n_channels: i32,
|
||||
}
|
||||
|
||||
impl Image {
|
||||
pub fn resolution(&self) -> Point2i {
|
||||
self.resolution
|
||||
}
|
||||
|
||||
pub fn is_valid(&self) -> bool {
|
||||
self.resolution.x() > 0. && self.resolution.y() > 0.
|
||||
}
|
||||
|
||||
pub fn format(&self) -> PixelFormat {
|
||||
self.format
|
||||
}
|
||||
|
||||
pub fn n_channels(&self) -> i32 {
|
||||
self.n_channels
|
||||
}
|
||||
|
||||
pub fn pixel_offset(&self, p: Point2i) -> u32 {
|
||||
let width = self.resolution.x() as u32;
|
||||
let idx = p.y() as u32 * width + p.x() as u32;
|
||||
idx * (self.n_channels as u32)
|
||||
}
|
||||
|
||||
pub fn get_channel_with_wrap(&self, p: Point2i, c: i32, wrap_mode: WrapMode2D) -> Float {
|
||||
if !self.remap_pixel_coords(&mut p, wrap_mode) {
|
||||
return 0.;
|
||||
}
|
||||
|
||||
let offset = self.pixel_offset(p) + c;
|
||||
unsafe {
|
||||
match self.pixels {
|
||||
Pixels::U8(ptr) => {
|
||||
let raw_u8 = *ptr.add(offset);
|
||||
self.encoding.to_linear_scalar(raw_u8)
|
||||
}
|
||||
Pixels::F16(ptr) => {
|
||||
let half_bits = *ptr.add(offset);
|
||||
f16_to_f32(f16::from_bits(half_bits))
|
||||
}
|
||||
Pixels::F32(ptr) => *ptr.add(offset),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_channel(&self, p: Point2i, c: i32) -> Float {
|
||||
self.get_channel_with_wrap(p, c, WrapMode::Clamp.into())
|
||||
}
|
||||
|
||||
impl ImageBase {
|
||||
pub fn remap_pixel_coords(&self, p: &mut Point2i, wrap_mode: WrapMode2D) -> bool {
|
||||
let resolution = self.resolution;
|
||||
for i in 0..2 {
|
||||
if p[i] >= 0 && p[i] < self.resolution[i] {
|
||||
if p[i] >= 0 && p[i] < resolution[i] {
|
||||
continue;
|
||||
}
|
||||
match wrap_mode.uv[i] {
|
||||
WrapMode::Black => return false,
|
||||
WrapMode::Clamp => p[i] = p[i].clamp(0, self.resolution[i] - 1),
|
||||
WrapMode::Repeat => p[i] = p[i].rem_euclid(self.resolution[i]),
|
||||
WrapMode::Clamp => p[i] = p[i].clamp(0, resolution[i] - 1),
|
||||
WrapMode::Repeat => p[i] = p[i].rem_euclid(resolution[i]),
|
||||
WrapMode::OctahedralSphere => {
|
||||
p[i] = p[i].clamp(0, self.resolution[i] - 1);
|
||||
p[i] = p[i].clamp(0, resolution[i] - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct DeviceImage {
|
||||
pub base: ImageBase,
|
||||
pub pixels: Pixels,
|
||||
}
|
||||
|
||||
impl DeviceImage {
|
||||
pub fn base(&self) -> ImageBase {
|
||||
self.base
|
||||
}
|
||||
|
||||
pub fn resolution(&self) -> Point2i {
|
||||
self.base.resolution
|
||||
}
|
||||
|
||||
pub fn is_valid(&self) -> bool {
|
||||
self.resolution().x() > 0 && self.resolution().y() > 0
|
||||
}
|
||||
|
||||
pub fn format(&self) -> PixelFormat {
|
||||
self.base().format
|
||||
}
|
||||
|
||||
pub fn n_channels(&self) -> i32 {
|
||||
self.base().n_channels
|
||||
}
|
||||
|
||||
pub fn pixel_offset(&self, p: Point2i) -> u32 {
|
||||
let width = self.resolution().x() as u32;
|
||||
let idx = p.y() as u32 * width + p.x() as u32;
|
||||
idx * (self.n_channels() as u32)
|
||||
}
|
||||
|
||||
pub fn bilerp_channel(&self, p: Point2f, c: i32) -> Float {
|
||||
self.bilerp_channel_with_wrap(p, c, WrapMode::Clamp.into())
|
||||
}
|
||||
|
||||
pub fn bilerp_channel_with_wrap(&self, p: Point2f, c: i32, wrap_mode: WrapMode2D) -> Float {
|
||||
let x = p.x() * self.resolution.x() as Float - 0.5;
|
||||
let y = p.y() * self.resolution.y() as Float - 0.5;
|
||||
let x = p.x() * self.resolution().x() as Float - 0.5;
|
||||
let y = p.y() * self.resolution().y() as Float - 0.5;
|
||||
let xi = x.floor() as i32;
|
||||
let yi = y.floor() as i32;
|
||||
let dx = x - xi as Float;
|
||||
|
|
@ -157,22 +145,51 @@ impl Image {
|
|||
let v11 = self.get_channel_with_wrap(Point2i::new(xi + 1, yi + 1), c, wrap_mode);
|
||||
lerp(dy, lerp(dx, v00, v10), lerp(dx, v01, v11))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lookup_nearest_channel_with_wrap(
|
||||
&self,
|
||||
p: Point2f,
|
||||
c: i32,
|
||||
wrap_mode: WrapMode2D,
|
||||
) -> Float {
|
||||
pub trait ImageAccess {
|
||||
fn get_channel_with_wrap(&self, p: Point2i, c: i32, wrap_mode: WrapMode2D) -> Float;
|
||||
fn get_channel(&self, p: Point2i, c: i32) -> Float;
|
||||
fn lookup_nearest_channel_with_wrap(&self, p: Point2f, c: i32, wrap_mode: WrapMode2D) -> Float;
|
||||
fn lookup_nearest_channel(&self, p: Point2f, c: i32) -> Float;
|
||||
}
|
||||
|
||||
impl ImageAccess for DeviceImage {
|
||||
fn get_channel_with_wrap(&self, mut p: Point2i, c: i32, wrap_mode: WrapMode2D) -> Float {
|
||||
if !self.base.remap_pixel_coords(&mut p, wrap_mode) {
|
||||
return 0.;
|
||||
}
|
||||
|
||||
let offset = self.pixel_offset(p) + c as u32;
|
||||
unsafe {
|
||||
match self.pixels {
|
||||
Pixels::U8(ptr) => {
|
||||
let raw_u8 = *ptr.add(offset as usize);
|
||||
self.base().encoding.to_linear_scalar(raw_u8)
|
||||
}
|
||||
Pixels::F16(ptr) => {
|
||||
let half_bits: u16 = *ptr.add(offset as usize) as u16;
|
||||
f16_to_f32(half_bits)
|
||||
}
|
||||
Pixels::F32(ptr) => *ptr.add(offset as usize),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_channel(&self, p: Point2i, c: i32) -> Float {
|
||||
self.get_channel_with_wrap(p, c, WrapMode::Clamp.into())
|
||||
}
|
||||
|
||||
fn lookup_nearest_channel_with_wrap(&self, p: Point2f, c: i32, wrap_mode: WrapMode2D) -> Float {
|
||||
let pi = Point2i::new(
|
||||
p.x() as i32 * self.resolution.x(),
|
||||
p.y() as i32 * self.resolution.y(),
|
||||
p.x() as i32 * self.resolution().x(),
|
||||
p.y() as i32 * self.resolution().y(),
|
||||
);
|
||||
|
||||
self.get_channel_with_wrap(pi, c, wrap_mode)
|
||||
}
|
||||
|
||||
pub fn lookup_nearest_channel(&self, p: Point2f, c: i32) -> Float {
|
||||
fn lookup_nearest_channel(&self, p: Point2f, c: i32) -> Float {
|
||||
self.lookup_nearest_channel_with_wrap(p, c, WrapMode::Clamp.into())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::core::camera::{Camera, CameraTrait};
|
|||
use crate::core::geometry::{
|
||||
Normal3f, Point2f, Point3f, Point3fi, Ray, RayDifferential, Vector3f, VectorLike,
|
||||
};
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::DeviceImage;
|
||||
use crate::core::light::{Light, LightTrait};
|
||||
use crate::core::material::{
|
||||
Material, MaterialEvalContext, MaterialTrait, NormalBumpEvalContext, bump_map, normal_map,
|
||||
|
|
@ -16,7 +16,7 @@ use crate::core::sampler::{Sampler, SamplerTrait};
|
|||
use crate::core::shape::Shape;
|
||||
use crate::core::texture::{GPUFloatTexture, UniversalTextureEvaluator};
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::math::{clamp, difference_of_products, square};
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use std::any::Any;
|
||||
|
|
@ -31,7 +31,7 @@ pub struct InteractionBase {
|
|||
pub wo: Vector3f,
|
||||
pub uv: Point2f,
|
||||
pub medium_interface: MediumInterface,
|
||||
pub medium: Ptr<Medium>,
|
||||
pub medium: DevicePtr<Medium>,
|
||||
}
|
||||
|
||||
impl InteractionBase {
|
||||
|
|
@ -49,11 +49,11 @@ impl InteractionBase {
|
|||
wo: wo.normalize(),
|
||||
time,
|
||||
medium_interface: MediumInterface::default(),
|
||||
medium: Ptr::null(),
|
||||
medium: DevicePtr::null(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_medium(p: Point3f, wo: Vector3f, time: Float, medium: Ptr<Medium>) -> Self {
|
||||
pub fn new_medium(p: Point3f, wo: Vector3f, time: Float, medium: DevicePtr<Medium>) -> Self {
|
||||
Self {
|
||||
pi: Point3fi::new_from_point(p),
|
||||
n: Normal3f::zero(),
|
||||
|
|
@ -114,7 +114,7 @@ pub trait InteractionTrait {
|
|||
false
|
||||
}
|
||||
|
||||
fn get_medium(&self, w: Vector3f) -> Ptr<Medium> {
|
||||
fn get_medium(&self, w: Vector3f) -> DevicePtr<Medium> {
|
||||
let data = self.get_common();
|
||||
if !data.medium_interface.inside.is_null() || !data.medium_interface.outside.is_null() {
|
||||
if w.dot(data.n.into()) > 0.0 {
|
||||
|
|
@ -225,9 +225,9 @@ pub struct SurfaceInteraction {
|
|||
pub dndv: Normal3f,
|
||||
pub shading: ShadingGeom,
|
||||
pub face_index: u32,
|
||||
pub area_light: Ptr<Light>,
|
||||
pub material: Ptr<Material>,
|
||||
pub shape: Ptr<Shape>,
|
||||
pub area_light: DevicePtr<Light>,
|
||||
pub material: DevicePtr<Material>,
|
||||
pub shape: DevicePtr<Shape>,
|
||||
pub dpdx: Vector3f,
|
||||
pub dpdy: Vector3f,
|
||||
pub dudx: Float,
|
||||
|
|
@ -412,8 +412,8 @@ impl SurfaceInteraction {
|
|||
fn compute_bump_geom(
|
||||
&mut self,
|
||||
tex_eval: &UniversalTextureEvaluator,
|
||||
displacement: Ptr<GPUFloatTexture>,
|
||||
normal_image: Ptr<Image>,
|
||||
displacement: DevicePtr<GPUFloatTexture>,
|
||||
normal_image: DevicePtr<DeviceImage>,
|
||||
) {
|
||||
let ctx = NormalBumpEvalContext::from(&*self);
|
||||
let (dpdu, dpdv) = if !displacement.is_null() {
|
||||
|
|
@ -536,7 +536,7 @@ impl InteractionTrait for SurfaceInteraction {
|
|||
&mut self.common
|
||||
}
|
||||
|
||||
fn get_medium(&self, w: Vector3f) -> Ptr<Medium> {
|
||||
fn get_medium(&self, w: Vector3f) -> DevicePtr<Medium> {
|
||||
let interface = self.common.medium_interface;
|
||||
if self.n().dot(w.into()) > 0.0 {
|
||||
interface.outside
|
||||
|
|
@ -583,16 +583,16 @@ impl SurfaceInteraction {
|
|||
dndu,
|
||||
dndv,
|
||||
},
|
||||
material: Ptr::null(),
|
||||
material: DevicePtr::null(),
|
||||
face_index: 0,
|
||||
area_light: Ptr::null(),
|
||||
area_light: DevicePtr::null(),
|
||||
dpdx: Vector3f::zero(),
|
||||
dpdy: Vector3f::zero(),
|
||||
dudx: 0.0,
|
||||
dudy: 0.0,
|
||||
dvdx: 0.0,
|
||||
dvdy: 0.0,
|
||||
shape: Ptr::null(),
|
||||
shape: DevicePtr::null(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -658,13 +658,13 @@ impl SurfaceInteraction {
|
|||
ray_medium: &Medium,
|
||||
prim_medium_interface: MediumInterface,
|
||||
) {
|
||||
self.material = Ptr::from(mtl);
|
||||
self.area_light = Ptr::from(area);
|
||||
self.material = DevicePtr::from(mtl);
|
||||
self.area_light = DevicePtr::from(area);
|
||||
|
||||
if prim_medium_interface.is_medium_transition() {
|
||||
self.common.medium_interface = prim_medium_interface;
|
||||
} else {
|
||||
self.common.medium = Ptr::from(ray_medium);
|
||||
self.common.medium = DevicePtr::from(ray_medium);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -681,7 +681,7 @@ impl MediumInteraction {
|
|||
p: Point3f,
|
||||
wo: Vector3f,
|
||||
time: Float,
|
||||
medium: Ptr<Medium>,
|
||||
medium: DevicePtr<Medium>,
|
||||
phase: PhaseFunction,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::core::geometry::{
|
|||
Bounds2f, Bounds3f, DirectionCone, Normal3f, Point2f, Point2i, Point3f, Point3fi, Ray,
|
||||
Vector3f, VectorLike, cos_theta,
|
||||
};
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::DeviceImage;
|
||||
use crate::core::interaction::{
|
||||
Interaction, InteractionBase, InteractionTrait, MediumInteraction, SimpleInteraction,
|
||||
SurfaceInteraction,
|
||||
|
|
@ -17,8 +17,8 @@ use crate::spectra::{
|
|||
};
|
||||
use crate::utils::Transform;
|
||||
use crate::utils::math::{equal_area_sphere_to_square, radians, safe_sqrt, smooth_step, square};
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::sampling::PiecewiseConstant2D;
|
||||
use crate::utils::ptr::{DevicePtr, Ptr};
|
||||
use crate::utils::sampling::DevicePiecewiseConstant2D;
|
||||
use crate::{Float, PI};
|
||||
use bitflags::bitflags;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::core::bsdf::BSDF;
|
|||
use crate::core::bssrdf::BSSRDF;
|
||||
use crate::core::bxdf::BxDF;
|
||||
use crate::core::geometry::{Frame, Normal3f, Point2f, Point3f, Vector2f, Vector3f, VectorLike};
|
||||
use crate::core::image::{Image, WrapMode, WrapMode2D};
|
||||
use crate::core::image::{DeviceImage, WrapMode, WrapMode2D};
|
||||
use crate::core::interaction::{Interaction, InteractionTrait, ShadingGeom, SurfaceInteraction};
|
||||
use crate::core::scattering::TrowbridgeReitzDistribution;
|
||||
use crate::core::spectrum::{Spectrum, SpectrumTrait};
|
||||
|
|
@ -19,7 +19,7 @@ use crate::core::texture::{
|
|||
};
|
||||
use crate::materials::*;
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::hash::hash_float;
|
||||
use crate::utils::math::clamp;
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ impl From<&NormalBumpEvalContext> for TextureEvalContext {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn normal_map(normal_map: &Image, ctx: &NormalBumpEvalContext) -> (Vector3f, Vector3f) {
|
||||
pub fn normal_map(normal_map: &DeviceImage, ctx: &NormalBumpEvalContext) -> (Vector3f, Vector3f) {
|
||||
let wrap = WrapMode2D::from(WrapMode::Repeat);
|
||||
let uv = Point2f::new(ctx.uv[0], 1. - ctx.uv[1]);
|
||||
let r = normal_map.bilerp_channel_with_wrap(uv, 0, wrap);
|
||||
|
|
@ -125,7 +125,7 @@ pub fn bump_map<T: TextureEvaluator>(
|
|||
displacement: &GPUFloatTexture,
|
||||
ctx: &NormalBumpEvalContext,
|
||||
) -> (Vector3f, Vector3f) {
|
||||
debug_assert!(tex_eval.can_evaluate(&[Ptr::from(displacement)], &[]));
|
||||
debug_assert!(tex_eval.can_evaluate(&[DevicePtr::from(displacement)], &[]));
|
||||
let mut du = 0.5 * (ctx.dudx.abs() + ctx.dudy.abs());
|
||||
if du == 0.0 {
|
||||
du = 0.0005;
|
||||
|
|
@ -173,8 +173,8 @@ pub trait MaterialTrait {
|
|||
) -> Option<BSSRDF>;
|
||||
|
||||
fn can_evaluate_textures(&self, tex_eval: &dyn TextureEvaluator) -> bool;
|
||||
fn get_normal_map(&self) -> Option<&Image>;
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture>;
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage>;
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture>;
|
||||
fn has_subsurface_scattering(&self) -> bool;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::spectra::{
|
|||
};
|
||||
use crate::utils::containers::SampledGrid;
|
||||
use crate::utils::math::{clamp, square};
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
use crate::utils::rng::Rng;
|
||||
use crate::utils::transform::Transform;
|
||||
|
||||
|
|
@ -829,8 +829,8 @@ impl MediumTrait for NanoVDBMedium {
|
|||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct MediumInterface {
|
||||
pub inside: Ptr<Medium>,
|
||||
pub outside: Ptr<Medium>,
|
||||
pub inside: DevicePtr<Medium>,
|
||||
pub outside: DevicePtr<Medium>,
|
||||
}
|
||||
|
||||
unsafe impl Send for MediumInterface {}
|
||||
|
|
@ -839,17 +839,32 @@ unsafe impl Sync for MediumInterface {}
|
|||
impl Default for MediumInterface {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
inside: Ptr::null(),
|
||||
outside: Ptr::null(),
|
||||
inside: DevicePtr::null(),
|
||||
outside: DevicePtr::null(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Medium> for MediumInterface {
|
||||
fn from(medium: Medium) -> Self {
|
||||
Self {
|
||||
inside: DevicePtr::from(&medium),
|
||||
outside: DevicePtr::from(&medium),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Medium> for MediumInterface {
|
||||
fn from(medium: &Medium) -> Self {
|
||||
Self::from(medium.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl MediumInterface {
|
||||
pub fn new(inside: &Medium, outside: &Medium) -> Self {
|
||||
Self {
|
||||
inside: Ptr::from(inside),
|
||||
outside: Ptr::from(outside),
|
||||
inside: DevicePtr::from(inside),
|
||||
outside: DevicePtr::from(outside),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::core::medium::{Medium, MediumInterface};
|
|||
use crate::core::pbrt::Float;
|
||||
use crate::core::shape::{Shape, ShapeIntersection, ShapeTrait};
|
||||
use crate::core::texture::{GPUFloatTexture, TextureEvalContext};
|
||||
use crate::utils::ArenaPtr;
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::hash::hash_float;
|
||||
use crate::utils::transform::{AnimatedTransform, Transform};
|
||||
|
||||
|
|
@ -88,13 +88,13 @@ impl PrimitiveTrait for GeometricPrimitive {
|
|||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct SimplePrimitive {
|
||||
shape: ArenaPtr<Shape>,
|
||||
material: ArenaPtr<Material>,
|
||||
shape: Ptr<Shape>,
|
||||
material: Ptr<Material>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TransformedPrimitive {
|
||||
pub primitive: ArenaPtr<Primitive>,
|
||||
pub primitive: Ptr<Primitive>,
|
||||
pub render_from_primitive: Transform,
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ impl PrimitiveTrait for TransformedPrimitive {
|
|||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct AnimatedPrimitive {
|
||||
primitive: ArenaPtr<Primitive>,
|
||||
primitive: Ptr<Primitive>,
|
||||
render_from_primitive: AnimatedTransform,
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ impl PrimitiveTrait for AnimatedPrimitive {
|
|||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct BVHAggregatePrimitive {
|
||||
max_prims_in_node: u32,
|
||||
primitives: *const ArenaPtr<Primitive>,
|
||||
primitives: *const Ptr<Primitive>,
|
||||
nodes: *const LinearBVHNode,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::core::filter::FilterTrait;
|
|||
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, find_interval};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::containers::Array2D;
|
||||
use crate::utils::math::{
|
||||
BinaryPermuteScrambler, DigitPermutation, FastOwenScrambler, NoRandomizer, OwenScrambler,
|
||||
|
|
@ -103,7 +103,7 @@ pub struct HaltonSampler {
|
|||
mult_inverse: [u64; 2],
|
||||
halton_index: u64,
|
||||
dim: u32,
|
||||
digit_permutations: Ptr<DigitPermutation>,
|
||||
digit_permutations: DevicePtr<DigitPermutation>,
|
||||
}
|
||||
|
||||
impl HaltonSampler {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::core::material::Material;
|
|||
use crate::core::medium::{Medium, MediumInterface};
|
||||
use crate::shapes::*;
|
||||
use crate::utils::math::{next_float_down, next_float_up};
|
||||
use crate::utils::{Ptr, Transform};
|
||||
use crate::utils::{DevicePtr, Transform};
|
||||
use crate::{Float, PI};
|
||||
use enum_dispatch::enum_dispatch;
|
||||
|
||||
|
|
@ -118,7 +118,12 @@ impl ShapeSampleContext {
|
|||
}
|
||||
|
||||
pub fn spawn_ray(&self, w: Vector3f) -> Ray {
|
||||
Ray::new(self.offset_ray_origin(w), w, Some(self.time), &Ptr::null())
|
||||
Ray::new(
|
||||
self.offset_ray_origin(w),
|
||||
w,
|
||||
Some(self.time),
|
||||
&DevicePtr::null(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::spectra::{
|
|||
SampledWavelengths,
|
||||
};
|
||||
use crate::textures::*;
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::Transform;
|
||||
use crate::utils::math::square;
|
||||
use crate::{Float, INV_2_PI, INV_PI, PI};
|
||||
|
|
@ -428,8 +428,8 @@ pub trait TextureEvaluator: Send + Sync {
|
|||
|
||||
fn can_evaluate(
|
||||
&self,
|
||||
_ftex: &[Ptr<GPUFloatTexture>],
|
||||
_stex: &[Ptr<GPUSpectrumTexture>],
|
||||
_ftex: &[DevicePtr<GPUFloatTexture>],
|
||||
_stex: &[DevicePtr<GPUSpectrumTexture>],
|
||||
) -> bool;
|
||||
}
|
||||
|
||||
|
|
@ -453,8 +453,8 @@ impl TextureEvaluator for UniversalTextureEvaluator {
|
|||
|
||||
fn can_evaluate(
|
||||
&self,
|
||||
_float_textures: &[Ptr<GPUFloatTexture>],
|
||||
_spectrum_textures: &[Ptr<GPUSpectrumTexture>],
|
||||
_float_textures: &[DevicePtr<GPUFloatTexture>],
|
||||
_spectrum_textures: &[DevicePtr<GPUSpectrumTexture>],
|
||||
) -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::PI;
|
||||
use crate::core::color::{RGB, XYZ};
|
||||
use crate::core::geometry::*;
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::{DeviceImage, ImageAccess};
|
||||
use crate::core::interaction::{
|
||||
Interaction, InteractionTrait, MediumInteraction, SurfaceInteraction,
|
||||
};
|
||||
|
|
@ -17,17 +17,17 @@ use crate::core::texture::{
|
|||
};
|
||||
use crate::spectra::*;
|
||||
use crate::utils::hash::hash_float;
|
||||
use crate::utils::{Ptr, Transform};
|
||||
use crate::utils::{DevicePtr, Transform};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Copy)]
|
||||
pub struct DiffuseAreaLight {
|
||||
pub base: LightBase,
|
||||
pub shape: Ptr<Shape>,
|
||||
pub alpha: Ptr<GPUFloatTexture>,
|
||||
pub image_color_space: Ptr<RGBColorSpace>,
|
||||
pub lemit: Ptr<DenselySampledSpectrum>,
|
||||
pub image: Ptr<Image>,
|
||||
pub shape: DevicePtr<Shape>,
|
||||
pub alpha: DevicePtr<GPUFloatTexture>,
|
||||
pub image_color_space: DevicePtr<RGBColorSpace>,
|
||||
pub lemit: DevicePtr<DenselySampledSpectrum>,
|
||||
pub image: DevicePtr<DeviceImage>,
|
||||
pub area: Float,
|
||||
pub two_sided: bool,
|
||||
pub scale: Float,
|
||||
|
|
@ -175,8 +175,8 @@ impl LightTrait for DiffuseAreaLight {
|
|||
fn bounds(&self) -> Option<LightBounds> {
|
||||
let mut phi = 0.;
|
||||
if !self.image.is_null() {
|
||||
for y in 0..self.image.resolution.y() {
|
||||
for x in 0..self.image.resolution.x() {
|
||||
for y in 0..self.image.base.resolution.y() {
|
||||
for x in 0..self.image.base.resolution.x() {
|
||||
for c in 0..3 {
|
||||
phi += self.image.get_channel(Point2i::new(x, y), c);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ use crate::core::interaction::{Interaction, InteractionBase, SimpleInteraction};
|
|||
use crate::core::light::{LightBase, LightBounds, LightLiSample, LightSampleContext, LightTrait};
|
||||
use crate::core::spectrum::SpectrumTrait;
|
||||
use crate::spectra::{DenselySampledSpectrum, SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::{ArenaPtr, Ptr};
|
||||
use crate::utils::{DevicePtr, Ptr};
|
||||
use crate::{Float, PI};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct DistantLight {
|
||||
pub base: LightBase,
|
||||
pub lemit: Ptr<DenselySampledSpectrum>,
|
||||
pub lemit: DevicePtr<DenselySampledSpectrum>,
|
||||
pub scale: Float,
|
||||
pub scene_center: Point3f,
|
||||
pub scene_radius: Float,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::core::geometry::{Bounds3f, Normal3f, Point2f, Point2i, Point3f, Ray, Vector3f};
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::{DeviceImage, ImageAccess};
|
||||
use crate::core::light::{
|
||||
LightBase, LightBounds, LightLiSample, LightSampleContext, LightTrait, LightType,
|
||||
};
|
||||
|
|
@ -7,17 +7,17 @@ use crate::core::medium::MediumInterface;
|
|||
use crate::core::spectrum::{Spectrum, SpectrumTrait};
|
||||
use crate::spectra::{DenselySampledSpectrum, SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::math::equal_area_sphere_to_square;
|
||||
use crate::utils::sampling::PiecewiseConstant2D;
|
||||
use crate::utils::{Ptr, Transform};
|
||||
use crate::utils::sampling::DevicePiecewiseConstant2D;
|
||||
use crate::utils::{DevicePtr, Transform};
|
||||
use crate::{Float, PI};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct GoniometricLight {
|
||||
pub base: LightBase,
|
||||
iemit: DenselySampledSpectrum,
|
||||
scale: Float,
|
||||
image: Ptr<Image>,
|
||||
distrib: Ptr<PiecewiseConstant2D>,
|
||||
pub iemit: DenselySampledSpectrum,
|
||||
pub scale: Float,
|
||||
pub image: DevicePtr<DeviceImage>,
|
||||
pub distrib: DevicePtr<DevicePiecewiseConstant2D>,
|
||||
}
|
||||
|
||||
impl GoniometricLight {
|
||||
|
|
@ -77,13 +77,14 @@ impl LightTrait for GoniometricLight {
|
|||
|
||||
#[cfg(not(target_os = "cuda"))]
|
||||
fn phi(&self, lambda: SampledWavelengths) -> SampledSpectrum {
|
||||
let resolution = self.image.resolution();
|
||||
let mut sum_y = 0.;
|
||||
for y in 0..self.image.resolution.y() {
|
||||
for x in 0..self.image.resolution.x() {
|
||||
for y in 0..resolution.y() {
|
||||
for x in 0..resolution.x() {
|
||||
sum_y += self.image.get_channel(Point2i::new(x, y), 0);
|
||||
}
|
||||
}
|
||||
self.scale * self.iemit.sample(&lambda) * 4. * PI * sum_y
|
||||
/ (self.image.resolution.x() * self.image.resolution.y()) as Float
|
||||
/ (resolution.x() * resolution.y()) as Float
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,10 @@
|
|||
use crate::{
|
||||
core::{
|
||||
geometry::{Frame, VectorLike},
|
||||
interaction::InteractionBase,
|
||||
},
|
||||
spectra::{RGBColorSpace, RGBIlluminantSpectrum},
|
||||
utils::{
|
||||
math::{clamp, equal_area_sphere_to_square, equal_area_square_to_sphere, square},
|
||||
sampling::{
|
||||
AliasTable, PiecewiseConstant2D, WindowedPiecewiseConstant2D, sample_uniform_sphere,
|
||||
uniform_sphere_pdf,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::core::color::RGB;
|
||||
use crate::core::geometry::{
|
||||
Bounds2f, Bounds3f, Normal3f, Point2f, Point2i, Point3f, Ray, Vector2f, Vector3f,
|
||||
};
|
||||
use crate::core::image::{Image, PixelFormat, WrapMode};
|
||||
use crate::core::geometry::{Frame, VectorLike};
|
||||
use crate::core::image::{DeviceImage, ImageAccess, PixelFormat, WrapMode};
|
||||
use crate::core::interaction::InteractionBase;
|
||||
use crate::core::interaction::{Interaction, SimpleInteraction};
|
||||
use crate::core::light::{
|
||||
LightBase, LightBounds, LightLiSample, LightSampleContext, LightTrait, LightType,
|
||||
|
|
@ -25,8 +12,14 @@ use crate::core::light::{
|
|||
use crate::core::medium::{Medium, MediumInterface};
|
||||
use crate::core::spectrum::{Spectrum, SpectrumTrait};
|
||||
use crate::spectra::{DenselySampledSpectrum, SampledSpectrum, SampledWavelengths};
|
||||
use crate::spectra::{RGBColorSpace, RGBIlluminantSpectrum};
|
||||
use crate::utils::Transform;
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::math::{clamp, equal_area_sphere_to_square, equal_area_square_to_sphere, square};
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
use crate::utils::sampling::{
|
||||
AliasTable, DevicePiecewiseConstant2D, WindowedPiecewiseConstant2D, sample_uniform_sphere,
|
||||
uniform_sphere_pdf,
|
||||
};
|
||||
use crate::{Float, PI};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
@ -34,7 +27,7 @@ use std::sync::Arc;
|
|||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct InfiniteUniformLight {
|
||||
pub base: LightBase,
|
||||
pub lemit: Ptr<DenselySampledSpectrum>,
|
||||
pub lemit: DevicePtr<DenselySampledSpectrum>,
|
||||
pub scale: Float,
|
||||
pub scene_center: Point3f,
|
||||
pub scene_radius: Float,
|
||||
|
|
@ -122,10 +115,10 @@ impl LightTrait for InfiniteUniformLight {
|
|||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct InfiniteImageLight {
|
||||
pub base: LightBase,
|
||||
pub image: Ptr<Image>,
|
||||
pub image_color_space: Ptr<RGBColorSpace>,
|
||||
pub distrib: Ptr<PiecewiseConstant2D>,
|
||||
pub compensated_distrib: Ptr<PiecewiseConstant2D>,
|
||||
pub image: DevicePtr<DeviceImage>,
|
||||
pub image_color_space: DevicePtr<RGBColorSpace>,
|
||||
pub distrib: DevicePtr<DevicePiecewiseConstant2D>,
|
||||
pub compensated_distrib: DevicePtr<DevicePiecewiseConstant2D>,
|
||||
pub scale: Float,
|
||||
pub scene_radius: Float,
|
||||
pub scene_center: Point3f,
|
||||
|
|
@ -258,8 +251,8 @@ impl LightTrait for InfiniteImageLight {
|
|||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct InfinitePortalLight {
|
||||
pub base: LightBase,
|
||||
pub image: Ptr<Image>,
|
||||
pub image_color_space: Ptr<RGBColorSpace>,
|
||||
pub image: DevicePtr<DeviceImage>,
|
||||
pub image_color_space: DevicePtr<RGBColorSpace>,
|
||||
pub scale: Float,
|
||||
pub portal: [Point3f; 4],
|
||||
pub portal_frame: Frame,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::core::light::{
|
|||
};
|
||||
use crate::core::spectrum::SpectrumTrait;
|
||||
use crate::spectra::{DenselySampledSpectrum, SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
use crate::{Float, PI};
|
||||
|
||||
#[repr(C)]
|
||||
|
|
@ -15,7 +15,7 @@ use crate::{Float, PI};
|
|||
pub struct PointLight {
|
||||
pub base: LightBase,
|
||||
pub scale: Float,
|
||||
pub i: Ptr<DenselySampledSpectrum>,
|
||||
pub i: DevicePtr<DenselySampledSpectrum>,
|
||||
}
|
||||
|
||||
impl LightTrait for PointLight {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::core::color::RGB;
|
|||
use crate::core::geometry::{
|
||||
Bounds2f, Bounds3f, Normal3f, Point2f, Point2i, Point3f, Ray, Vector3f, VectorLike, cos_theta,
|
||||
};
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::DeviceImage;
|
||||
use crate::core::light::{
|
||||
LightBase, LightBounds, LightLiSample, LightSampleContext, LightTrait, LightType,
|
||||
};
|
||||
|
|
@ -11,10 +11,10 @@ use crate::core::medium::MediumInterface;
|
|||
use crate::core::spectrum::SpectrumTrait;
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::math::{radians, square};
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
use crate::{
|
||||
spectra::{RGBColorSpace, RGBIlluminantSpectrum},
|
||||
utils::{Transform, sampling::PiecewiseConstant2D},
|
||||
utils::{Transform, sampling::DevicePiecewiseConstant2D},
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
|
|
@ -27,9 +27,9 @@ pub struct ProjectionLight {
|
|||
pub screen_from_light: Transform,
|
||||
pub light_from_screen: Transform,
|
||||
pub a: Float,
|
||||
pub image: Ptr<Image>,
|
||||
pub distrib: Ptr<PiecewiseConstant2D>,
|
||||
pub image_color_space: Ptr<RGBColorSpace>,
|
||||
pub image: DevicePtr<DeviceImage>,
|
||||
pub distrib: DevicePtr<DevicePiecewiseConstant2D>,
|
||||
pub image_color_space: DevicePtr<RGBColorSpace>,
|
||||
}
|
||||
|
||||
impl ProjectionLight {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::core::light::{LightBounds, LightSampleContext};
|
|||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::math::{clamp, lerp, sample_discrete};
|
||||
use crate::utils::math::{safe_sqrt, square};
|
||||
use crate::utils::ptr::{Ptr, Slice};
|
||||
use crate::utils::ptr::{DevicePtr, Slice};
|
||||
use crate::utils::sampling::AliasTable;
|
||||
use crate::{Float, ONE_MINUS_EPSILON, PI};
|
||||
use enum_dispatch::enum_dispatch;
|
||||
|
|
@ -154,14 +154,14 @@ impl CompactLightBounds {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SampledLight {
|
||||
pub light: Ptr<Light>,
|
||||
pub light: DevicePtr<Light>,
|
||||
pub p: Float,
|
||||
}
|
||||
|
||||
impl SampledLight {
|
||||
pub fn new(light: Light, p: Float) -> Self {
|
||||
Self {
|
||||
light: Ptr::from(&light),
|
||||
light: DevicePtr::from(&light),
|
||||
p,
|
||||
}
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ impl LightSamplerTrait for UniformLightSampler {
|
|||
|
||||
let light_index = (u as u32 * self.lights_len).min(self.lights_len - 1) as usize;
|
||||
Some(SampledLight {
|
||||
light: Ptr::from(&self.light(light_index)),
|
||||
light: DevicePtr::from(&self.light(light_index)),
|
||||
p: 1. / self.lights_len as Float,
|
||||
})
|
||||
}
|
||||
|
|
@ -262,7 +262,7 @@ impl LightSamplerTrait for PowerLightSampler {
|
|||
|
||||
let light_ref = &self.lights[light_index as usize];
|
||||
Some(SampledLight {
|
||||
light: Ptr::from(light_ref),
|
||||
light: DevicePtr::from(light_ref),
|
||||
p: pmf,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ use crate::core::interaction::{Interaction, InteractionBase, InteractionTrait, S
|
|||
use crate::core::light::{LightBase, LightBounds, LightLiSample, LightSampleContext, LightTrait};
|
||||
use crate::core::spectrum::SpectrumTrait;
|
||||
use crate::spectra::{DenselySampledSpectrum, SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::{Float, PI};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct SpotLight {
|
||||
pub base: LightBase,
|
||||
pub iemit: Ptr<DenselySampledSpectrum>,
|
||||
pub iemit: DevicePtr<DenselySampledSpectrum>,
|
||||
pub scale: Float,
|
||||
pub cos_falloff_start: Float,
|
||||
pub cos_falloff_end: Float,
|
||||
|
|
|
|||
|
|
@ -4,27 +4,27 @@ use crate::bxdfs::{
|
|||
use crate::core::bsdf::BSDF;
|
||||
use crate::core::bssrdf::BSSRDF;
|
||||
use crate::core::bxdf::BxDF;
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::DeviceImage;
|
||||
use crate::core::material::{Material, MaterialEvalContext, MaterialTrait};
|
||||
use crate::core::scattering::TrowbridgeReitzDistribution;
|
||||
use crate::core::spectrum::{Spectrum, SpectrumTrait};
|
||||
use crate::core::texture::{GPUFloatTexture, GPUSpectrumTexture, TextureEvaluator};
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::math::clamp;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct CoatedDiffuseMaterial {
|
||||
pub normal_map: Ptr<Image>,
|
||||
pub displacement: Ptr<GPUFloatTexture>,
|
||||
pub reflectance: Ptr<GPUSpectrumTexture>,
|
||||
pub albedo: Ptr<GPUSpectrumTexture>,
|
||||
pub u_roughness: Ptr<GPUFloatTexture>,
|
||||
pub v_roughness: Ptr<GPUFloatTexture>,
|
||||
pub thickness: Ptr<GPUFloatTexture>,
|
||||
pub g: Ptr<GPUFloatTexture>,
|
||||
pub eta: Ptr<Spectrum>,
|
||||
pub normal_map: DevicePtr<DeviceImage>,
|
||||
pub displacement: DevicePtr<GPUFloatTexture>,
|
||||
pub reflectance: DevicePtr<GPUSpectrumTexture>,
|
||||
pub albedo: DevicePtr<GPUSpectrumTexture>,
|
||||
pub u_roughness: DevicePtr<GPUFloatTexture>,
|
||||
pub v_roughness: DevicePtr<GPUFloatTexture>,
|
||||
pub thickness: DevicePtr<GPUFloatTexture>,
|
||||
pub g: DevicePtr<GPUFloatTexture>,
|
||||
pub eta: DevicePtr<Spectrum>,
|
||||
pub remap_roughness: bool,
|
||||
pub max_depth: usize,
|
||||
pub n_samples: usize,
|
||||
|
|
@ -42,21 +42,21 @@ impl CoatedDiffuseMaterial {
|
|||
g: &GPUFloatTexture,
|
||||
eta: &Spectrum,
|
||||
displacement: &GPUFloatTexture,
|
||||
normal_map: &Image,
|
||||
normal_map: &DeviceImage,
|
||||
remap_roughness: bool,
|
||||
max_depth: usize,
|
||||
n_samples: usize,
|
||||
) -> Self {
|
||||
Self {
|
||||
displacement: Ptr::from(displacement),
|
||||
normal_map: Ptr::from(normal_map),
|
||||
reflectance: Ptr::from(reflectance),
|
||||
albedo: Ptr::from(albedo),
|
||||
u_roughness: Ptr::from(u_roughness),
|
||||
v_roughness: Ptr::from(v_roughness),
|
||||
thickness: Ptr::from(thickness),
|
||||
g: Ptr::from(g),
|
||||
eta: Ptr::from(eta),
|
||||
displacement: DevicePtr::from(displacement),
|
||||
normal_map: DevicePtr::from(normal_map),
|
||||
reflectance: DevicePtr::from(reflectance),
|
||||
albedo: DevicePtr::from(albedo),
|
||||
u_roughness: DevicePtr::from(u_roughness),
|
||||
v_roughness: DevicePtr::from(v_roughness),
|
||||
thickness: DevicePtr::from(thickness),
|
||||
g: DevicePtr::from(g),
|
||||
eta: DevicePtr::from(eta),
|
||||
remap_roughness,
|
||||
max_depth,
|
||||
n_samples,
|
||||
|
|
@ -115,7 +115,7 @@ impl MaterialTrait for CoatedDiffuseMaterial {
|
|||
self.n_samples,
|
||||
));
|
||||
|
||||
BSDF::new(ctx.ns, ctx.dpdus, Ptr::from(&bxdf))
|
||||
BSDF::new(ctx.ns, ctx.dpdus, DevicePtr::from(&bxdf))
|
||||
}
|
||||
|
||||
fn get_bssrdf<T>(
|
||||
|
|
@ -134,11 +134,11 @@ impl MaterialTrait for CoatedDiffuseMaterial {
|
|||
)
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
Some(&*self.normal_map)
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
self.displacement
|
||||
}
|
||||
|
||||
|
|
@ -150,19 +150,19 @@ impl MaterialTrait for CoatedDiffuseMaterial {
|
|||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct CoatedConductorMaterial {
|
||||
normal_map: Ptr<Image>,
|
||||
displacement: Ptr<GPUFloatTexture>,
|
||||
interface_uroughness: Ptr<GPUFloatTexture>,
|
||||
interface_vroughness: Ptr<GPUFloatTexture>,
|
||||
thickness: Ptr<GPUFloatTexture>,
|
||||
interface_eta: Ptr<Spectrum>,
|
||||
g: Ptr<GPUFloatTexture>,
|
||||
albedo: Ptr<GPUSpectrumTexture>,
|
||||
conductor_uroughness: Ptr<GPUFloatTexture>,
|
||||
conductor_vroughness: Ptr<GPUFloatTexture>,
|
||||
conductor_eta: Ptr<GPUSpectrumTexture>,
|
||||
k: Ptr<GPUSpectrumTexture>,
|
||||
reflectance: Ptr<GPUSpectrumTexture>,
|
||||
normal_map: DevicePtr<DeviceImage>,
|
||||
displacement: DevicePtr<GPUFloatTexture>,
|
||||
interface_uroughness: DevicePtr<GPUFloatTexture>,
|
||||
interface_vroughness: DevicePtr<GPUFloatTexture>,
|
||||
thickness: DevicePtr<GPUFloatTexture>,
|
||||
interface_eta: DevicePtr<Spectrum>,
|
||||
g: DevicePtr<GPUFloatTexture>,
|
||||
albedo: DevicePtr<GPUSpectrumTexture>,
|
||||
conductor_uroughness: DevicePtr<GPUFloatTexture>,
|
||||
conductor_vroughness: DevicePtr<GPUFloatTexture>,
|
||||
conductor_eta: DevicePtr<GPUSpectrumTexture>,
|
||||
k: DevicePtr<GPUSpectrumTexture>,
|
||||
reflectance: DevicePtr<GPUSpectrumTexture>,
|
||||
remap_roughness: bool,
|
||||
max_depth: u32,
|
||||
n_samples: u32,
|
||||
|
|
@ -172,7 +172,7 @@ impl CoatedConductorMaterial {
|
|||
#[allow(clippy::too_many_arguments)]
|
||||
#[cfg(not(target_os = "cuda"))]
|
||||
pub fn new(
|
||||
normal_map: &Image,
|
||||
normal_map: &DeviceImage,
|
||||
displacement: &GPUFloatTexture,
|
||||
interface_uroughness: &GPUFloatTexture,
|
||||
interface_vroughness: &GPUFloatTexture,
|
||||
|
|
@ -190,19 +190,19 @@ impl CoatedConductorMaterial {
|
|||
n_samples: u32,
|
||||
) -> Self {
|
||||
Self {
|
||||
displacement: Ptr::from(displacement),
|
||||
normal_map: Ptr::from(normal_map),
|
||||
interface_uroughness: Ptr::from(interface_uroughness),
|
||||
interface_vroughness: Ptr::from(interface_vroughness),
|
||||
thickness: Ptr::from(thickness),
|
||||
interface_eta: Ptr::from(interface_eta),
|
||||
g: Ptr::from(g),
|
||||
albedo: Ptr::from(albedo),
|
||||
conductor_uroughness: Ptr::from(conductor_uroughness),
|
||||
conductor_vroughness: Ptr::from(conductor_vroughness),
|
||||
conductor_eta: Ptr::from(conductor_eta),
|
||||
k: Ptr::from(k),
|
||||
reflectance: Ptr::from(reflectance),
|
||||
displacement: DevicePtr::from(displacement),
|
||||
normal_map: DevicePtr::from(normal_map),
|
||||
interface_uroughness: DevicePtr::from(interface_uroughness),
|
||||
interface_vroughness: DevicePtr::from(interface_vroughness),
|
||||
thickness: DevicePtr::from(thickness),
|
||||
interface_eta: DevicePtr::from(interface_eta),
|
||||
g: DevicePtr::from(g),
|
||||
albedo: DevicePtr::from(albedo),
|
||||
conductor_uroughness: DevicePtr::from(conductor_uroughness),
|
||||
conductor_vroughness: DevicePtr::from(conductor_vroughness),
|
||||
conductor_eta: DevicePtr::from(conductor_eta),
|
||||
k: DevicePtr::from(k),
|
||||
reflectance: DevicePtr::from(reflectance),
|
||||
remap_roughness,
|
||||
max_depth,
|
||||
n_samples,
|
||||
|
|
@ -285,7 +285,7 @@ impl MaterialTrait for CoatedConductorMaterial {
|
|||
self.max_depth as usize,
|
||||
self.n_samples as usize,
|
||||
));
|
||||
BSDF::new(ctx.ns, ctx.dpdus, Ptr::from(&bxdf))
|
||||
BSDF::new(ctx.ns, ctx.dpdus, DevicePtr::from(&bxdf))
|
||||
}
|
||||
|
||||
fn get_bssrdf<T>(
|
||||
|
|
@ -326,11 +326,11 @@ impl MaterialTrait for CoatedConductorMaterial {
|
|||
tex_eval.can_evaluate(&float_textures, &spectrum_textures)
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
Some(&*self.normal_map)
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
self.displacement
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,40 +6,40 @@ use crate::bxdfs::{
|
|||
use crate::core::bsdf::BSDF;
|
||||
use crate::core::bssrdf::{BSSRDF, BSSRDFTable};
|
||||
use crate::core::bxdf::BxDF;
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::DeviceImage;
|
||||
use crate::core::material::{Material, MaterialEvalContext, MaterialTrait};
|
||||
use crate::core::scattering::TrowbridgeReitzDistribution;
|
||||
use crate::core::spectrum::{Spectrum, SpectrumTrait};
|
||||
use crate::core::texture::{GPUFloatTexture, GPUSpectrumTexture, TextureEvaluator};
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::textures::GPUSpectrumMixTexture;
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::math::clamp;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct HairMaterial {
|
||||
pub sigma_a: Ptr<GPUSpectrumTexture>,
|
||||
pub color: Ptr<GPUSpectrumTexture>,
|
||||
pub eumelanin: Ptr<GPUFloatTexture>,
|
||||
pub pheomelanin: Ptr<GPUFloatTexture>,
|
||||
pub eta: Ptr<GPUFloatTexture>,
|
||||
pub beta_m: Ptr<GPUFloatTexture>,
|
||||
pub beta_n: Ptr<GPUFloatTexture>,
|
||||
pub alpha: Ptr<GPUFloatTexture>,
|
||||
pub sigma_a: DevicePtr<GPUSpectrumTexture>,
|
||||
pub color: DevicePtr<GPUSpectrumTexture>,
|
||||
pub eumelanin: DevicePtr<GPUFloatTexture>,
|
||||
pub pheomelanin: DevicePtr<GPUFloatTexture>,
|
||||
pub eta: DevicePtr<GPUFloatTexture>,
|
||||
pub beta_m: DevicePtr<GPUFloatTexture>,
|
||||
pub beta_n: DevicePtr<GPUFloatTexture>,
|
||||
pub alpha: DevicePtr<GPUFloatTexture>,
|
||||
}
|
||||
|
||||
impl HairMaterial {
|
||||
#[cfg(not(target_os = "cuda"))]
|
||||
pub fn new(
|
||||
sigma_a: Ptr<GPUSpectrumTexture>,
|
||||
color: Ptr<GPUSpectrumTexture>,
|
||||
eumelanin: Ptr<GPUFloatTexture>,
|
||||
pheomelanin: Ptr<GPUFloatTexture>,
|
||||
eta: Ptr<GPUFloatTexture>,
|
||||
beta_m: Ptr<GPUFloatTexture>,
|
||||
beta_n: Ptr<GPUFloatTexture>,
|
||||
alpha: Ptr<GPUFloatTexture>,
|
||||
sigma_a: DevicePtr<GPUSpectrumTexture>,
|
||||
color: DevicePtr<GPUSpectrumTexture>,
|
||||
eumelanin: DevicePtr<GPUFloatTexture>,
|
||||
pheomelanin: DevicePtr<GPUFloatTexture>,
|
||||
eta: DevicePtr<GPUFloatTexture>,
|
||||
beta_m: DevicePtr<GPUFloatTexture>,
|
||||
beta_n: DevicePtr<GPUFloatTexture>,
|
||||
alpha: DevicePtr<GPUFloatTexture>,
|
||||
) -> Self {
|
||||
Self {
|
||||
sigma_a,
|
||||
|
|
@ -76,12 +76,12 @@ impl MaterialTrait for HairMaterial {
|
|||
todo!()
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
Ptr::null()
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
DevicePtr::null()
|
||||
}
|
||||
|
||||
fn has_subsurface_scattering(&self) -> bool {
|
||||
|
|
@ -92,9 +92,9 @@ impl MaterialTrait for HairMaterial {
|
|||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct MeasuredMaterial {
|
||||
pub displacement: Ptr<GPUFloatTexture>,
|
||||
pub normal_map: Ptr<Image>,
|
||||
pub brdf: Ptr<MeasuredBxDFData>,
|
||||
pub displacement: DevicePtr<GPUFloatTexture>,
|
||||
pub normal_map: DevicePtr<DeviceImage>,
|
||||
pub brdf: DevicePtr<MeasuredBxDFData>,
|
||||
}
|
||||
|
||||
impl MaterialTrait for MeasuredMaterial {
|
||||
|
|
@ -121,11 +121,11 @@ impl MaterialTrait for MeasuredMaterial {
|
|||
true
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
Some(&*self.normal_map)
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
self.displacement
|
||||
}
|
||||
|
||||
|
|
@ -137,16 +137,16 @@ impl MaterialTrait for MeasuredMaterial {
|
|||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct SubsurfaceMaterial {
|
||||
pub normal_map: Ptr<Image>,
|
||||
pub displacement: Ptr<GPUFloatTexture>,
|
||||
pub sigma_a: Ptr<GPUSpectrumTexture>,
|
||||
pub sigma_s: Ptr<GPUSpectrumMixTexture>,
|
||||
pub reflectance: Ptr<GPUSpectrumMixTexture>,
|
||||
pub mfp: Ptr<GPUSpectrumMixTexture>,
|
||||
pub normal_map: DevicePtr<DeviceImage>,
|
||||
pub displacement: DevicePtr<GPUFloatTexture>,
|
||||
pub sigma_a: DevicePtr<GPUSpectrumTexture>,
|
||||
pub sigma_s: DevicePtr<GPUSpectrumMixTexture>,
|
||||
pub reflectance: DevicePtr<GPUSpectrumMixTexture>,
|
||||
pub mfp: DevicePtr<GPUSpectrumMixTexture>,
|
||||
pub eta: Float,
|
||||
pub scale: Float,
|
||||
pub u_roughness: Ptr<GPUFloatTexture>,
|
||||
pub v_roughness: Ptr<GPUFloatTexture>,
|
||||
pub u_roughness: DevicePtr<GPUFloatTexture>,
|
||||
pub v_roughness: DevicePtr<GPUFloatTexture>,
|
||||
pub remap_roughness: bool,
|
||||
pub table: BSSRDFTable,
|
||||
}
|
||||
|
|
@ -173,11 +173,11 @@ impl MaterialTrait for SubsurfaceMaterial {
|
|||
todo!()
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,26 +4,26 @@ use crate::bxdfs::{
|
|||
use crate::core::bsdf::BSDF;
|
||||
use crate::core::bssrdf::BSSRDF;
|
||||
use crate::core::bxdf::BxDF;
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::DeviceImage;
|
||||
use crate::core::material::{Material, MaterialEvalContext, MaterialTrait};
|
||||
use crate::core::scattering::TrowbridgeReitzDistribution;
|
||||
use crate::core::spectrum::{Spectrum, SpectrumTrait};
|
||||
use crate::core::texture::{GPUFloatTexture, GPUSpectrumTexture, TextureEvaluator};
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::math::clamp;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct ConductorMaterial {
|
||||
pub displacement: Ptr<GPUFloatTexture>,
|
||||
pub eta: Ptr<GPUSpectrumTexture>,
|
||||
pub k: Ptr<GPUSpectrumTexture>,
|
||||
pub reflectance: Ptr<GPUSpectrumTexture>,
|
||||
pub u_roughness: Ptr<GPUFloatTexture>,
|
||||
pub v_roughness: Ptr<GPUFloatTexture>,
|
||||
pub displacement: DevicePtr<GPUFloatTexture>,
|
||||
pub eta: DevicePtr<GPUSpectrumTexture>,
|
||||
pub k: DevicePtr<GPUSpectrumTexture>,
|
||||
pub reflectance: DevicePtr<GPUSpectrumTexture>,
|
||||
pub u_roughness: DevicePtr<GPUFloatTexture>,
|
||||
pub v_roughness: DevicePtr<GPUFloatTexture>,
|
||||
pub remap_roughness: bool,
|
||||
pub normal_map: Ptr<Image>,
|
||||
pub normal_map: DevicePtr<DeviceImage>,
|
||||
}
|
||||
|
||||
impl MaterialTrait for ConductorMaterial {
|
||||
|
|
@ -50,11 +50,11 @@ impl MaterialTrait for ConductorMaterial {
|
|||
)
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,23 +4,23 @@ use crate::bxdfs::{
|
|||
use crate::core::bsdf::BSDF;
|
||||
use crate::core::bssrdf::BSSRDF;
|
||||
use crate::core::bxdf::BxDF;
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::DeviceImage;
|
||||
use crate::core::material::{Material, MaterialEvalContext, MaterialTrait};
|
||||
use crate::core::scattering::TrowbridgeReitzDistribution;
|
||||
use crate::core::spectrum::{Spectrum, SpectrumTrait};
|
||||
use crate::core::texture::{GPUFloatTexture, GPUSpectrumTexture, TextureEvaluator};
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::math::clamp;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct DielectricMaterial {
|
||||
normal_map: Ptr<Image>,
|
||||
displacement: Ptr<GPUFloatTexture>,
|
||||
u_roughness: Ptr<GPUFloatTexture>,
|
||||
v_roughness: Ptr<GPUFloatTexture>,
|
||||
eta: Ptr<Spectrum>,
|
||||
normal_map: DevicePtr<DeviceImage>,
|
||||
displacement: DevicePtr<GPUFloatTexture>,
|
||||
u_roughness: DevicePtr<GPUFloatTexture>,
|
||||
v_roughness: DevicePtr<GPUFloatTexture>,
|
||||
eta: DevicePtr<Spectrum>,
|
||||
remap_roughness: bool,
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ impl MaterialTrait for DielectricMaterial {
|
|||
let distrib = TrowbridgeReitzDistribution::new(u_rough, v_rough);
|
||||
let bxdf = BxDF::Dielectric(DielectricBxDF::new(sampled_eta, distrib));
|
||||
|
||||
BSDF::new(ctx.ns, ctx.dpdus, Ptr::from(&bxdf))
|
||||
BSDF::new(ctx.ns, ctx.dpdus, DevicePtr::from(&bxdf))
|
||||
}
|
||||
|
||||
fn get_bssrdf<T>(
|
||||
|
|
@ -67,11 +67,11 @@ impl MaterialTrait for DielectricMaterial {
|
|||
tex_eval.can_evaluate(&[self.u_roughness, self.v_roughness], &[])
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
Some(&*self.normal_map)
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
self.displacement
|
||||
}
|
||||
|
||||
|
|
@ -83,9 +83,9 @@ impl MaterialTrait for DielectricMaterial {
|
|||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct ThinDielectricMaterial {
|
||||
pub displacement: Ptr<GPUFloatTexture>,
|
||||
pub normal_map: Ptr<Image>,
|
||||
pub eta: Ptr<Spectrum>,
|
||||
pub displacement: DevicePtr<GPUFloatTexture>,
|
||||
pub normal_map: DevicePtr<DeviceImage>,
|
||||
pub eta: DevicePtr<Spectrum>,
|
||||
}
|
||||
impl MaterialTrait for ThinDielectricMaterial {
|
||||
fn get_bsdf<T: TextureEvaluator>(
|
||||
|
|
@ -109,11 +109,11 @@ impl MaterialTrait for ThinDielectricMaterial {
|
|||
true
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
Some(&*self.normal_map)
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
self.displacement
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,21 +5,21 @@ use crate::bxdfs::{
|
|||
use crate::core::bsdf::BSDF;
|
||||
use crate::core::bssrdf::BSSRDF;
|
||||
use crate::core::bxdf::BxDF;
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::DeviceImage;
|
||||
use crate::core::material::{Material, MaterialEvalContext, MaterialTrait};
|
||||
use crate::core::scattering::TrowbridgeReitzDistribution;
|
||||
use crate::core::spectrum::{Spectrum, SpectrumTrait};
|
||||
use crate::core::texture::{GPUFloatTexture, GPUSpectrumTexture, TextureEvaluator};
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::math::clamp;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct DiffuseMaterial {
|
||||
pub normal_map: Ptr<Image>,
|
||||
pub displacement: Ptr<GPUFloatTexture>,
|
||||
pub reflectance: Ptr<GPUSpectrumTexture>,
|
||||
pub normal_map: DevicePtr<DeviceImage>,
|
||||
pub displacement: DevicePtr<GPUFloatTexture>,
|
||||
pub reflectance: DevicePtr<GPUSpectrumTexture>,
|
||||
}
|
||||
|
||||
impl MaterialTrait for DiffuseMaterial {
|
||||
|
|
@ -31,7 +31,7 @@ impl MaterialTrait for DiffuseMaterial {
|
|||
) -> BSDF {
|
||||
let r = tex_eval.evaluate_spectrum(&self.reflectance, ctx, lambda);
|
||||
let bxdf = BxDF::Diffuse(DiffuseBxDF::new(r));
|
||||
BSDF::new(ctx.ns, ctx.dpdus, Ptr::from(&bxdf))
|
||||
BSDF::new(ctx.ns, ctx.dpdus, DevicePtr::from(&bxdf))
|
||||
}
|
||||
|
||||
fn get_bssrdf<T>(
|
||||
|
|
@ -47,11 +47,11 @@ impl MaterialTrait for DiffuseMaterial {
|
|||
tex_eval.can_evaluate(&[], &[self.reflectance])
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
Some(&*self.normal_map)
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
self.displacement
|
||||
}
|
||||
|
||||
|
|
@ -63,10 +63,10 @@ impl MaterialTrait for DiffuseMaterial {
|
|||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct DiffuseTransmissionMaterial {
|
||||
pub image: Ptr<Image>,
|
||||
pub displacement: Ptr<GPUFloatTexture>,
|
||||
pub reflectance: Ptr<GPUFloatTexture>,
|
||||
pub transmittance: Ptr<GPUFloatTexture>,
|
||||
pub image: DevicePtr<DeviceImage>,
|
||||
pub displacement: DevicePtr<GPUFloatTexture>,
|
||||
pub reflectance: DevicePtr<GPUFloatTexture>,
|
||||
pub transmittance: DevicePtr<GPUFloatTexture>,
|
||||
pub scale: Float,
|
||||
}
|
||||
|
||||
|
|
@ -92,11 +92,11 @@ impl MaterialTrait for DiffuseTransmissionMaterial {
|
|||
tex_eval.can_evaluate(&[self.reflectance, self.transmittance], &[])
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
Some(&*self.image)
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
self.displacement
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::bxdfs::{
|
|||
use crate::core::bsdf::BSDF;
|
||||
use crate::core::bssrdf::BSSRDF;
|
||||
use crate::core::bxdf::BxDF;
|
||||
use crate::core::image::Image;
|
||||
use crate::core::image::DeviceImage;
|
||||
use crate::core::material::{Material, MaterialEvalContext, MaterialTrait};
|
||||
use crate::core::scattering::TrowbridgeReitzDistribution;
|
||||
use crate::core::spectrum::{Spectrum, SpectrumTrait};
|
||||
|
|
@ -12,13 +12,13 @@ use crate::core::texture::{GPUFloatTexture, GPUSpectrumTexture, TextureEvaluator
|
|||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::hash::hash_float;
|
||||
use crate::utils::math::clamp;
|
||||
use crate::utils::{ArenaPtr, Ptr};
|
||||
use crate::utils::{DevicePtr, Ptr};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct MixMaterial {
|
||||
pub amount: Ptr<GPUFloatTexture>,
|
||||
pub materials: [ArenaPtr<Material>; 2],
|
||||
pub amount: DevicePtr<GPUFloatTexture>,
|
||||
pub materials: [Ptr<Material>; 2],
|
||||
}
|
||||
|
||||
impl MixMaterial {
|
||||
|
|
@ -69,11 +69,11 @@ impl MaterialTrait for MixMaterial {
|
|||
tex_eval.can_evaluate(&[self.amount], &[])
|
||||
}
|
||||
|
||||
fn get_normal_map(&self) -> Option<&Image> {
|
||||
fn get_normal_map(&self) -> Option<&DeviceImage> {
|
||||
None
|
||||
}
|
||||
|
||||
fn get_displacement(&self) -> Ptr<GPUFloatTexture> {
|
||||
fn get_displacement(&self) -> DevicePtr<GPUFloatTexture> {
|
||||
panic!(
|
||||
"MixMaterial::get_displacement() shouldn't be called. \
|
||||
Displacement is not supported on Mix materials directly."
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@ use crate::core::geometry::Point2f;
|
|||
use crate::core::pbrt::Float;
|
||||
use crate::spectra::{DenselySampledSpectrum, SampledSpectrum};
|
||||
use crate::utils::math::SquareMatrix3f;
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
|
||||
use std::cmp::{Eq, PartialEq};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Debug, Clone)]
|
||||
pub struct StandardColorSpaces {
|
||||
pub srgb: Ptr<RGBColorSpace>,
|
||||
pub dci_p3: Ptr<RGBColorSpace>,
|
||||
pub rec2020: Ptr<RGBColorSpace>,
|
||||
pub aces2065_1: Ptr<RGBColorSpace>,
|
||||
pub srgb: DevicePtr<RGBColorSpace>,
|
||||
pub dci_p3: DevicePtr<RGBColorSpace>,
|
||||
pub rec2020: DevicePtr<RGBColorSpace>,
|
||||
pub aces2065_1: DevicePtr<RGBColorSpace>,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
|
@ -24,7 +24,7 @@ pub struct RGBColorSpace {
|
|||
pub b: Point2f,
|
||||
pub w: Point2f,
|
||||
pub illuminant: DenselySampledSpectrum,
|
||||
pub rgb_to_spectrum_table: Ptr<RGBToSpectrumTable>,
|
||||
pub rgb_to_spectrum_table: DevicePtr<RGBToSpectrumTable>,
|
||||
pub xyz_from_rgb: SquareMatrix3f,
|
||||
pub rgb_from_xyz: SquareMatrix3f,
|
||||
}
|
||||
|
|
@ -52,6 +52,14 @@ impl RGBColorSpace {
|
|||
|
||||
self.rgb_from_xyz * other.xyz_from_rgb
|
||||
}
|
||||
|
||||
pub fn luminance_vector(&self) -> RGB {
|
||||
RGB::new(
|
||||
self.xyz_from_rgb[1][0],
|
||||
self.xyz_from_rgb[1][1],
|
||||
self.xyz_from_rgb[1][2],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for RGBColorSpace {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use super::{
|
|||
};
|
||||
use crate::core::color::{RGB, RGBSigmoidPolynomial, XYZ};
|
||||
use crate::core::spectrum::SpectrumTrait;
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
|
||||
use crate::Float;
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ impl SpectrumTrait for UnboundedRGBSpectrum {
|
|||
pub struct RGBIlluminantSpectrum {
|
||||
pub scale: Float,
|
||||
pub rsp: RGBSigmoidPolynomial,
|
||||
pub illuminant: Ptr<DenselySampledSpectrum>,
|
||||
pub illuminant: DevicePtr<DenselySampledSpectrum>,
|
||||
}
|
||||
|
||||
impl RGBIlluminantSpectrum {
|
||||
|
|
@ -85,7 +85,7 @@ impl RGBIlluminantSpectrum {
|
|||
Self {
|
||||
scale,
|
||||
rsp,
|
||||
illuminant: Ptr::from(&illuminant),
|
||||
illuminant: DevicePtr::from(&illuminant),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use super::cie::*;
|
|||
use super::sampled::{LAMBDA_MAX, LAMBDA_MIN};
|
||||
use crate::core::spectrum::{Spectrum, SpectrumTrait};
|
||||
use crate::spectra::{N_SPECTRUM_SAMPLES, SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
use crate::{Float, find_interval};
|
||||
use core::slice;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
|
@ -35,7 +35,7 @@ impl SpectrumTrait for ConstantSpectrum {
|
|||
pub struct DenselySampledSpectrum {
|
||||
pub lambda_min: i32,
|
||||
pub lambda_max: i32,
|
||||
pub values: Ptr<Float>,
|
||||
pub values: DevicePtr<Float>,
|
||||
}
|
||||
|
||||
unsafe impl Send for DenselySampledSpectrum {}
|
||||
|
|
@ -130,8 +130,8 @@ impl SpectrumTrait for DenselySampledSpectrum {
|
|||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct PiecewiseLinearSpectrum {
|
||||
pub lambdas: Ptr<Float>,
|
||||
pub values: Ptr<Float>,
|
||||
pub lambdas: DevicePtr<Float>,
|
||||
pub values: DevicePtr<Float>,
|
||||
pub count: u32,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::core::spectrum::Spectrum;
|
|||
use crate::core::spectrum::SpectrumTrait;
|
||||
use crate::core::texture::{TextureEvalContext, TextureMapping2D};
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::{Ptr, Transform};
|
||||
use crate::utils::{DevicePtr, Transform};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
|
@ -48,19 +48,19 @@ impl FloatBilerpTexture {
|
|||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct SpectrumBilerpTexture {
|
||||
pub mapping: TextureMapping2D,
|
||||
pub v00: Ptr<Spectrum>,
|
||||
pub v01: Ptr<Spectrum>,
|
||||
pub v10: Ptr<Spectrum>,
|
||||
pub v11: Ptr<Spectrum>,
|
||||
pub v00: DevicePtr<Spectrum>,
|
||||
pub v01: DevicePtr<Spectrum>,
|
||||
pub v10: DevicePtr<Spectrum>,
|
||||
pub v11: DevicePtr<Spectrum>,
|
||||
}
|
||||
|
||||
impl SpectrumBilerpTexture {
|
||||
pub fn new(
|
||||
mapping: TextureMapping2D,
|
||||
v00: Ptr<Spectrum>,
|
||||
v01: Ptr<Spectrum>,
|
||||
v10: Ptr<Spectrum>,
|
||||
v11: Ptr<Spectrum>,
|
||||
v00: DevicePtr<Spectrum>,
|
||||
v01: DevicePtr<Spectrum>,
|
||||
v10: DevicePtr<Spectrum>,
|
||||
v11: DevicePtr<Spectrum>,
|
||||
) -> Self {
|
||||
Self {
|
||||
mapping,
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ use crate::core::texture::{
|
|||
TextureMapping3DTrait,
|
||||
};
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::{ArenaPtr, Ptr, math::square};
|
||||
use crate::utils::{DevicePtr, Ptr, math::square};
|
||||
|
||||
fn checkerboard(
|
||||
ctx: &TextureEvalContext,
|
||||
map2d: Ptr<TextureMapping2D>,
|
||||
map3d: Ptr<TextureMapping3D>,
|
||||
map2d: DevicePtr<TextureMapping2D>,
|
||||
map3d: DevicePtr<TextureMapping3D>,
|
||||
) -> Float {
|
||||
let d = |x: Float| -> Float {
|
||||
let y = x / 2. - (x / 2.).floor() - 0.5;
|
||||
|
|
@ -43,9 +43,9 @@ fn checkerboard(
|
|||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct FloatCheckerboardTexture {
|
||||
pub map2d: Ptr<TextureMapping2D>,
|
||||
pub map3d: Ptr<TextureMapping3D>,
|
||||
pub tex: [ArenaPtr<GPUFloatTexture>; 2],
|
||||
pub map2d: DevicePtr<TextureMapping2D>,
|
||||
pub map3d: DevicePtr<TextureMapping3D>,
|
||||
pub tex: [Ptr<GPUFloatTexture>; 2],
|
||||
}
|
||||
|
||||
impl FloatCheckerboardTexture {
|
||||
|
|
@ -74,9 +74,9 @@ impl FloatCheckerboardTexture {
|
|||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct SpectrumCheckerboardTexture {
|
||||
pub map2d: Ptr<TextureMapping2D>,
|
||||
pub map3d: Ptr<TextureMapping3D>,
|
||||
pub tex: [ArenaPtr<GPUSpectrumTexture>; 2],
|
||||
pub map2d: DevicePtr<TextureMapping2D>,
|
||||
pub map3d: DevicePtr<TextureMapping3D>,
|
||||
pub tex: [Ptr<GPUSpectrumTexture>; 2],
|
||||
}
|
||||
|
||||
impl SpectrumCheckerboardTexture {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::core::texture::{
|
|||
GPUFloatTexture, GPUSpectrumTexture, TextureEvalContext, TextureMapping2D,
|
||||
};
|
||||
use crate::spectra::sampled::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use crate::utils::math::square;
|
||||
use crate::utils::noise::noise_2d;
|
||||
|
||||
|
|
@ -28,8 +28,8 @@ fn inside_polka_dot(st: Point2f) -> bool {
|
|||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct FloatDotsTexture {
|
||||
pub mapping: TextureMapping2D,
|
||||
pub outside_dot: Ptr<GPUFloatTexture>,
|
||||
pub inside_dot: Ptr<GPUFloatTexture>,
|
||||
pub outside_dot: DevicePtr<GPUFloatTexture>,
|
||||
pub inside_dot: DevicePtr<GPUFloatTexture>,
|
||||
}
|
||||
|
||||
impl FloatDotsTexture {
|
||||
|
|
@ -53,8 +53,8 @@ impl FloatDotsTexture {
|
|||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct SpectrumDotsTexture {
|
||||
pub mapping: TextureMapping2D,
|
||||
pub outside_dot: Ptr<GPUSpectrumTexture>,
|
||||
pub inside_dot: Ptr<GPUSpectrumTexture>,
|
||||
pub outside_dot: DevicePtr<GPUSpectrumTexture>,
|
||||
pub inside_dot: DevicePtr<GPUSpectrumTexture>,
|
||||
}
|
||||
|
||||
impl SpectrumDotsTexture {
|
||||
|
|
|
|||
|
|
@ -95,11 +95,13 @@ impl GPUFloatImageTexture {
|
|||
let d_p_dy = [c.dsdy, c.dtdy];
|
||||
let val: Float = unsafe { intrinsics::tex2d_grad(self.tex_obj, u, v, d_p_dx, d_p_dy) };
|
||||
|
||||
if self.invert {
|
||||
return (1. - v).max(0.);
|
||||
let result = if self.invert {
|
||||
(1.0 - val).max(0.0) // Invert the pixel intensity
|
||||
} else {
|
||||
return v;
|
||||
}
|
||||
val
|
||||
};
|
||||
|
||||
return result * self.scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::core::texture::{TextureEvalContext, TextureMapping3D};
|
|||
use crate::spectra::{RGBAlbedoSpectrum, RGBColorSpace, SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::math::clamp;
|
||||
use crate::utils::noise::fbm;
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
use crate::utils::splines::evaluate_cubic_bezier;
|
||||
|
||||
#[repr(C)]
|
||||
|
|
@ -18,7 +18,7 @@ pub struct MarbleTexture {
|
|||
pub scale: Float,
|
||||
pub variation: Float,
|
||||
// TODO: DO not forget to pass StandardColorSpace here!!
|
||||
pub colorspace: Ptr<RGBColorSpace>,
|
||||
pub colorspace: DevicePtr<RGBColorSpace>,
|
||||
}
|
||||
|
||||
unsafe impl Send for MarbleTexture {}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ use crate::Float;
|
|||
use crate::core::geometry::{Vector3f, VectorLike};
|
||||
use crate::core::texture::{GPUFloatTexture, GPUSpectrumTexture, TextureEvalContext};
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::ArenaPtr;
|
||||
use crate::utils::Ptr;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct GPUFloatMixTexture {
|
||||
pub tex1: ArenaPtr<GPUFloatTexture>,
|
||||
pub tex2: ArenaPtr<GPUFloatTexture>,
|
||||
pub amount: ArenaPtr<GPUFloatTexture>,
|
||||
pub tex1: Ptr<GPUFloatTexture>,
|
||||
pub tex2: Ptr<GPUFloatTexture>,
|
||||
pub amount: Ptr<GPUFloatTexture>,
|
||||
}
|
||||
|
||||
impl GPUFloatMixTexture {
|
||||
|
|
@ -34,8 +34,8 @@ impl GPUFloatMixTexture {
|
|||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct GPUFloatDirectionMixTexture {
|
||||
pub tex1: ArenaPtr<GPUFloatTexture>,
|
||||
pub tex2: ArenaPtr<GPUFloatTexture>,
|
||||
pub tex1: Ptr<GPUFloatTexture>,
|
||||
pub tex2: Ptr<GPUFloatTexture>,
|
||||
pub dir: Vector3f,
|
||||
}
|
||||
|
||||
|
|
@ -61,9 +61,9 @@ impl GPUFloatDirectionMixTexture {
|
|||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct GPUSpectrumMixTexture {
|
||||
pub tex1: ArenaPtr<GPUSpectrumTexture>,
|
||||
pub tex2: ArenaPtr<GPUSpectrumTexture>,
|
||||
pub amount: ArenaPtr<GPUFloatTexture>,
|
||||
pub tex1: Ptr<GPUSpectrumTexture>,
|
||||
pub tex2: Ptr<GPUSpectrumTexture>,
|
||||
pub amount: Ptr<GPUFloatTexture>,
|
||||
}
|
||||
|
||||
impl GPUSpectrumMixTexture {
|
||||
|
|
@ -98,8 +98,8 @@ impl GPUSpectrumMixTexture {
|
|||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct GPUSpectrumDirectionMixTexture {
|
||||
pub tex1: ArenaPtr<GPUSpectrumTexture>,
|
||||
pub tex2: ArenaPtr<GPUSpectrumTexture>,
|
||||
pub tex1: Ptr<GPUSpectrumTexture>,
|
||||
pub tex2: Ptr<GPUSpectrumTexture>,
|
||||
pub dir: Vector3f,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::spectra::{
|
|||
RGBAlbedoSpectrum, RGBColorSpace, RGBIlluminantSpectrum, RGBUnboundedSpectrum, SampledSpectrum,
|
||||
SampledWavelengths, StandardColorSpaces,
|
||||
};
|
||||
use crate::utils::ptr::{Ptr, Slice};
|
||||
use crate::utils::ptr::{DevicePtr, Slice};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use crate::Float;
|
||||
use crate::core::texture::{GPUFloatTexture, GPUSpectrumTexture, TextureEvalContext};
|
||||
use crate::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use crate::utils::ArenaPtr;
|
||||
use crate::utils::Ptr;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct GPUFloatScaledTexture {
|
||||
pub tex: ArenaPtr<GPUFloatTexture>,
|
||||
pub scale: ArenaPtr<GPUFloatTexture>,
|
||||
pub tex: Ptr<GPUFloatTexture>,
|
||||
pub scale: Ptr<GPUFloatTexture>,
|
||||
}
|
||||
|
||||
impl GPUFloatScaledTexture {
|
||||
|
|
@ -23,8 +23,8 @@ impl GPUFloatScaledTexture {
|
|||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct GPUSpectrumScaledTexture {
|
||||
pub tex: ArenaPtr<GPUSpectrumTexture>,
|
||||
pub scale: ArenaPtr<GPUFloatTexture>,
|
||||
pub tex: Ptr<GPUSpectrumTexture>,
|
||||
pub scale: Ptr<GPUFloatTexture>,
|
||||
}
|
||||
|
||||
impl GPUSpectrumScaledTexture {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::core::pbrt::{Float, FloatBitOps, FloatBits, ONE_MINUS_EPSILON, PI, PI
|
|||
use crate::utils::hash::{hash_buffer, mix_bits};
|
||||
use crate::utils::sobol::{SOBOL_MATRICES_32, VDC_SOBOL_MATRICES, VDC_SOBOL_MATRICES_INV};
|
||||
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::DevicePtr;
|
||||
use half::f16;
|
||||
use num_traits::{Float as NumFloat, Num, One, Signed, Zero};
|
||||
use std::error::Error;
|
||||
|
|
@ -753,7 +753,7 @@ pub fn inverse_radical_inverse(mut inverse: u64, base: u64, n_digits: u64) -> u6
|
|||
pub struct DigitPermutation {
|
||||
pub base: u32,
|
||||
pub n_digits: u32,
|
||||
pub permutations: Ptr<u16>,
|
||||
pub permutations: DevicePtr<u16>,
|
||||
}
|
||||
|
||||
impl DigitPermutation {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::Float;
|
||||
use crate::core::geometry::{Normal3f, Point2f, Point3f, Vector3f};
|
||||
use crate::utils::Ptr;
|
||||
use crate::utils::Transform;
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::sampling::PiecewiseConstant2D;
|
||||
use crate::utils::sampling::DevicePiecewiseConstant2D;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
|
@ -30,5 +30,5 @@ pub struct BilinearPatchMesh {
|
|||
pub p: Ptr<Point3f>,
|
||||
pub n: Ptr<Normal3f>,
|
||||
pub uv: Ptr<Point2f>,
|
||||
pub image_distribution: Ptr<PiecewiseConstant2D>,
|
||||
pub image_distribution: Ptr<DevicePiecewiseConstant2D>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pub mod sobol;
|
|||
pub mod splines;
|
||||
pub mod transform;
|
||||
|
||||
pub use ptr::{ArenaPtr, Ptr};
|
||||
pub use ptr::{DevicePtr, Ptr};
|
||||
pub use transform::{AnimatedTransform, Transform, TransformGeneric};
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -3,84 +3,63 @@ use core::ops::Index;
|
|||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct ArenaPtr<T: ?Sized> {
|
||||
offset: i32,
|
||||
_marker: PhantomData<T>,
|
||||
pub struct Ptr<T: ?Sized> {
|
||||
pub offset: u32,
|
||||
pub _marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T: ?Sized> Clone for ArenaPtr<T> {
|
||||
impl<T: ?Sized> Clone for Ptr<T> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
impl<T: ?Sized> Copy for Ptr<T> {}
|
||||
|
||||
impl<T: ?Sized> Copy for ArenaPtr<T> {}
|
||||
|
||||
impl<T> ArenaPtr<T> {
|
||||
impl<T> Ptr<T> {
|
||||
pub const NULL_OFFSET: u32 = 0xFFFFFFFF;
|
||||
pub fn null() -> Self {
|
||||
Self {
|
||||
offset: 0xFFFFFFFF,
|
||||
offset: Self::NULL_OFFSET,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_null(&self) -> bool {
|
||||
self.offset == 0xFFFFFFFF
|
||||
self.offset == Self::NULL_OFFSET
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_ptr(&self, base: *const u8) -> *const T {
|
||||
pub unsafe fn deref<'a>(&self, base: *const u8) -> &'a T {
|
||||
if self.is_null() {
|
||||
core::ptr::null()
|
||||
} else {
|
||||
unsafe { base.add(self.offset as usize) as *const T }
|
||||
panic!("Null pointer dereference");
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_ref<'a>(&self, base: *const u8) -> &'a T {
|
||||
unsafe { &*self.as_ptr(base) }
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "cuda"))]
|
||||
pub fn new(me: *const Self, target: *const T) -> Self {
|
||||
if target.is_null() {
|
||||
return Self::null();
|
||||
}
|
||||
|
||||
let diff = unsafe { (target as *const u8).offset_from(me as *const u8) };
|
||||
|
||||
if diff > i32::MAX as isize || diff < i32::MIN as isize {
|
||||
panic!("RelPtr offset out of i32 range! Are objects too far apart?");
|
||||
}
|
||||
|
||||
Self {
|
||||
offset: diff as i32,
|
||||
_marker: PhantomData,
|
||||
unsafe {
|
||||
let ptr = base.add(self.offset as usize);
|
||||
&*(ptr as *const T)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Ptr<T>(pub *const T);
|
||||
pub struct DevicePtr<T>(pub *const T);
|
||||
|
||||
impl<T> Default for Ptr<T> {
|
||||
impl<T> Default for DevicePtr<T> {
|
||||
fn default() -> Self {
|
||||
Self(core::ptr::null())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq for Ptr<T> {
|
||||
impl<T> PartialEq for DevicePtr<T> {
|
||||
#[inline(always)]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for Ptr<T> {}
|
||||
impl<T> Eq for DevicePtr<T> {}
|
||||
|
||||
impl<T> Ptr<T> {
|
||||
impl<T> DevicePtr<T> {
|
||||
pub fn null() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
|
@ -107,10 +86,10 @@ impl<T> Ptr<T> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: Sync> Send for Ptr<T> {}
|
||||
unsafe impl<T: Sync> Sync for Ptr<T> {}
|
||||
unsafe impl<T: Sync> Send for DevicePtr<T> {}
|
||||
unsafe impl<T: Sync> Sync for DevicePtr<T> {}
|
||||
|
||||
impl<T> std::ops::Deref for Ptr<T> {
|
||||
impl<T> std::ops::Deref for DevicePtr<T> {
|
||||
type Target = T;
|
||||
|
||||
#[inline(always)]
|
||||
|
|
@ -119,19 +98,19 @@ impl<T> std::ops::Deref for Ptr<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> From<&T> for Ptr<T> {
|
||||
impl<T> From<&T> for DevicePtr<T> {
|
||||
fn from(r: &T) -> Self {
|
||||
Self(r as *const T)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<&mut T> for Ptr<T> {
|
||||
impl<T> From<&mut T> for DevicePtr<T> {
|
||||
fn from(r: &mut T) -> Self {
|
||||
Self(r as *const T)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Index<usize> for Ptr<T> {
|
||||
impl<T> Index<usize> for DevicePtr<T> {
|
||||
type Output = T;
|
||||
|
||||
#[inline(always)]
|
||||
|
|
@ -142,7 +121,7 @@ impl<T> Index<usize> for Ptr<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Index<u32> for Ptr<T> {
|
||||
impl<T> Index<u32> for DevicePtr<T> {
|
||||
type Output = T;
|
||||
|
||||
#[inline(always)]
|
||||
|
|
@ -154,7 +133,7 @@ impl<T> Index<u32> for Ptr<T> {
|
|||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Slice<T> {
|
||||
pub ptr: Ptr<T>,
|
||||
pub ptr: DevicePtr<T>,
|
||||
pub len: u32,
|
||||
pub _marker: PhantomData<T>,
|
||||
}
|
||||
|
|
@ -163,7 +142,7 @@ unsafe impl<T: Sync> Send for Slice<T> {}
|
|||
unsafe impl<T: Sync> Sync for Slice<T> {}
|
||||
|
||||
impl<T> Slice<T> {
|
||||
pub fn new(ptr: Ptr<T>, len: u32) -> Self {
|
||||
pub fn new(ptr: DevicePtr<T>, len: u32) -> Self {
|
||||
Self {
|
||||
ptr,
|
||||
len,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crate::utils::math::{
|
|||
catmull_rom_weights, clamp, difference_of_products, evaluate_polynomial, lerp, logistic,
|
||||
newton_bisection, safe_sqrt, square, sum_of_products,
|
||||
};
|
||||
use crate::utils::ptr::Ptr;
|
||||
use crate::utils::ptr::DevicePtr;
|
||||
use crate::utils::rng::Rng;
|
||||
use crate::{
|
||||
Float, INV_2_PI, INV_4_PI, INV_PI, ONE_MINUS_EPSILON, PI, PI_OVER_2, PI_OVER_4, find_interval,
|
||||
|
|
@ -702,19 +702,19 @@ pub struct PLSample {
|
|||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct PiecewiseConstant1D {
|
||||
pub func: Ptr<Float>,
|
||||
pub cdf: Ptr<Float>,
|
||||
pub struct DevicePiecewiseConstant1D {
|
||||
pub func: DevicePtr<Float>,
|
||||
pub cdf: DevicePtr<Float>,
|
||||
pub min: Float,
|
||||
pub max: Float,
|
||||
pub n: u32,
|
||||
pub func_integral: Float,
|
||||
}
|
||||
|
||||
unsafe impl Send for PiecewiseConstant1D {}
|
||||
unsafe impl Sync for PiecewiseConstant1D {}
|
||||
unsafe impl Send for DevicePiecewiseConstant1D {}
|
||||
unsafe impl Sync for DevicePiecewiseConstant1D {}
|
||||
|
||||
impl PiecewiseConstant1D {
|
||||
impl DevicePiecewiseConstant1D {
|
||||
pub fn integral(&self) -> Float {
|
||||
self.func_integral
|
||||
}
|
||||
|
|
@ -742,14 +742,14 @@ impl PiecewiseConstant1D {
|
|||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct PiecewiseConstant2D {
|
||||
pub struct DevicePiecewiseConstant2D {
|
||||
pub domain: Bounds2f,
|
||||
pub p_marginal: PiecewiseConstant1D,
|
||||
pub p_marginal: DevicePiecewiseConstant1D,
|
||||
pub n_conditionals: usize,
|
||||
pub p_conditional_v: Ptr<PiecewiseConstant1D>,
|
||||
pub p_conditional_v: DevicePtr<DevicePiecewiseConstant1D>,
|
||||
}
|
||||
|
||||
impl PiecewiseConstant2D {
|
||||
impl DevicePiecewiseConstant2D {
|
||||
pub fn resolution(&self) -> Point2i {
|
||||
Point2i::new(
|
||||
self.p_conditional_v[0u32].size() as i32,
|
||||
|
|
@ -1056,10 +1056,10 @@ pub struct PiecewiseLinear2D<const N: usize> {
|
|||
pub inv_patch_size: Vector2f,
|
||||
pub param_size: [u32; N],
|
||||
pub param_strides: [u32; N],
|
||||
pub param_values: [Ptr<Float>; N],
|
||||
pub data: Ptr<Float>,
|
||||
pub marginal_cdf: Ptr<Float>,
|
||||
pub conditional_cdf: Ptr<Float>,
|
||||
pub param_values: [DevicePtr<Float>; N],
|
||||
pub data: DevicePtr<Float>,
|
||||
pub marginal_cdf: DevicePtr<Float>,
|
||||
pub conditional_cdf: DevicePtr<Float>,
|
||||
}
|
||||
|
||||
impl<const N: usize> PiecewiseLinear2D<N> {
|
||||
|
|
@ -1311,7 +1311,7 @@ impl<const N: usize> PiecewiseLinear2D<N> {
|
|||
|
||||
fn lookup(
|
||||
&self,
|
||||
data: Ptr<Float>,
|
||||
data: DevicePtr<Float>,
|
||||
i0: u32,
|
||||
size: u32,
|
||||
param_weight: &[(Float, Float); N],
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use super::math::{SquareMatrix, radians, safe_acos};
|
|||
use super::quaternion::Quaternion;
|
||||
use crate::core::color::{RGB, XYZ};
|
||||
use crate::core::geometry::{
|
||||
Bounds3f, Normal, Normal3f, Point, Point3f, Point3fi, Ray, Vector, Vector3f, Vector3fi,
|
||||
Bounds3f, Frame, Normal, Normal3f, Point, Point3f, Point3fi, Ray, Vector, Vector3f, Vector3fi,
|
||||
VectorLike,
|
||||
};
|
||||
use crate::core::interaction::{
|
||||
|
|
@ -714,6 +714,30 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Frame> for TransformGeneric<Float> {
|
||||
fn from(frame: Frame) -> Self {
|
||||
let values: &[Float; 16] = &[
|
||||
frame.x.x(),
|
||||
frame.x.y(),
|
||||
frame.x.z(),
|
||||
0.,
|
||||
frame.y.x(),
|
||||
frame.y.y(),
|
||||
frame.y.z(),
|
||||
0.,
|
||||
frame.z.x(),
|
||||
frame.z.y(),
|
||||
frame.z.z(),
|
||||
0.,
|
||||
0.,
|
||||
0.,
|
||||
0.,
|
||||
1.,
|
||||
];
|
||||
Self::from_flat(values).expect("Transform must be inversible")
|
||||
}
|
||||
}
|
||||
impl From<Quaternion> for TransformGeneric<Float> {
|
||||
fn from(q: Quaternion) -> Self {
|
||||
let xx = q.v.x() * q.v.x();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use super::ImageBuffer;
|
||||
use super::{Image, ImageAndMetadata};
|
||||
use crate::utils::error::ImageError;
|
||||
use anyhow::{Context, Result, bail};
|
||||
use exr::prelude::{read_first_rgba_layer_from_file, write_rgba_file};
|
||||
|
|
@ -6,7 +6,7 @@ use image_rs::ImageReader;
|
|||
use image_rs::{DynamicImage, ImageBuffer, Rgb, Rgba};
|
||||
use shared::Float;
|
||||
use shared::core::color::{ColorEncoding, LINEAR, SRGB};
|
||||
use shared::core::image::Image;
|
||||
use shared::core::image::DeviceImage;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, BufWriter, Read, Write};
|
||||
use std::path::Path;
|
||||
|
|
@ -21,7 +21,7 @@ pub trait ImageIO {
|
|||
fn to_u8_buffer(&self) -> Vec<u8>;
|
||||
}
|
||||
|
||||
impl ImageIO for ImageBuffer {
|
||||
impl ImageIO for Image {
|
||||
fn read(path: &Path, encoding: Option<ColorEncoding>) -> Result<ImageAndMetadata> {
|
||||
let ext = path
|
||||
.extension()
|
||||
|
|
@ -206,14 +206,14 @@ fn read_generic(path: &Path, encoding: Option<ColorEncoding>) -> Result<ImageAnd
|
|||
|
||||
// Check if it was loaded as high precision or standard
|
||||
let image = match dyn_img {
|
||||
DynamicImage::ImageRgb32F(buf) => Image {
|
||||
DynamicImage::ImageRgb32F(buf) => DeviceImage {
|
||||
format: PixelFormat::F32,
|
||||
resolution: res,
|
||||
channel_names: vec!["R".into(), "G".into(), "B".into()],
|
||||
encoding: LINEAR,
|
||||
pixels: PixelData::F32(buf.into_raw()),
|
||||
},
|
||||
DynamicImage::ImageRgba32F(buf) => Image {
|
||||
DynamicImage::ImageRgba32F(buf) => DeviceImage {
|
||||
format: PixelFormat::F32,
|
||||
resolution: res,
|
||||
channel_names: vec!["R".into(), "G".into(), "B".into(), "A".into()],
|
||||
|
|
@ -224,7 +224,7 @@ fn read_generic(path: &Path, encoding: Option<ColorEncoding>) -> Result<ImageAnd
|
|||
// Default to RGB8 for everything else
|
||||
if dyn_img.color().has_alpha() {
|
||||
let buf = dyn_img.to_rgba8();
|
||||
Image {
|
||||
DeviceImage {
|
||||
format: PixelFormat::U8,
|
||||
resolution: res,
|
||||
channel_names: vec!["R".into(), "G".into(), "B".into(), "A".into()],
|
||||
|
|
@ -233,7 +233,7 @@ fn read_generic(path: &Path, encoding: Option<ColorEncoding>) -> Result<ImageAnd
|
|||
}
|
||||
} else {
|
||||
let buf = dyn_img.to_rgb8();
|
||||
Image {
|
||||
DeviceImage {
|
||||
format: PixelFormat::U8,
|
||||
resolution: res,
|
||||
channel_names: vec!["R".into(), "G".into(), "B".into()],
|
||||
|
|
@ -270,7 +270,7 @@ fn read_exr(path: &Path) -> Result<ImageAndMetadata> {
|
|||
let w = image.layer_data.size.width() as i32;
|
||||
let h = image.layer_data.size.height() as i32;
|
||||
|
||||
let image = Image {
|
||||
let image = DeviceImage {
|
||||
format: PixelFormat::F32,
|
||||
resolution: Point2i::new(w, h),
|
||||
channel_names: vec!["R".into(), "G".into(), "B".into(), "A".into()],
|
||||
|
|
@ -355,7 +355,7 @@ fn read_pfm(path: &Path) -> Result<ImageAndMetadata> {
|
|||
vec!["R".into(), "G".into(), "B".into()]
|
||||
};
|
||||
|
||||
let image = Image {
|
||||
let image = DeviceImage {
|
||||
format: PixelFormat::F32,
|
||||
resolution: Point2i::new(w, h),
|
||||
channel_names: names,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use shared::core::geometry::Point2i;
|
||||
use shared::core::image::{Image, PixelFormat};
|
||||
use shared::core::image::{DeviceImage, ImageAccess, ImageBase, PixelFormat, WrapMode};
|
||||
use shared::utils::math::f16_to_f32;
|
||||
use std::ops::Deref;
|
||||
|
||||
|
|
@ -8,6 +8,7 @@ pub mod metadata;
|
|||
pub mod ops;
|
||||
pub mod pixel;
|
||||
|
||||
pub use io::ImageIO;
|
||||
pub use metadata::*;
|
||||
|
||||
impl std::fmt::Display for PixelFormat {
|
||||
|
|
@ -75,39 +76,50 @@ pub enum PixelStorage {
|
|||
F32(Vec<f32>),
|
||||
}
|
||||
|
||||
pub struct ImageBuffer {
|
||||
pub view: Image,
|
||||
pub struct Image {
|
||||
pub base: ImageBase,
|
||||
pub pixels: PixelStorage,
|
||||
pub channel_names: Vec<String>,
|
||||
_storage: PixelStorage,
|
||||
}
|
||||
|
||||
impl Deref for ImageBuffer {
|
||||
type Target = Image;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.view
|
||||
impl ImageAccess for Image {
|
||||
fn get_channel_with_wrap(&self, p: Point2i, c: i32, wrap_mode: WrapMode2D) -> Float {
|
||||
todo!()
|
||||
}
|
||||
fn get_channel(&self, p: Point2i, c: i32) -> Float {
|
||||
todo!()
|
||||
}
|
||||
fn lookup_nearest_channel_with_wrap(&self, p: Point2f, c: i32, wrap_mode: WrapMode2D) -> Float {
|
||||
todo!()
|
||||
}
|
||||
fn lookup_nearest_channel(&self, p: Point2f, c: i32) -> Float {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ImageAndMetadata {
|
||||
pub image: ImageBuffer,
|
||||
pub image: Image,
|
||||
pub metadata: ImageMetadata,
|
||||
}
|
||||
|
||||
impl ImageBuffer {
|
||||
fn resolution(&self) {
|
||||
self.view.resolution()
|
||||
impl Image {
|
||||
pub fn resolution(&self) -> Point2i {
|
||||
self.base.resolution
|
||||
}
|
||||
|
||||
fn n_channels(&self) -> i32 {
|
||||
self.base.n_channels
|
||||
}
|
||||
|
||||
pub fn new_empty() -> Self {
|
||||
Self {
|
||||
channel_names: Vec::new(),
|
||||
_storage: PixelStorage::U8(Vec::new()),
|
||||
view: Image {
|
||||
pixels: PixelStorage::U8(Vec::new()),
|
||||
base: ImageBase {
|
||||
format: PixelFormat::U256,
|
||||
resolution: Point2i::new(0, 0),
|
||||
n_channels: 0,
|
||||
pixels: Pixels::U8(std::ptr::null()),
|
||||
encoding: ColorEncoding::default(),
|
||||
},
|
||||
}
|
||||
|
|
@ -120,23 +132,22 @@ impl ImageBuffer {
|
|||
encoding: ColorEncoding,
|
||||
) -> Self {
|
||||
let n_channels = channel_names.len() as i32;
|
||||
let (format, pixels_view) = match &storage {
|
||||
let (format, pixels) = match &storage {
|
||||
PixelStorage::U8(vec) => (PixelFormat::U8, ImagePixels::U8(vec.as_ptr())),
|
||||
PixelStorage::F16(vec) => (PixelFormat::F16, ImagePixels::F16(vec.as_ptr())),
|
||||
PixelStorage::F32(vec) => (PixelFormat::F32, ImagePixels::F32(vec.as_ptr())),
|
||||
};
|
||||
|
||||
let view = Image {
|
||||
let base = ImageBase {
|
||||
format,
|
||||
resolution,
|
||||
n_channels,
|
||||
encoding,
|
||||
pixels: pixels_view,
|
||||
};
|
||||
|
||||
Self {
|
||||
view,
|
||||
_storage: storage,
|
||||
base,
|
||||
pixels,
|
||||
channel_names,
|
||||
}
|
||||
}
|
||||
|
|
@ -165,18 +176,17 @@ impl ImageBuffer {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let view = Image {
|
||||
let base = ImageBase {
|
||||
format: PixelFormat::U256,
|
||||
resolution,
|
||||
n_channels,
|
||||
pixels: Pixels::U8(ptr),
|
||||
encoding: encoding.clone(),
|
||||
};
|
||||
|
||||
Self {
|
||||
view,
|
||||
base,
|
||||
channel_names,
|
||||
_storage: storage,
|
||||
pixels: ptr,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -205,18 +215,17 @@ impl ImageBuffer {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let view = Image {
|
||||
let base = ImageBase {
|
||||
format: PixelFormat::U256,
|
||||
resolution,
|
||||
n_channels,
|
||||
pixels: Pixels::U8(ptr),
|
||||
encoding: encoding.clone(),
|
||||
};
|
||||
|
||||
Self {
|
||||
view,
|
||||
base,
|
||||
channel_names,
|
||||
_storage: storage,
|
||||
pixels: ptr,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -235,18 +244,17 @@ impl ImageBuffer {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let view = Image {
|
||||
let base = ImageBase {
|
||||
format: PixelFormat::Half,
|
||||
resolution,
|
||||
n_channels,
|
||||
pixels: Pixels::F16(ptr),
|
||||
encoding: ColorEncoding::default(),
|
||||
};
|
||||
|
||||
Self {
|
||||
view,
|
||||
base,
|
||||
channel_names,
|
||||
_storage: storage,
|
||||
pixels: ptr,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -265,18 +273,17 @@ impl ImageBuffer {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let view = Image {
|
||||
let base = ImageBase {
|
||||
format: PixelFormat::Float,
|
||||
resolution,
|
||||
n_channels,
|
||||
pixels: Pixels::F32(ptr),
|
||||
encoding: ColorEncoding::default(),
|
||||
};
|
||||
|
||||
Self {
|
||||
view,
|
||||
base,
|
||||
channel_names,
|
||||
_storage: storage,
|
||||
pixels: ptr,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -412,6 +419,16 @@ impl ImageBuffer {
|
|||
ImageChannelValues(values)
|
||||
}
|
||||
|
||||
pub fn get_channel_with_wrap(
|
||||
&self,
|
||||
p: Point2i,
|
||||
c: i32,
|
||||
wrap_mode: Option<WrapMode2D>,
|
||||
) -> Float {
|
||||
// if !self.remap_pixel_coords
|
||||
0.
|
||||
}
|
||||
|
||||
pub fn channel_names_from_desc(&self, desc: &ImageChannelDesc) -> Vec<&str> {
|
||||
desc.offset
|
||||
.iter()
|
||||
|
|
@ -566,9 +583,9 @@ impl ImageBuffer {
|
|||
pub fn mse(
|
||||
&self,
|
||||
desc: ImageChannelDesc,
|
||||
ref_img: &Image,
|
||||
ref_img: &DeviceImage,
|
||||
generate_mse_image: bool,
|
||||
) -> (ImageChannelValues, Option<Image>) {
|
||||
) -> (ImageChannelValues, Option<DeviceImage>) {
|
||||
let mut sum_se: Vec<f64> = vec![0.; desc.size()];
|
||||
let names_ref = self.channel_names_from_desc(&desc);
|
||||
let ref_desc = ref_img
|
||||
|
|
@ -613,7 +630,7 @@ impl ImageBuffer {
|
|||
sum_se.iter().map(|&s| (s / pixel_count) as Float).collect();
|
||||
|
||||
let mse_image = if generate_mse_image {
|
||||
Some(Image::new(
|
||||
Some(DeviceImage::new(
|
||||
PixelFormat::F32,
|
||||
self.resolution,
|
||||
&names_ref,
|
||||
|
|
@ -633,4 +650,21 @@ impl ImageBuffer {
|
|||
PixelStorage::F32(vec) => Pixels::F32(vec.as_ptr()),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn has_any_infinite_pixels(&self) -> bool {
|
||||
if format == PixelFormat::Float {
|
||||
return false;
|
||||
}
|
||||
|
||||
for y in 0..self.resolution().y() {
|
||||
for x in 0..self.resolution().x() {
|
||||
for c in 0..self.n_channels() {
|
||||
if self.get_channel(Point2i::new(x, y), c).is_infinite() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// use rayon::prelude::*;
|
||||
use super::ImageBuffer;
|
||||
use super::Image;
|
||||
use rayon::prelude::*;
|
||||
use shared::Float;
|
||||
use shared::core::geometry::{Bounds2i, Point2i};
|
||||
|
|
@ -13,7 +13,7 @@ pub struct ResampleWeight {
|
|||
pub weight: [Float; 4],
|
||||
}
|
||||
|
||||
impl ImageBuffer {
|
||||
impl Image {
|
||||
pub fn flip_y(&mut self) {
|
||||
let res = self.resolution;
|
||||
let nc = self.n_channels();
|
||||
|
|
|
|||
|
|
@ -1,31 +1,191 @@
|
|||
use shared::core::geometry::{Bounds3f, Point2i};
|
||||
use shared::core::image::Image;
|
||||
use shared::core::light::LightBase;
|
||||
use shared::core::image::DeviceImage;
|
||||
use shared::core::light::{Light, LightBase};
|
||||
use shared::core::medium::MediumInterface;
|
||||
use shared::core::spectrum::Spectrum;
|
||||
use shared::spectra::{DenselySampledSpectrum, SampledSpectrum, SampledWavelengths};
|
||||
use shared::utils::Transform;
|
||||
use shared::core::texture::SpectrumType;
|
||||
use shared::lights::{
|
||||
DistantLight, GoniometricLight, InfiniteUniformLight, PointLight, ProjectionLight, SpotLight,
|
||||
};
|
||||
use shared::spectra::{DenselySampledSpectrum, RGBColorSpace, SampledSpectrum, SampledWavelengths};
|
||||
use shared::utils::{Ptr, Transform};
|
||||
use shared::{Float, PI};
|
||||
|
||||
use crate::core::spectrum::SPECTRUM_CACHE;
|
||||
use crate::core::spectrum::{SPECTRUM_CACHE, spectrum_to_photometric};
|
||||
use crate::lights::*;
|
||||
use crate::utils::containers::InternCache;
|
||||
use crate::utils::{Arena, ParameterDictionary, Upload, resolve_filename};
|
||||
|
||||
pub trait LightBaseTrait {
|
||||
pub fn lookup_spectrum(s: &Spectrum) -> DenselySampledSpectrum {
|
||||
let cache = SPECTRUM_CACHE.get_or_init(InternCache::new);
|
||||
let dense_spectrum = DenselySampledSpectrum::from_spectrum(s);
|
||||
cache.lookup(dense_spectrum).as_ref()
|
||||
}
|
||||
pub fn lookup_spectrum(s: &Spectrum) -> DenselySampledSpectrum {
|
||||
let cache = SPECTRUM_CACHE.get_or_init(InternCache::new);
|
||||
let dense_spectrum = DenselySampledSpectrum::from_spectrum(s);
|
||||
cache.lookup(dense_spectrum).as_ref()
|
||||
}
|
||||
|
||||
impl LightBaseTrait for LightBase {}
|
||||
|
||||
pub trait LightFactory {
|
||||
pub trait CreateLight {
|
||||
fn new(
|
||||
render_from_light: Transform,
|
||||
medium_interface: MediumInterface,
|
||||
le: Spectrum,
|
||||
scale: Float,
|
||||
iemit: &Spectrum,
|
||||
image: &Image,
|
||||
shape: Option<Ptr<Shape>>,
|
||||
alpha: Option<Ptr<FloatTexture>>,
|
||||
image: Option<Ptr<Image>>,
|
||||
image_color_space: Option<Ptr<RGBColorSpace>>,
|
||||
two_sided: Option<bool>,
|
||||
fov: Option<Float>,
|
||||
cos_fallof_start: Option<Float>,
|
||||
total_width: Option<Float>,
|
||||
) -> Self;
|
||||
|
||||
fn create(
|
||||
arena: &mut Arena,
|
||||
render_from_light: Transform,
|
||||
medium: Medium,
|
||||
parameters: &ParameterDictionary,
|
||||
loc: &FileLoc,
|
||||
shape: &Shape,
|
||||
alpha_tex: &FloatTexture,
|
||||
colorspace: Option<&RGBColorSpace>,
|
||||
) -> Light;
|
||||
}
|
||||
|
||||
pub trait LightFactory {
|
||||
fn create(
|
||||
name: &str,
|
||||
arena: &mut Arena,
|
||||
render_from_light: Transform,
|
||||
medium: Medium,
|
||||
parameters: &ParameterDictionary,
|
||||
loc: &FileLoc,
|
||||
shape: &Shape,
|
||||
alpha_tex: &FloatTexture,
|
||||
colorspace: Option<&RGBColorSpace>,
|
||||
) -> Self;
|
||||
}
|
||||
|
||||
impl LightFactory for Light {
|
||||
fn create(
|
||||
name: &str,
|
||||
arena: &mut Arena,
|
||||
render_from_light: Transform,
|
||||
medium: Medium,
|
||||
parameters: &ParameterDictionary,
|
||||
loc: &FileLoc,
|
||||
shape: &Shape,
|
||||
alpha_tex: &FloatTexture,
|
||||
colorspace: Option<&RGBColorSpace>,
|
||||
) -> Self {
|
||||
match name {
|
||||
"point" => PointLight::create(
|
||||
arena,
|
||||
render_from_light,
|
||||
medium,
|
||||
parameters,
|
||||
loc,
|
||||
shape,
|
||||
alpha_tex,
|
||||
colorspace,
|
||||
),
|
||||
"spot" => SpotLight::create(
|
||||
arena,
|
||||
render_from_light,
|
||||
medium,
|
||||
parameters,
|
||||
loc,
|
||||
shape,
|
||||
alpha_tex,
|
||||
colorspace,
|
||||
),
|
||||
"goniometric" => GoniometricLight::create(
|
||||
arena,
|
||||
render_from_light,
|
||||
medium,
|
||||
parameters,
|
||||
loc,
|
||||
shape,
|
||||
alpha_tex,
|
||||
colorspace,
|
||||
),
|
||||
"projection" => ProjectionLight::create(
|
||||
arena,
|
||||
render_from_light,
|
||||
medium,
|
||||
parameters,
|
||||
loc,
|
||||
shape,
|
||||
alpha_tex,
|
||||
colorspace,
|
||||
),
|
||||
"distant" => DistantLight::create(
|
||||
arena,
|
||||
render_from_light,
|
||||
medium,
|
||||
parameters,
|
||||
loc,
|
||||
shape,
|
||||
alpha_tex,
|
||||
colorspace,
|
||||
),
|
||||
"infinite" => {
|
||||
let colorspace = parameters.color_space.unwrap();
|
||||
let l = parameters.get_spectrum_array("L", SpectrumType::Illuminant);
|
||||
let mut scale = parameters.get_one_float("scale", 1.);
|
||||
let portal = parameters.get_point3f_array("portal");
|
||||
let filename = resolve_filename(parameters.get_one_string("filename", ""));
|
||||
let e_v = parameters.get_one_float("illuminance", -1.);
|
||||
if l.is_empty() && filename.is_empty() && portal.is_empty() {
|
||||
if e_v > 0. {
|
||||
let k_e = PI;
|
||||
scale *= e_v / k_e;
|
||||
}
|
||||
let specific = InfiniteUniformLight::new(
|
||||
render_from_light,
|
||||
medium_interface,
|
||||
arena.alloc(le),
|
||||
scale,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
arena.alloc(specific);
|
||||
return Light::InfiniteUniform(specific);
|
||||
} else if !l.is_empty() && portal.is_empty() {
|
||||
if !filename.is_empty() {
|
||||
panic!(
|
||||
"{}: Both \"L\" and \"filename\" specified for DiffuseAreaLight.",
|
||||
loc
|
||||
);
|
||||
}
|
||||
scale /= spectrum_to_photometric(l[0]);
|
||||
if e_v > 0. {
|
||||
let k_e = PI;
|
||||
scale *= e_v / k_e;
|
||||
}
|
||||
let specific = InfiniteUniformLight::new(
|
||||
render_from_light,
|
||||
medium_interface,
|
||||
arena.alloc(le),
|
||||
scale,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
arena.alloc(specific);
|
||||
return Light::InfiniteUniform(specific);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::image::ImageBuffer;
|
||||
use crate::core::image::Image;
|
||||
use crate::utils::error::FileLoc;
|
||||
use crate::utils::parameters::ParameterDictionary;
|
||||
use shared::core::material::Material;
|
||||
|
|
@ -8,7 +8,7 @@ use std::collections::HashMap;
|
|||
pub trait CreateMaterial: Sized {
|
||||
fn create(
|
||||
parameters: &TextureParameterDictionary,
|
||||
normal_map: Option<Arc<ImageBuffer>>,
|
||||
normal_map: Option<Arc<Image>>,
|
||||
named_materials: &HashMap<String, Material>,
|
||||
loc: &FileLoc,
|
||||
) -> Self;
|
||||
|
|
@ -35,7 +35,7 @@ pub trait MaterialFactory {
|
|||
fn create(
|
||||
name: &str,
|
||||
params: &TextureParameterDictionary,
|
||||
normal_map: Arc<ImageBuffer>,
|
||||
normal_map: Arc<Image>,
|
||||
named_materials: HashMap<String, Material>,
|
||||
loc: &FileLoc,
|
||||
) -> Result<Self, String>;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::core::filter::FilterFactory;
|
||||
use crate::core::image::{ImageBuffer, io::ImageIO};
|
||||
use crate::core::image::{Image, io::ImageIO};
|
||||
use crate::core::texture::SpectrumTexture;
|
||||
use crate::utils::parallel::{AsyncJob, run_async};
|
||||
use crate::utils::parameters::{
|
||||
|
|
@ -694,7 +694,7 @@ impl BasicScene {
|
|||
let job = crate::parallel::run_async(move || {
|
||||
let path = std::path::Path::new(&filename_clone);
|
||||
|
||||
let immeta = ImageBuffer::read(path, Some(ColorEncoding::Linear))
|
||||
let immeta = Image::read(path, Some(ColorEncoding::Linear))
|
||||
.unwrap_or_else(|e| panic!("{}: unable to read normal map: {}", filename_clone, e));
|
||||
|
||||
let image = &immeta.image;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::core::texture::FloatTexture;
|
||||
use crate::shapes::TriQuadMesh;
|
||||
use crate::utils::{FileLoc, ParameterDictionary, resolve_filename};
|
||||
use crate::utils::{Arena, FileLoc, ParameterDictionary, resolve_filename};
|
||||
use shared::core::options::get_options;
|
||||
use shared::core::shape::*;
|
||||
use shared::shapes::*;
|
||||
|
|
@ -21,6 +21,7 @@ pub trait CreateShape {
|
|||
parameters: ParameterDictionary,
|
||||
float_textures: HashMap<String, FloatTexture>,
|
||||
loc: FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Vec<Shape>;
|
||||
}
|
||||
|
||||
|
|
@ -33,6 +34,7 @@ pub trait ShapeFactory {
|
|||
parameters: ParameterDictionary,
|
||||
float_textures: HashMap<String, FloatTexture>,
|
||||
loc: FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Vec<Shape>;
|
||||
}
|
||||
|
||||
|
|
@ -45,6 +47,7 @@ impl ShapeFactory for Shape {
|
|||
parameters: ParameterDictionary,
|
||||
float_textures: HashMap<String, FloatTexture>,
|
||||
loc: FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Vec<Shape> {
|
||||
match name {
|
||||
"sphere" => SphereShape::create(
|
||||
|
|
@ -55,6 +58,7 @@ impl ShapeFactory for Shape {
|
|||
parameters,
|
||||
float_textures,
|
||||
loc,
|
||||
arena,
|
||||
),
|
||||
"cylinder" => CylinderShape::create(
|
||||
name,
|
||||
|
|
@ -64,6 +68,7 @@ impl ShapeFactory for Shape {
|
|||
parameters,
|
||||
float_textures,
|
||||
loc,
|
||||
arena,
|
||||
),
|
||||
"disk" => DiskShape::create(
|
||||
name,
|
||||
|
|
@ -73,6 +78,7 @@ impl ShapeFactory for Shape {
|
|||
parameters,
|
||||
float_textures,
|
||||
loc,
|
||||
arena,
|
||||
),
|
||||
"bilinearmesh" => BilinearPatchShape::create(
|
||||
name,
|
||||
|
|
@ -82,6 +88,7 @@ impl ShapeFactory for Shape {
|
|||
parameters,
|
||||
float_textures,
|
||||
loc,
|
||||
arena,
|
||||
),
|
||||
"trianglemesh" => TriangleShape::create(
|
||||
name,
|
||||
|
|
@ -91,6 +98,7 @@ impl ShapeFactory for Shape {
|
|||
parameters,
|
||||
float_textures,
|
||||
loc,
|
||||
arena,
|
||||
),
|
||||
"plymesh" => {
|
||||
let filename = resolve_filename(parameters.get_one_string("filename", ""));
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
use crate::core::light::LightBaseTrait;
|
||||
use crate::spectra::cie_y;
|
||||
use crate::utils::containers::InternCache;
|
||||
use shared::Float;
|
||||
use shared::core::light::LightBase;
|
||||
use shared::core::spectrum::Spectrum;
|
||||
|
||||
pub static SPECTRUM_CACHE: Lazy<Mutex<HashMap<String, Spectrum>>> =
|
||||
Lazy::new(|| Mutex::new(HashMap::new()));
|
||||
|
|
@ -6,3 +11,11 @@ pub static SPECTRUM_CACHE: Lazy<Mutex<HashMap<String, Spectrum>>> =
|
|||
fn get_spectrum_cache() -> &'static InternCache<DenselySampledSpectrum> {
|
||||
SPECTRUM_CACHE.get_or_init(InternCache::new)
|
||||
}
|
||||
|
||||
pub fn spectrum_to_photometric(s: Spectrum) -> Float {
|
||||
let effective_spectrum = match s {
|
||||
Spectrum::RGBIlluminant(ill) => &Spectrum::Dense(ill.illuminant),
|
||||
_ => s,
|
||||
};
|
||||
effective_spectrum.inner_product(cie_y)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::core::image::ImageBuffer;
|
||||
use crate::core::image::Image;
|
||||
use crate::core::material::CreateMaterial;
|
||||
use crate::utils::parameters::ParameterDictionary;
|
||||
use crate::utils::{Arena, ParameterDictionary};
|
||||
use shared::core::spectrum::Spectrum;
|
||||
use shared::core::texture::SpectrumType;
|
||||
use shared::materials::coated::*;
|
||||
|
|
@ -10,9 +10,10 @@ use shared::textures::SpectrumConstantTexture;
|
|||
impl CreateMaterial for CoatedDiffuseMaterial {
|
||||
fn create(
|
||||
parameters: &TextureParameterDictionary,
|
||||
normal_map: Option<Arc<ImageBuffer>>,
|
||||
normal_map: Option<Arc<Image>>,
|
||||
named_materials: &HashMap<String, Material>,
|
||||
loc: &FileLoc,
|
||||
area: &mut Arena,
|
||||
) -> Self {
|
||||
let reflectance = parameters
|
||||
.get_spectrum_texture("reflectance", None, SpectrumType::Albedo)
|
||||
|
|
@ -45,15 +46,30 @@ impl CreateMaterial for CoatedDiffuseMaterial {
|
|||
});
|
||||
let displacement = parameters.get_float_texture("displacement");
|
||||
let remap_roughness = parameters.get_one_bool("remaproughness", true);
|
||||
arena.alloc(Self::new(
|
||||
reflectance,
|
||||
u_roughness,
|
||||
v_roughness,
|
||||
thickness,
|
||||
albedo,
|
||||
g,
|
||||
eta,
|
||||
displacement,
|
||||
normal_map,
|
||||
remap_roughness,
|
||||
max_depth,
|
||||
n_samples,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
impl CreateMaterial for CoatedConductorMaterial {
|
||||
fn create(
|
||||
parameters: &TextureParameterDictionary,
|
||||
normal_map: Option<Arc<ImageBuffer>>,
|
||||
normal_map: Option<Arc<Image>>,
|
||||
named_materials: &HashMap<String, Material>,
|
||||
loc: &FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Result<Self, String> {
|
||||
let interface_u_roughness = parameters
|
||||
.get_float_texture_or_null("interface.uroughness")
|
||||
|
|
@ -106,7 +122,7 @@ impl CreateMaterial for CoatedConductorMaterial {
|
|||
});
|
||||
let displacement = parameters.get_float_texture_or_null("displacement");
|
||||
let remap_roughness = parameters.get_one_bool("remaproughness", true);
|
||||
Self::new(
|
||||
let material = Self::new(
|
||||
displacement,
|
||||
normal_map,
|
||||
interface_u_roughness,
|
||||
|
|
@ -123,6 +139,8 @@ impl CreateMaterial for CoatedConductorMaterial {
|
|||
remap_roughness,
|
||||
max_depth,
|
||||
n_samples,
|
||||
)
|
||||
);
|
||||
arena.alloc(material);
|
||||
return material;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::core::material::CreateMaterial;
|
||||
use crate::utils::{Arena, FileLoc, TextureParameterDictionary};
|
||||
use shared::core::bxdf::HairBxDF;
|
||||
use shared::core::spectrum::Spectrum;
|
||||
use shared::core::texture::{GPUFloatTexture, GPUSpectrumTexture};
|
||||
|
|
@ -10,6 +11,7 @@ impl CreateMaterial for HairMaterial {
|
|||
normal_map: Option<Arc<ImageBuffer>>,
|
||||
named_materials: &HashMap<String, Material>,
|
||||
loc: &FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Result<Self, String> {
|
||||
let sigma_a = parameters.get_spectrum_texture_or_null("sigma_a", SpectrumType::Unbounded);
|
||||
let reflectance = parameters
|
||||
|
|
@ -57,7 +59,7 @@ impl CreateMaterial for HairMaterial {
|
|||
let beta_m = parameters.get_float_texture("beta_m", 0.3);
|
||||
let beta_n = parameters.get_float_texture("beta_n", 0.3);
|
||||
let alpha = parameters.get_float_texture("alpha", 2.);
|
||||
HairMaterial::new(
|
||||
let material = HairMaterial::new(
|
||||
sigma_a,
|
||||
reflectance,
|
||||
eumelanin,
|
||||
|
|
@ -66,7 +68,10 @@ impl CreateMaterial for HairMaterial {
|
|||
beta_m,
|
||||
beta_n,
|
||||
alpha,
|
||||
)
|
||||
);
|
||||
|
||||
arena.alloc(material);
|
||||
return material;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
use crate::core::shape::{ALL_BILINEAR_MESHES, CreateShape};
|
||||
use crate::core::shape::{ALL_BILINEAR_MESHES, CreateMesh, CreateShape};
|
||||
use crate::core::texture::FloatTexture;
|
||||
use crate::shapes::mesh::BilinearPatchMeshHost;
|
||||
use crate::utils::{FileLoc, ParameterDictionary};
|
||||
use crate::shapes::mesh::Mesh;
|
||||
use crate::utils::{Arena, FileLoc, ParameterDictionary};
|
||||
use shared::shapes::BilinearPatchShape;
|
||||
use shared::utils::Transform;
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl CreateShape for BilinearPatchShape {
|
||||
impl CreateMesh for BilinearPatchShape {
|
||||
fn create(
|
||||
render_from_object: &Transform,
|
||||
_object_from_render: &Transform,
|
||||
|
|
@ -13,6 +14,7 @@ impl CreateShape for BilinearPatchShape {
|
|||
parameters: &ParameterDictionary,
|
||||
_float_textures: &HashMap<String, FloatTexture>,
|
||||
_loc: &FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Result<Mesh, String> {
|
||||
let mut vertex_indices = parameters.get_int_array("indices");
|
||||
let mut p = parameters.get_point3f_array("P");
|
||||
|
|
@ -128,6 +130,7 @@ impl CreateShape for BilinearPatchShape {
|
|||
rectangle: false,
|
||||
}));
|
||||
}
|
||||
arena.alloc(shapes);
|
||||
Ok(shapes)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,6 +194,7 @@ impl CreateShape for CurveShape {
|
|||
|
||||
curves.extend(new_curves);
|
||||
}
|
||||
arena.alloc(curves);
|
||||
Ok(curves)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::core::shape::CreateShape;
|
||||
use crate::core::texture::FloatTexture;
|
||||
use crate::utils::{FileLoc, ParameterDictionary};
|
||||
use crate::utils::{Arena, FileLoc, ParameterDictionary};
|
||||
use shared::core::shape::Shape;
|
||||
use shared::shapes::CylinderShape;
|
||||
use shared::utils::Transform;
|
||||
|
|
@ -15,6 +15,7 @@ impl CreateShape for CylinderShape {
|
|||
parameters: ParameterDictionary,
|
||||
float_textures: HashMap<String, FloatTexture>,
|
||||
loc: FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Result<Vec<Shape>, String> {
|
||||
let radius = parameters.get_one_float("radius", 1.);
|
||||
let z_min = parameters.get_one_float("zmin", -1.);
|
||||
|
|
@ -30,6 +31,7 @@ impl CreateShape for CylinderShape {
|
|||
phi_max,
|
||||
);
|
||||
|
||||
arena.alloc(Shape::Cylinder(shape));
|
||||
Ok(vec![Shape::Cylinder(shape)])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::core::shape::CreateShape;
|
||||
use crate::core::texture::FloatTexture;
|
||||
use crate::utils::{FileLoc, ParameterDictionary};
|
||||
use crate::utils::{Arena, FileLoc, ParameterDictionary};
|
||||
use shared::core::shape::Shape;
|
||||
use shared::shapes::DiskShape;
|
||||
use shared::utils::Transform;
|
||||
|
|
@ -15,6 +15,7 @@ impl CreateShape for DiskShape {
|
|||
parameters: ParameterDictionary,
|
||||
float_textures: HashMap<String, FloatTexture>,
|
||||
loc: FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Result<Vec<Shape>, String> {
|
||||
let height = parameters.get_one_float("height", 0.);
|
||||
let radius = parameters.get_one_float("radius", 1.);
|
||||
|
|
@ -30,6 +31,7 @@ impl CreateShape for DiskShape {
|
|||
reverse_orientation,
|
||||
);
|
||||
|
||||
arena.alloc(Shape::Disk(shape));
|
||||
Ok(vec![Shape::Disk(shape)])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use ply_rs::parser::Parser;
|
|||
use ply_rs::ply::{DefaultElement, Property};
|
||||
use shared::utils::Transform;
|
||||
use shared::utils::mesh::{BilinearPatchMesh, TriangleMesh};
|
||||
use shared::utils::sampling::PiecewiseConstant2D;
|
||||
use shared::utils::sampling::DevicePiecewiseConstant2D;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
|
|
@ -211,40 +211,32 @@ impl TriQuadMesh {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct TriangleMeshStorage {
|
||||
vertex_indices: Vec<u32>,
|
||||
p: Vec<Point3f>,
|
||||
n: Vec<Normal3f>,
|
||||
s: Vec<Vector3f>,
|
||||
uv: Vec<Point2f>,
|
||||
face_indices: Vec<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct TriangleMeshHost {
|
||||
pub view: TriangleMesh,
|
||||
_storage: Arc<TriangleMeshStorage>,
|
||||
}
|
||||
|
||||
impl Deref for TriangleMeshHost {
|
||||
type Target = TriangleMesh;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.view
|
||||
}
|
||||
}
|
||||
|
||||
impl TriangleMeshHost {
|
||||
pub fn new(
|
||||
render_from_object: Transform,
|
||||
pub trait TriangleMeshFactory {
|
||||
fn create(
|
||||
arena: &mut Arena,
|
||||
render_from_object: &Transform,
|
||||
reverse_orientation: bool,
|
||||
vertex_indices: Vec<usize>,
|
||||
mut p: Vec<Point3f>,
|
||||
mut s: Vec<Vector3f>,
|
||||
mut n: Vec<Normal3f>,
|
||||
vertex_indices: Vec<u32>,
|
||||
p: Vec<Point3f>,
|
||||
n: Vec<Normal3f>,
|
||||
s: Vec<Vector3f>,
|
||||
uv: Vec<Point2f>,
|
||||
face_indices: Vec<usize>,
|
||||
) -> Self {
|
||||
face_indices: Vec<u32>,
|
||||
) -> ArenaPtr<TriangleMesh>;
|
||||
}
|
||||
|
||||
impl TriangleMeshFactory for TriangleMesh {
|
||||
fn create(
|
||||
arena: &mut Arena,
|
||||
render_from_object: &Transform,
|
||||
reverse_orientation: bool,
|
||||
vertex_indices: Vec<u32>,
|
||||
p: Vec<Point3f>,
|
||||
n: Vec<Normal3f>,
|
||||
s: Vec<Vector3f>,
|
||||
uv: Vec<Point2f>,
|
||||
face_indices: Vec<u32>,
|
||||
) -> ArenaPtr<TriangleMesh> {
|
||||
let n_triangles = indices.len() / 3;
|
||||
let n_vertices = p.len();
|
||||
for pt in p.iter_mut() {
|
||||
|
|
@ -342,7 +334,7 @@ pub struct BilinearMeshStorage {
|
|||
p: Vec<Point3f>,
|
||||
n: Vec<Normal3f>,
|
||||
uv: Vec<Point2f>,
|
||||
image_distribution: Option<PiecewiseConstant2D>,
|
||||
image_distribution: Option<DevicePiecewiseConstant2D>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
@ -366,7 +358,7 @@ impl BilinearPatchMeshHost {
|
|||
mut p: Vec<Point3f>,
|
||||
mut n: Vec<Normal3f>,
|
||||
uv: Vec<Point2f>,
|
||||
image_distribution: Option<PiecewiseConstant2D>,
|
||||
image_distribution: Option<DevicePiecewiseConstant2D>,
|
||||
) -> Self {
|
||||
let n_patches = indices.len() / 3;
|
||||
let n_vertices = p.len();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::core::shape::CreateShape;
|
||||
use crate::core::texture::FloatTexture;
|
||||
use crate::utils::{FileLoc, ParameterDictionary};
|
||||
use crate::utils::{Arena, FileLoc, ParameterDictionary};
|
||||
use shared::core::shape::Shape;
|
||||
use shared::shapes::SphereShape;
|
||||
use shared::utils::Transform;
|
||||
|
|
@ -14,6 +14,7 @@ impl CreateShape for SphereShape {
|
|||
parameters: ParameterDictionary,
|
||||
float_textures: HashMap<String, FloatTexture>,
|
||||
loc: FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Result<Vec<Shape>, String> {
|
||||
let radius = parameters.get_one_float("radius", 1.);
|
||||
let zmin = parameters.get_one_float("zmin", -radius);
|
||||
|
|
@ -28,6 +29,7 @@ impl CreateShape for SphereShape {
|
|||
zmax,
|
||||
phimax,
|
||||
);
|
||||
arena.alloc(vec![Shape::Sphere(SphereShape)]);
|
||||
Ok(vec![Shape::Sphere(SphereShape)])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::core::shape::{ALL_TRIANGLE_MESHES, CreateShape};
|
||||
use crate::core::texture::FloatTexture;
|
||||
use crate::shapes::mesh::TriangleMeshHost;
|
||||
use crate::utils::{FileLoc, ParameterDictionary};
|
||||
use crate::utils::{Arena, FileLoc, ParameterDictionary};
|
||||
use shared::shapes::TriangleShape;
|
||||
use shared::utils::Transform;
|
||||
|
||||
|
|
@ -12,6 +12,7 @@ impl CreateShape for TriangleShape {
|
|||
reverse_orientation: bool,
|
||||
parameters: ParameterDictionary,
|
||||
loc: FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Result<Mesh, String> {
|
||||
let mut vertex_indices = parameters.get_int_array("indices");
|
||||
let mut p = parameters.get_point3f_array("P");
|
||||
|
|
@ -104,6 +105,8 @@ impl CreateShape for TriangleShape {
|
|||
tri_index: i,
|
||||
}));
|
||||
}
|
||||
|
||||
arena.alloc(shapes);
|
||||
Ok(shapes)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ impl SpectrumTextureTrait for SpectrumImageTexture {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FloatImageTexture {
|
||||
base: ImageTextureBase,
|
||||
pub base: ImageTextureBase,
|
||||
}
|
||||
|
||||
impl FloatImageTexture {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
use crate::core::texture::{
|
||||
FloatTexture, FloatTextureTrait, SpectrumTexture, SpectrumTextureTrait,
|
||||
};
|
||||
use crate::utils::{FileLoc, TextureParameterDictionary};
|
||||
use crate::utils::{Arena, FileLoc, TextureParameterDictionary};
|
||||
use shared::core::geometry::Vector3f;
|
||||
use shared::utils::Transform;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FloatMixTexture {
|
||||
tex1: Arc<FloatTexture>,
|
||||
tex2: Arc<FloatTexture>,
|
||||
amount: Arc<FloatTexture>,
|
||||
pub tex1: Arc<FloatTexture>,
|
||||
pub tex2: Arc<FloatTexture>,
|
||||
pub amount: Arc<FloatTexture>,
|
||||
}
|
||||
|
||||
impl FloatMixTexture {
|
||||
|
|
@ -26,11 +26,12 @@ impl FloatMixTexture {
|
|||
_render_from_texture: &Transform,
|
||||
params: &TextureParameterDictionary,
|
||||
_loc: &FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Self {
|
||||
let tex1 = params.get_float_texture("tex1", 0.);
|
||||
let tex2 = params.get_float_texture("tex2", 1.);
|
||||
let amount = params.get_float_texture("amount", 0.5);
|
||||
Self::new(tex1, tex2, amount)
|
||||
arena.alloc(Self::new(tex1, tex2, amount))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,9 +52,9 @@ impl FloatTextureTrait for FloatMixTexture {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FloatDirectionMixTexture {
|
||||
tex1: Arc<FloatTexture>,
|
||||
tex2: Arc<FloatTexture>,
|
||||
dir: Vector3f,
|
||||
pub tex1: Arc<FloatTexture>,
|
||||
pub tex2: Arc<FloatTexture>,
|
||||
pub dir: Vector3f,
|
||||
}
|
||||
|
||||
impl FloatDirectionMixTexture {
|
||||
|
|
@ -65,12 +66,13 @@ impl FloatDirectionMixTexture {
|
|||
render_from_texture: &Transform,
|
||||
params: &TextureParameterDictionary,
|
||||
_loc: &FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> Self {
|
||||
let dir_raw = params.get_one_vector3f("dir", Vector3f::new(0., 1., 0.));
|
||||
let dir = render_from_texture.apply_to_vector(dir_raw).normalize();
|
||||
let tex1 = params.get_float_texture("tex1", 0.);
|
||||
let tex2 = params.get_float_texture("tex2", 1.);
|
||||
Self::new(tex1, tex2, dir)
|
||||
arena.alloc(Self::new(tex1, tex2, dir))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::utils::{FileLoc, TextureParameterDictionary};
|
||||
use crate::utils::{Arena, FileLoc, TextureParameterDictionary};
|
||||
use shared::core::texture::{SpectrumType, TextureEvalContext};
|
||||
use shared::spectra::ColorEncoding;
|
||||
use shared::spectra::color::RGB;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use crate::core::texture::{
|
||||
FloatTexture, FloatTextureTrait, SpectrumTexture, SpectrumTextureTrait,
|
||||
};
|
||||
use crate::utils::{FileLoc, TextureParameterDictionary};
|
||||
use crate::utils::{Arena, FileLoc, TextureParameterDictionary};
|
||||
use shared::core::texture::TextureEvalContext;
|
||||
use shared::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use shared::utils::Transform;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FloatScaledTexture {
|
||||
tex: Arc<FloatTexture>,
|
||||
scale: Arc<FloatTexture>,
|
||||
pub tex: Arc<FloatTexture>,
|
||||
pub scale: Arc<FloatTexture>,
|
||||
}
|
||||
|
||||
impl FloatScaledTexture {
|
||||
|
|
@ -21,6 +21,7 @@ impl FloatScaledTexture {
|
|||
_render_from_texture: &Transform,
|
||||
params: &TextureParameterDictionary,
|
||||
_loc: &FileLoc,
|
||||
arena: &mut Arena,
|
||||
) -> FloatTexture {
|
||||
let mut tex = params.get_float_texture("tex", 1.);
|
||||
let mut scale = params.get_float_texture("scale", 1.);
|
||||
|
|
@ -40,6 +41,7 @@ impl FloatScaledTexture {
|
|||
std::mem::swap(&mut tex, &mut scale);
|
||||
}
|
||||
std::mem::swap(&mut tex, &mut scale);
|
||||
arena.alloc(FloatScaledTexture::new(tex, scale));
|
||||
FloatTexture::FloatScaled(FloatScaledTexture::new(tex, scale))
|
||||
}
|
||||
}
|
||||
|
|
@ -56,8 +58,8 @@ impl FloatTextureTrait for FloatScaledTexture {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SpectrumScaledTexture {
|
||||
tex: Arc<SpectrumTexture>,
|
||||
scale: Arc<FloatTexture>,
|
||||
pub tex: Arc<SpectrumTexture>,
|
||||
pub scale: Arc<FloatTexture>,
|
||||
}
|
||||
|
||||
impl SpectrumTextureTrait for SpectrumScaledTexture {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use half::f16;
|
||||
use shared::Float;
|
||||
use shared::utils::Ptr;
|
||||
use shared::utils::DevicePtr;
|
||||
use shared::utils::math::{DigitPermutation, PRIMES};
|
||||
|
||||
pub fn new_digit_permutation(base: u32, seed: u64) -> Vec<u16> {
|
||||
|
|
@ -56,7 +56,7 @@ pub fn compute_radical_inverse_permutations(seed: u64) -> (Vec<u16>, Vec<DigitPe
|
|||
views.push(DigitPermutation::new(
|
||||
base as u32,
|
||||
n_digits,
|
||||
Ptr(ptr_to_data),
|
||||
DevicePtr(ptr_to_data),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
pub mod arena;
|
||||
pub mod containers;
|
||||
pub mod error;
|
||||
pub mod file;
|
||||
|
|
@ -9,6 +10,7 @@ pub mod parameters;
|
|||
pub mod parser;
|
||||
pub mod sampling;
|
||||
|
||||
pub use arena::{Arena, Upload};
|
||||
pub use error::FileLoc;
|
||||
pub use file::{read_float_file, resolve_filename};
|
||||
pub use parameters::{
|
||||
|
|
|
|||
|
|
@ -1,30 +1,39 @@
|
|||
use shared::Float;
|
||||
use shared::core::geometry::{Bounds2f, Point2f};
|
||||
use shared::utils::Ptr;
|
||||
use shared::utils::DevicePtr;
|
||||
use shared::utils::sampling::{
|
||||
AliasTable, PiecewiseConstant1D, PiecewiseConstant2D, PiecewiseLinear2D,
|
||||
AliasTable, DevicePiecewiseConstant1D, DevicePiecewiseConstant2D, PiecewiseLinear2D,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PiecewiseConstant1DHost {
|
||||
pub view: PiecewiseConstant1D,
|
||||
_func: Vec<Float>,
|
||||
_cdf: Vec<Float>,
|
||||
pub struct PiecewiseConstant1D {
|
||||
pub func: Vec<Float>,
|
||||
pub cdf: Vec<Float>,
|
||||
pub func_integral: Float,
|
||||
pub min: Float,
|
||||
pub max: Float,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for PiecewiseConstant1DHost {
|
||||
type Target = PiecewiseConstant1D;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.view
|
||||
}
|
||||
}
|
||||
|
||||
impl PiecewiseConstant1DHost {
|
||||
impl PiecewiseConstant1D {
|
||||
pub fn new(f: &[Float]) -> Self {
|
||||
Self::new_with_bounds(f, 0.0, 1.0)
|
||||
}
|
||||
|
||||
pub fn to_shared(&self, arena: &mut Arena) -> DevicePiecewiseConstant1D {
|
||||
let func_ptr = arena.alloc_slice(&self.func);
|
||||
let cdf_ptr = arena.alloc_slice(&self.cdf);
|
||||
|
||||
DevicePiecewiseConstant1D {
|
||||
func: func_ptr,
|
||||
cdf: cdf_ptr,
|
||||
func_integral: self.func_integral,
|
||||
n: func.len(),
|
||||
min: self.min,
|
||||
max: self.max,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_bounds(f: &[Float], min: Float, max: Float) -> Self {
|
||||
let n = f.len();
|
||||
|
||||
|
|
@ -47,44 +56,31 @@ impl PiecewiseConstant1DHost {
|
|||
}
|
||||
}
|
||||
|
||||
let view = PiecewiseConstant1D {
|
||||
func: Ptr(func_vec.as_ptr()),
|
||||
cdf: Ptr(cdf_vec.as_ptr()),
|
||||
Self {
|
||||
func: func_vec,
|
||||
cdf: cdf_vec,
|
||||
func_integral,
|
||||
min,
|
||||
max,
|
||||
n: n as u32,
|
||||
func_integral,
|
||||
};
|
||||
|
||||
Self {
|
||||
view,
|
||||
_func: func_vec,
|
||||
_cdf: cdf_vec,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PiecewiseConstant2DHost {
|
||||
pub view: PiecewiseConstant2D,
|
||||
_p_conditional_v: Vec<PiecewiseConstant1D>,
|
||||
pub struct PiecewiseConstant2D {
|
||||
pub domain: Bounds2f,
|
||||
pub p_marginal: PiecewiseConstant1D,
|
||||
pub p_conditionals: Vec<PiecewiseConstant1D>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for PiecewiseConstant2DHost {
|
||||
type Target = PiecewiseConstant2D;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.view
|
||||
}
|
||||
}
|
||||
|
||||
impl PiecewiseConstant2DHost {
|
||||
impl PiecewiseConstant2D {
|
||||
pub fn new(data: &Array2D<Float>, x_size: u32, y_size: u32, domain: Bounds2f) -> Self {
|
||||
let nu = x_size as usize;
|
||||
let nv = y_size as usize;
|
||||
let mut conditionals = Vec::with_capacity(nv);
|
||||
for v in 0..nv {
|
||||
let row = unsafe { core::slice::from_raw_parts(data.values.add(v * nu), nu) };
|
||||
conditionals.push(PiecewiseConstant1D::new_with_bounds(
|
||||
conditionals.push(DevicePiecewiseConstant1D::new_with_bounds(
|
||||
row,
|
||||
domain.p_min.x(),
|
||||
domain.p_max.x(),
|
||||
|
|
@ -92,24 +88,16 @@ impl PiecewiseConstant2DHost {
|
|||
}
|
||||
|
||||
let marginal_funcs: Vec<Float> = conditionals.iter().map(|c| c.func_integral).collect();
|
||||
let p_marginal = PiecewiseConstant1D::new_with_bounds(
|
||||
let p_marginal = DevicePiecewiseConstant1D::new_with_bounds(
|
||||
&marginal_funcs,
|
||||
domain.p_min.y(),
|
||||
domain.p_max.y(),
|
||||
);
|
||||
|
||||
let p_conditional_v = conditionals.as_mut_ptr();
|
||||
std::mem::forget(conditionals);
|
||||
let view = PiecewiseConstant2D {
|
||||
Self {
|
||||
domain,
|
||||
p_marginal,
|
||||
n_conditionals: nv,
|
||||
p_conditional_v: Ptr(p_conditional_v),
|
||||
};
|
||||
|
||||
Self {
|
||||
view,
|
||||
_p_conditional_v: p_conditional_v,
|
||||
p_conditionals: conditionals,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue