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