Very broken
This commit is contained in:
parent
4e1b3619f4
commit
dac5d2c28f
9 changed files with 72 additions and 30 deletions
|
|
@ -78,7 +78,7 @@ impl UVMapping {
|
||||||
let dsdy = self.su * ctx.dudy;
|
let dsdy = self.su * ctx.dudy;
|
||||||
let dtdx = self.sv * ctx.dvdx;
|
let dtdx = self.sv * ctx.dvdx;
|
||||||
let dtdy = self.sv * ctx.dvdy;
|
let dtdy = self.sv * ctx.dvdy;
|
||||||
let st = Point2f::new(self.su * ctx.uv[0] + self.du, self.sv * ctx.uv[1] * self.dv);
|
let st = Point2f::new(self.su * ctx.uv[0] + self.du, self.sv * ctx.uv[1] + self.dv);
|
||||||
TexCoord2D {
|
TexCoord2D {
|
||||||
st,
|
st,
|
||||||
dsdx,
|
dsdx,
|
||||||
|
|
@ -107,7 +107,7 @@ impl SphericalMapping {
|
||||||
let x2y2 = square(pt.x()) + square(pt.y());
|
let x2y2 = square(pt.x()) + square(pt.y());
|
||||||
let sqrtx2y2 = x2y2.sqrt();
|
let sqrtx2y2 = x2y2.sqrt();
|
||||||
let dsdp = Vector3f::new(-pt.y(), pt.x(), 0.) / (2. * PI * x2y2);
|
let dsdp = Vector3f::new(-pt.y(), pt.x(), 0.) / (2. * PI * x2y2);
|
||||||
let dtdp = 1. / (PI * (x2y2 * square(pt.z())))
|
let dtdp = 1. / (PI * (x2y2 + square(pt.z())))
|
||||||
* Vector3f::new(
|
* Vector3f::new(
|
||||||
pt.x() * pt.z() / sqrtx2y2,
|
pt.x() * pt.z() / sqrtx2y2,
|
||||||
pt.y() * pt.z() / sqrtx2y2,
|
pt.y() * pt.z() / sqrtx2y2,
|
||||||
|
|
@ -148,7 +148,7 @@ impl CylindricalMapping {
|
||||||
let pt = self.texture_from_render.apply_to_point(ctx.p);
|
let pt = self.texture_from_render.apply_to_point(ctx.p);
|
||||||
let x2y2 = square(pt.x()) + square(pt.y());
|
let x2y2 = square(pt.x()) + square(pt.y());
|
||||||
let dsdp = Vector3f::new(-pt.y(), pt.x(), 0.) / (2. * PI * x2y2);
|
let dsdp = Vector3f::new(-pt.y(), pt.x(), 0.) / (2. * PI * x2y2);
|
||||||
let dtdp = Vector3f::new(1., 0., 0.);
|
let dtdp = Vector3f::new(0., 0., 1.);
|
||||||
let dpdx = self.texture_from_render.apply_to_vector(ctx.dpdx);
|
let dpdx = self.texture_from_render.apply_to_vector(ctx.dpdx);
|
||||||
let dpdy = self.texture_from_render.apply_to_vector(ctx.dpdy);
|
let dpdy = self.texture_from_render.apply_to_vector(ctx.dpdy);
|
||||||
let dsdx = dsdp.dot(dpdx);
|
let dsdx = dsdp.dot(dpdx);
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ use crate::core::interaction::{Interaction, InteractionBase, SimpleInteraction};
|
||||||
use crate::core::light::{LightBase, LightBounds, LightLiSample, LightSampleContext, LightTrait};
|
use crate::core::light::{LightBase, LightBounds, LightLiSample, LightSampleContext, LightTrait};
|
||||||
use crate::core::spectrum::SpectrumTrait;
|
use crate::core::spectrum::SpectrumTrait;
|
||||||
use crate::spectra::{DenselySampledSpectrum, SampledSpectrum, SampledWavelengths};
|
use crate::spectra::{DenselySampledSpectrum, SampledSpectrum, SampledWavelengths};
|
||||||
use crate::utils::Ptr;
|
use crate::utils::math::square;
|
||||||
use crate::{Float, PI};
|
use crate::{Float, Ptr, PI};
|
||||||
use num_traits::Float as NumFloat;
|
use num_traits::Float as NumFloat;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
@ -42,7 +42,7 @@ impl LightTrait for DistantLight {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn phi(&self, lambda: SampledWavelengths) -> SampledSpectrum {
|
fn phi(&self, lambda: SampledWavelengths) -> SampledSpectrum {
|
||||||
self.scale * self.lemit.sample(&lambda) * PI * self.scene_radius.sqrt()
|
self.scale * self.lemit.sample(&lambda) * PI * square(self.scene_radius)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sample_li(
|
fn sample_li(
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::Float;
|
|
||||||
use crate::bxdfs::{
|
use crate::bxdfs::{
|
||||||
CoatedConductorBxDF, CoatedDiffuseBxDF, ConductorBxDF, DielectricBxDF, DiffuseBxDF, HairBxDF,
|
CoatedConductorBxDF, CoatedDiffuseBxDF, ConductorBxDF, DielectricBxDF, DiffuseBxDF, HairBxDF,
|
||||||
};
|
};
|
||||||
|
|
@ -11,8 +10,9 @@ 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::Ptr;
|
|
||||||
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)]
|
||||||
|
|
@ -29,7 +29,8 @@ impl MaterialTrait for DiffuseMaterial {
|
||||||
ctx: &MaterialEvalContext,
|
ctx: &MaterialEvalContext,
|
||||||
lambda: &SampledWavelengths,
|
lambda: &SampledWavelengths,
|
||||||
) -> BSDF {
|
) -> BSDF {
|
||||||
let r = 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 bxdf = BxDF::Diffuse(DiffuseBxDF::new(r));
|
let bxdf = BxDF::Diffuse(DiffuseBxDF::new(r));
|
||||||
BSDF::new(ctx.ns, ctx.dpdus, bxdf)
|
BSDF::new(ctx.ns, ctx.dpdus, bxdf)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,9 @@ impl SpectrumImageTexture {
|
||||||
};
|
};
|
||||||
let mut rgb = rgb * self.scale;
|
let mut rgb = rgb * self.scale;
|
||||||
if self.invert {
|
if self.invert {
|
||||||
rgb = (RGB::new(1.0, 1.0, 1.0) - rgb).clamp_zero();
|
rgb = (RGB::new(1.0, 1.0, 1.0) - rgb);
|
||||||
}
|
}
|
||||||
|
rgb = rgb.clamp_zero();
|
||||||
let cs = self
|
let cs = self
|
||||||
.color_space
|
.color_space
|
||||||
.get()
|
.get()
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ use crate::lights::sampler::create_light_sampler;
|
||||||
use crate::utils::parallel::{run_async, AsyncJob};
|
use crate::utils::parallel::{run_async, AsyncJob};
|
||||||
use crate::utils::parameters::{NamedTextures, ParameterDictionary, TextureParameterDictionary};
|
use crate::utils::parameters::{NamedTextures, ParameterDictionary, TextureParameterDictionary};
|
||||||
use crate::utils::resolve_filename;
|
use crate::utils::resolve_filename;
|
||||||
use crate::wavefront::{CreateWavefront, CpuAggregate, CpuWavefrontRenderer};
|
use crate::wavefront::{CpuAggregate, CpuWavefrontRenderer, CreateWavefront};
|
||||||
use crate::{Arena, ArenaUpload, FileLoc};
|
use crate::{Arena, ArenaUpload, FileLoc};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
|
@ -367,8 +367,8 @@ impl BasicScene {
|
||||||
let mut named = NamedTextures {
|
let mut named = NamedTextures {
|
||||||
float_textures: Arc::new(float_textures.clone()),
|
float_textures: Arc::new(float_textures.clone()),
|
||||||
albedo_spectrum_textures: Arc::new(spectrum_textures.clone()),
|
albedo_spectrum_textures: Arc::new(spectrum_textures.clone()),
|
||||||
illuminant_spectrum_textures: Arc::new(spectrum_textures.clone()),
|
illuminant_spectrum_textures: Arc::new(HashMap::new()),
|
||||||
unbounded_spectrum_textures: Arc::new(spectrum_textures.clone()),
|
unbounded_spectrum_textures: Arc::new(HashMap::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Serial float textures may reference already-loaded textures
|
// Serial float textures may reference already-loaded textures
|
||||||
|
|
@ -389,18 +389,25 @@ impl BasicScene {
|
||||||
|
|
||||||
for (name, entity) in state.serial_spectrum_textures.drain(..) {
|
for (name, entity) in state.serial_spectrum_textures.drain(..) {
|
||||||
let render_from_texture = entity.render_from_object.start_transform;
|
let render_from_texture = entity.render_from_object.start_transform;
|
||||||
let tex_dict =
|
let make = |st: SpectrumType, named: &NamedTextures, loc| {
|
||||||
TextureParameterDictionary::new(entity.base.parameters.into(), Some(&named));
|
let tex_dict = TextureParameterDictionary::new(
|
||||||
let tex = SpectrumTexture::create(
|
entity.base.parameters.clone().into(),
|
||||||
&entity.base.name,
|
Some(named),
|
||||||
render_from_texture,
|
);
|
||||||
tex_dict,
|
SpectrumTexture::create(
|
||||||
SpectrumType::Albedo,
|
&entity.base.name,
|
||||||
entity.base.loc,
|
render_from_texture,
|
||||||
arena,
|
tex_dict,
|
||||||
)
|
st,
|
||||||
.expect("Could not create spectrum texture");
|
loc,
|
||||||
Arc::make_mut(&mut named.albedo_spectrum_textures).insert(name, Arc::new(tex));
|
arena,
|
||||||
|
)
|
||||||
|
.expect("Could not create spectrum texture")
|
||||||
|
};
|
||||||
|
|
||||||
|
let albedo = make(SpectrumType::Albedo, &named, entity.base.loc.clone());
|
||||||
|
let unbounded = make(SpectrumType::Unbounded, &named, entity.base.loc.clone());
|
||||||
|
let illum = make(SpectrumType::Illuminant, &named, entity.base.loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
named
|
named
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,6 @@ impl CreateMaterial for ConductorMaterial {
|
||||||
remap_roughness,
|
remap_roughness,
|
||||||
);
|
);
|
||||||
|
|
||||||
arena.alloc(material);
|
|
||||||
Ok(Material::Conductor(material))
|
Ok(Material::Conductor(material))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ use crate::core::texture::{
|
||||||
SpectrumTextureTrait,
|
SpectrumTextureTrait,
|
||||||
};
|
};
|
||||||
use crate::utils::mipmap::{FilterFunction, MIPMap, MIPMapFilterOptions};
|
use crate::utils::mipmap::{FilterFunction, MIPMap, MIPMapFilterOptions};
|
||||||
use crate::utils::{FileLoc, TextureParameterDictionary, resolve_filename};
|
use crate::utils::{resolve_filename, FileLoc, TextureParameterDictionary};
|
||||||
use crate::{Arena};
|
use crate::Arena;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use shared::core::color::RGB;
|
use shared::core::color::RGB;
|
||||||
use shared::core::color::{ColorEncoding, SRGBEncoding};
|
use shared::core::color::{ColorEncoding, SRGBEncoding};
|
||||||
|
|
@ -143,7 +143,7 @@ impl SpectrumTextureTrait for SpectrumImageTexture {
|
||||||
return RGBUnboundedSpectrum::new(&cs, rgb).sample(lambda);
|
return RGBUnboundedSpectrum::new(&cs, rgb).sample(lambda);
|
||||||
}
|
}
|
||||||
SpectrumType::Albedo => {
|
SpectrumType::Albedo => {
|
||||||
return RGBAlbedoSpectrum::new(&cs, rgb).sample(lambda);
|
return RGBAlbedoSpectrum::new(&cs, rgb.clamp(0., 1.)).sample(lambda);
|
||||||
}
|
}
|
||||||
_ => return RGBIlluminantSpectrum::new(&cs, rgb).sample(lambda),
|
_ => return RGBIlluminantSpectrum::new(&cs, rgb).sample(lambda),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -907,6 +907,7 @@ impl TextureParameterDictionary {
|
||||||
if let Some(tex) = map.get(tex_name) {
|
if let Some(tex) = map.get(tex_name) {
|
||||||
return Some(Arc::clone(tex));
|
return Some(Arc::clone(tex));
|
||||||
}
|
}
|
||||||
|
|
||||||
panic!(
|
panic!(
|
||||||
"[{:?}] Couldn't find spectrum texture named '{}'",
|
"[{:?}] Couldn't find spectrum texture named '{}'",
|
||||||
p.loc, tex_name
|
p.loc, tex_name
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ use shared::core::interaction::InteractionTrait;
|
||||||
use shared::core::light::{Light, LightSampleContext, LightTrait};
|
use shared::core::light::{Light, LightSampleContext, LightTrait};
|
||||||
use shared::core::material::{MaterialEvalContext, MaterialTrait};
|
use shared::core::material::{MaterialEvalContext, MaterialTrait};
|
||||||
use shared::core::primitive::Primitive;
|
use shared::core::primitive::Primitive;
|
||||||
|
use shared::core::primitive::PrimitiveTrait;
|
||||||
use shared::core::sampler::{get_camera_sample, CameraSample, Sampler, SamplerTrait};
|
use shared::core::sampler::{get_camera_sample, CameraSample, Sampler, SamplerTrait};
|
||||||
use shared::core::texture::{BasicTextureEvaluator, TextureEvalContext, UniversalTextureEvaluator};
|
use shared::core::texture::{BasicTextureEvaluator, TextureEvalContext, UniversalTextureEvaluator};
|
||||||
use shared::lights::sampler::{LightSampler, LightSamplerTrait};
|
use shared::lights::sampler::{LightSampler, LightSamplerTrait};
|
||||||
|
|
@ -55,7 +56,7 @@ where
|
||||||
camera: Arc<Camera>,
|
camera: Arc<Camera>,
|
||||||
sampler: Arc<Sampler>,
|
sampler: Arc<Sampler>,
|
||||||
aggregate: Arc<Primitive>,
|
aggregate: Arc<Primitive>,
|
||||||
lights: Vec<Arc<Light>>,
|
mut lights: Vec<Arc<Light>>,
|
||||||
arena: &Arena,
|
arena: &Arena,
|
||||||
) -> CpuWavefrontRenderer {
|
) -> CpuWavefrontRenderer {
|
||||||
let max_depth = parameters
|
let max_depth = parameters
|
||||||
|
|
@ -84,6 +85,11 @@ where
|
||||||
|
|
||||||
let cpu_aggregate = CpuAggregate::new(*aggregate);
|
let cpu_aggregate = CpuAggregate::new(*aggregate);
|
||||||
|
|
||||||
|
let bounds = aggregate.bounds();
|
||||||
|
for light in &mut lights {
|
||||||
|
Arc::<Light>::make_mut(light).preprocess(&bounds);
|
||||||
|
}
|
||||||
|
|
||||||
CpuWavefrontRenderer(WavefrontPathIntegrator {
|
CpuWavefrontRenderer(WavefrontPathIntegrator {
|
||||||
aggregate: cpu_aggregate,
|
aggregate: cpu_aggregate,
|
||||||
camera: (*camera).clone(),
|
camera: (*camera).clone(),
|
||||||
|
|
@ -419,6 +425,33 @@ impl CpuWavefrontRenderer {
|
||||||
|
|
||||||
let lambda = w.lambda;
|
let lambda = w.lambda;
|
||||||
|
|
||||||
|
// DIAGNOSTIC: print image texture evaluate result for first few diffuse hits
|
||||||
|
{
|
||||||
|
use std::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
static DIAG_COUNT: AtomicU32 = AtomicU32::new(0);
|
||||||
|
if let shared::core::material::Material::Diffuse(dm) = material {
|
||||||
|
if !dm.reflectance.is_null() {
|
||||||
|
let cnt = DIAG_COUNT.fetch_add(1, Ordering::Relaxed);
|
||||||
|
if cnt < 5 {
|
||||||
|
let ref_tex = dm.reflectance.get().unwrap();
|
||||||
|
let val = ref_tex.evaluate(&ctx.texture, &lambda);
|
||||||
|
eprintln!(
|
||||||
|
"DIAG[{}] diffuse reflectance uv={:?} result={:?}",
|
||||||
|
cnt, w.uv, val
|
||||||
|
);
|
||||||
|
if let shared::core::texture::SpectrumTexture::Image(img_tex) = ref_tex
|
||||||
|
{
|
||||||
|
eprintln!(
|
||||||
|
" image_ptr_null={} scale={}",
|
||||||
|
img_tex.image.is_null(),
|
||||||
|
img_tex.scale
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut bsdf = if use_universal {
|
let mut bsdf = if use_universal {
|
||||||
material.get_bsdf(&UniversalTextureEvaluator, &ctx, &lambda)
|
material.get_bsdf(&UniversalTextureEvaluator, &ctx, &lambda)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue