Running tests on parsing

This commit is contained in:
Wito Wiala 2026-05-12 15:07:59 +01:00
parent c659ea0f44
commit c8d083df62
26 changed files with 827 additions and 663 deletions

1
.gitignore vendored
View file

@ -12,3 +12,4 @@ tests/
*.spv
*.json
*.txt
scenes/

View file

@ -1,7 +1,7 @@
use crate::core::pbrt::Float;
use crate::utils::math::{next_float_down, next_float_up};
use num_traits::Zero;
use core::ops::{Add, Div, Mul, Neg, Sub};
use num_traits::Zero;
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq)]

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -19,111 +19,79 @@ pub fn lookup_spectrum(s: &Spectrum) -> Arc<DenselySampledSpectrumBuffer> {
cache.lookup(dense_spectrum).into()
}
pub trait CreateLight {
fn create(
render_from_light: Transform,
medium: Medium,
parameters: &ParameterDictionary,
loc: &FileLoc,
shape: &Shape,
alpha_text: &FloatTexture,
colorspace: Option<&RGBColorSpace>,
arena: &Arena,
) -> Result<Light>;
// Placeholders for non-area lights that never inspect these arguments.
// TODO: refactor each light's create to only take what it actually needs,
// then delete these.
fn dummy_shape() -> Shape {
Shape::default()
}
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>,
camera_transform: CameraTransform,
) -> Result<Self>
where
Self: Sized;
fn dummy_alpha() -> FloatTexture {
FloatTexture::default()
}
impl LightFactory for Light {
fn create(
/// Create a non-area light from a scene file directive.
pub fn create_light(
name: &str,
arena: &mut Arena,
render_from_light: Transform,
medium: Medium,
medium: Option<Medium>,
parameters: &ParameterDictionary,
loc: &FileLoc,
shape: &Shape,
alpha_tex: &FloatTexture,
colorspace: Option<&RGBColorSpace>,
camera_transform: CameraTransform,
) -> Result<Self>
where
Self: Sized,
{
arena: &mut Arena,
) -> Result<Light> {
let shape = dummy_shape();
let alpha = dummy_alpha();
match name {
"diffuse" => DiffuseAreaLight::create(
"point" => crate::lights::point::create(
render_from_light,
medium,
parameters,
loc,
shape,
alpha_tex,
colorspace,
&shape,
&alpha,
None,
arena,
),
"point" => PointLight::create(
"spot" => crate::lights::spot::create(
render_from_light,
medium,
parameters,
loc,
shape,
alpha_tex,
colorspace,
&shape,
&alpha,
None,
arena,
),
"spot" => SpotLight::create(
"distant" => crate::lights::distant::create(
render_from_light,
medium,
parameters,
loc,
shape,
alpha_tex,
colorspace,
&shape,
&alpha,
None,
arena,
),
"goniometric" => GoniometricLight::create(
"goniometric" => crate::lights::goniometric::create(
render_from_light,
medium,
parameters,
loc,
shape,
alpha_tex,
colorspace,
&shape,
&alpha,
None,
arena,
),
"projection" => ProjectionLight::create(
"projection" => crate::lights::projection::create(
render_from_light,
medium,
parameters,
loc,
shape,
alpha_tex,
colorspace,
arena,
),
"distant" => DistantLight::create(
render_from_light,
medium,
parameters,
loc,
shape,
alpha_tex,
colorspace,
&shape,
&alpha,
None,
arena,
),
"infinite" => crate::lights::infinite::create(
@ -131,11 +99,38 @@ impl LightFactory for Light {
medium.into(),
camera_transform,
parameters,
colorspace,
None,
loc,
arena,
),
_ => Err(anyhow!("{}: unknown light type: \"{}\"", loc, name)),
}
"diffuse" => Err(anyhow!(
"{}: \"diffuse\" is an area light; use create_area_light with a shape",
loc
)),
_ => Err(anyhow!("{}: unknown light type \"{}\"", loc, name)),
}
}
/// Create a diffuse area light bound to a specific shape.
/// Called once per sub-shape (e.g. once per triangle in a mesh).
pub fn create_area_light(
render_from_light: Transform,
medium: Option<Medium>,
parameters: &ParameterDictionary,
loc: &FileLoc,
shape: &Shape,
alpha_tex: &FloatTexture,
colorspace: Option<&RGBColorSpace>,
arena: &mut Arena,
) -> Result<Light> {
crate::lights::diffuse::create(
render_from_light,
medium,
parameters,
loc,
shape,
alpha_tex,
colorspace,
arena,
)
}

View file

@ -39,7 +39,10 @@ impl MaterialFactory for Material {
named_materials: &HashMap<String, Material>,
loc: FileLoc,
arena: &Arena,
) -> Result<Self> where Self: Sized {
) -> Result<Self>
where
Self: Sized,
{
match name {
"diffuse" => {
DiffuseMaterial::create(parameters, normal_map, named_materials, &loc, arena)

View file

@ -641,7 +641,7 @@ impl ParserTarget for BasicSceneBuilder {
arena: Arc<Arena>,
) -> Result<(), ParserError> {
let name = normalize_utf8(orig_name);
self.verify_world("Texture", &loc);
self.verify_world("Texture", &loc)?;
let dict = ParameterDictionary::from_array(
params.clone(),
&self.graphics_state.texture_attributes,
@ -701,7 +701,7 @@ impl ParserTarget for BasicSceneBuilder {
params: ParsedParameterVector,
loc: FileLoc,
) -> Result<(), ParserError> {
self.verify_world("material", &loc);
self.verify_world("material", &loc)?;
let entity = SceneEntity {
name: name.to_string(),
loc,
@ -733,7 +733,7 @@ impl ParserTarget for BasicSceneBuilder {
let dict = ParameterDictionary::from_array(
params.clone(),
&self.graphics_state.medium_attributes,
self.graphics_state.color_space.clone()
self.graphics_state.color_space.clone(),
)?;
let render_from_light = AnimatedTransform::new(
@ -757,7 +757,6 @@ impl ParserTarget for BasicSceneBuilder {
self.scene.add_light(entity);
Ok(())
}
fn area_light_source(
@ -786,7 +785,7 @@ impl ParserTarget for BasicSceneBuilder {
let dict = ParameterDictionary::from_array(
params.clone(),
&self.graphics_state.shape_attributes,
self.graphics_state.color_space.clone()
self.graphics_state.color_space.clone(),
)?;
let render_from_object = self.graphics_state.ctm[0];
@ -797,7 +796,7 @@ impl ParserTarget for BasicSceneBuilder {
let light_entity = SceneEntity {
name: al.name.clone(),
loc: al.loc.clone(),
parameters: al_dict
parameters: al_dict,
};
Some(self.scene.add_area_light(light_entity))
} else {
@ -816,7 +815,7 @@ impl ParserTarget for BasicSceneBuilder {
base: SceneEntity {
name: name.to_string(),
loc,
parameters: dict
parameters: dict,
},
render_from_object: Arc::new(render_from_object),
object_from_render: Arc::new(object_from_render),
@ -828,7 +827,11 @@ impl ParserTarget for BasicSceneBuilder {
};
if self.active_instance_definition.is_some() {
self.active_instance_definition.as_mut().unwrap().shapes.push(entity)
self.active_instance_definition
.as_mut()
.unwrap()
.shapes
.push(entity)
} else {
self.scene.add_shape(entity);
}

View file

@ -1,9 +1,11 @@
mod builder;
mod entities;
mod scene;
mod state;
pub mod builder;
pub mod entities;
pub mod scene;
pub mod state;
pub use builder::BasicSceneBuilder;
pub use entities::*;
pub use scene::{BasicScene, SceneLookup};
pub use state::*;

View file

@ -4,7 +4,6 @@ use crate::core::camera::CameraFactory;
use crate::core::film::FilmFactory;
use crate::core::filter::FilterFactory;
use crate::core::image::{Image, io::ImageIO};
use crate::core::light::LightFactory;
use crate::core::material::MaterialFactory;
use crate::core::primitive::{CreateGeometricPrimitive, CreateSimplePrimitive};
use crate::core::sampler::SamplerFactory;
@ -17,7 +16,7 @@ use crate::{Arena, FileLoc};
use anyhow::{Result, anyhow};
use parking_lot::Mutex;
use rayon::prelude::*;
use shared::core::camera::{CameraTransform, Camera};
use shared::core::camera::{Camera, CameraTransform};
use shared::core::color::LINEAR;
use shared::core::film::Film;
use shared::core::filter::Filter;
@ -502,26 +501,114 @@ impl BasicScene {
&self,
camera_transform: &CameraTransform,
arena: &mut Arena,
) -> Result<Vec<Light>> {
) -> Vec<Light> {
let state = self.light_state.lock();
state.lights.par_iter().map(|entity| {
state
.lights
.iter()
.filter_map(|entity| {
let render_from_light = entity.transformed_base.render_from_object.start_transform;
let medium = self.get_medium(
&entity.medium,
let medium = self
.get_medium(&entity.medium, &entity.transformed_base.base.loc)
.map(|m| *m);
match crate::core::light::create_light(
&entity.transformed_base.base.name,
render_from_light,
medium,
&entity.transformed_base.base.parameters,
&entity.transformed_base.base.loc,
camera_transform.clone(),
arena,
) {
Ok(light) => Some(light),
Err(e) => {
log::error!(
"{}: failed to create light: {}",
entity.transformed_base.base.loc,
e
);
None
}
}
})
.collect()
}
/// Create area lights for shapes that reference one. Produces a map from
/// shape index to a vec of lights (one per sub-shape, e.g. per triangle).
/// Must be called after shapes are loaded but before upload_shapes.
pub fn create_area_lights(
&self,
loaded_shapes: &[Vec<Shape>],
shape_entities: &[ShapeSceneEntity],
textures: &NamedTextures,
arena: &mut Arena,
) -> HashMap<usize, Vec<Light>> {
let light_state = self.light_state.lock();
let mut shape_lights: HashMap<usize, Vec<Light>> = HashMap::new();
for (i, entity) in shape_entities.iter().enumerate() {
let light_idx = match entity.light_index {
Some(idx) => idx,
None => continue,
};
let shapes = match loaded_shapes.get(i) {
Some(s) if !s.is_empty() => s,
_ => continue,
};
let al_entity = &light_state.area_lights[light_idx];
let alpha_tex = self.get_alpha_texture(
&entity.base.parameters,
&entity.base.loc,
&textures.float_textures,
);
Light::create(
&entity.transformed_base.base.name,
&entity.transformed_base.base.parameters,
// Use the film colorspace as fallback for area light emission
let film_cs = self.film_colorspace.lock();
let colorspace_ref = al_entity
.parameters
.color_space
.as_ref()
.or(film_cs.as_ref());
let render_from_light = *entity.render_from_object;
let lights: Vec<Light> = shapes
.iter()
.filter_map(|shape| {
match crate::core::light::create_area_light(
render_from_light,
camera_transform,
medium.map(|m| *m),
&entity.transformed_base.base.loc,
None,
&al_entity.parameters,
&al_entity.loc,
shape,
alpha_tex
.as_ref()
.expect("Alpha texture required for area light"),
colorspace_ref.map(|cs| cs.as_ref()),
arena,
)
}).collect()
) {
Ok(light) => Some(light),
Err(e) => {
log::error!("{}: failed to create area light: {}", al_entity.loc, e);
None
}
}
})
.collect();
if !lights.is_empty() {
shape_lights.insert(i, lights);
}
}
shape_lights
}
pub fn create_aggregate(

View file

@ -1,4 +1,4 @@
use super::{SceneEntity, TextureSceneEntity, LightSceneEntity};
use super::{LightSceneEntity, SceneEntity, TextureSceneEntity};
use crate::core::image::Image;
use crate::core::texture::{FloatTexture, SpectrumTexture};
use crate::utils::parallel::AsyncJob;

View file

@ -45,6 +45,12 @@ pub enum FloatTexture {
Wrinkled(WrinkledTexture),
}
impl Default for FloatTexture {
fn default() -> Self {
FloatTexture::Constant(FloatConstantTexture::new(1.0))
}
}
impl FloatTextureTrait for Arc<FloatTexture> {
fn evaluate(&self, ctx: &TextureEvalContext) -> Float {
self.as_ref().evaluate(ctx)

View file

@ -1,7 +1,8 @@
use super::*;
use crate::Arena;
use crate::core::film::{CreateFilmBase, PixelSensor};
use crate::utils::containers::Array2D;
use std::sync::Arc;
use crate::Arena;
use anyhow::Result;
use shared::core::camera::CameraTransform;
use shared::core::film::{Film, FilmBase, RGBFilm, RGBPixel};
@ -69,7 +70,10 @@ impl CreateFilm for RGBFilm {
loc: &FileLoc,
_arena: &Arena,
) -> Result<Film> {
let colorspace = params.color_space.as_ref().unwrap();
let colorspace = params.color_space.as_ref().cloned().unwrap_or_else(|| {
let stdcs = crate::spectra::get_colorspace_device();
Arc::new(*stdcs.srgb)
});
let max_component_value = params.get_one_float("maxcomponentvalue", Float::INFINITY)?;
let write_fp16 = params.get_one_bool("savefp16", true)?;
let sensor = PixelSensor::create(params, colorspace.clone(), exposure_time, loc)?;

View file

@ -23,20 +23,52 @@ pub static UC_RHO: [Float; N_RHO_SAMPLES] = [
];
pub static U_RHO: [Point2f; N_RHO_SAMPLES] = [
Point2f { 0: [0.855985, 0.570367]},
Point2f { 0: [0.381823, 0.851844]},
Point2f { 0: [0.285328, 0.764262]},
Point2f { 0: [0.733380, 0.114073]},
Point2f { 0: [0.542663, 0.344465]},
Point2f { 0: [0.127274, 0.414848]},
Point2f { 0: [0.964700, 0.947162]},
Point2f { 0: [0.594089, 0.643463]},
Point2f { 0: [0.095109, 0.170369]},
Point2f { 0: [0.825444, 0.263359]},
Point2f { 0: [0.429467, 0.454469]},
Point2f { 0: [0.244460, 0.816459]},
Point2f { 0: [0.756135, 0.731258]},
Point2f { 0: [0.516165, 0.152852]},
Point2f { 0: [0.180888, 0.214174]},
Point2f { 0: [0.898579, 0.503897]},
Point2f {
0: [0.855985, 0.570367],
},
Point2f {
0: [0.381823, 0.851844],
},
Point2f {
0: [0.285328, 0.764262],
},
Point2f {
0: [0.733380, 0.114073],
},
Point2f {
0: [0.542663, 0.344465],
},
Point2f {
0: [0.127274, 0.414848],
},
Point2f {
0: [0.964700, 0.947162],
},
Point2f {
0: [0.594089, 0.643463],
},
Point2f {
0: [0.095109, 0.170369],
},
Point2f {
0: [0.825444, 0.263359],
},
Point2f {
0: [0.429467, 0.454469],
},
Point2f {
0: [0.244460, 0.816459],
},
Point2f {
0: [0.756135, 0.731258],
},
Point2f {
0: [0.516165, 0.152852],
},
Point2f {
0: [0.180888, 0.214174],
},
Point2f {
0: [0.898579, 0.503897],
},
];

View file

@ -1,10 +1,10 @@
use super::RayIntegratorTrait;
use super::base::IntegratorBase;
use super::constants::*;
use super::state::PathState;
use super::RayIntegratorTrait;
use crate::core::interaction::InteractionGetter;
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::camera::Camera;
use shared::core::film::VisibleSurface;

View file

@ -1,14 +1,14 @@
use std::path::Path;
use crate::core::image::{Image, ImageIO};
use crate::core::light::{CreateLight, lookup_spectrum};
use crate::core::light::lookup_spectrum;
use crate::core::spectrum::spectrum_to_photometric;
use crate::core::texture::FloatTexture;
use crate::utils::{Arena, FileLoc, ParameterDictionary, Upload, resolve_filename};
use anyhow::{Result, anyhow};
use shared::core::geometry::Point2i;
use shared::core::light::{Light, LightBase, LightType};
use shared::core::medium::Medium;
use shared::core::medium::{Medium, MediumInterface};
use shared::core::shape::{Shape, ShapeTrait};
use shared::core::spectrum::Spectrum;
use shared::core::texture::GPUFloatTexture;
@ -18,17 +18,16 @@ use shared::spectra::RGBColorSpace;
use shared::utils::{Ptr, Transform};
use shared::{Float, PI};
impl CreateLight for DiffuseAreaLight {
fn create(
pub fn create(
render_from_light: Transform,
medium: Medium,
medium: Option<Medium>,
params: &ParameterDictionary,
loc: &FileLoc,
shape: &Shape,
alpha: &FloatTexture,
colorspace: Option<&RGBColorSpace>,
arena: &Arena,
) -> Result<Light> {
) -> Result<Light> {
let mut l = params.get_one_spectrum("l", None, SpectrumType::Illuminant);
let illum_spec = Spectrum::Dense(colorspace.unwrap().illuminant);
let mut scale = params.get_one_float("scale", 1.)?;
@ -115,7 +114,18 @@ impl CreateLight for DiffuseAreaLight {
(LightType::Area, Some(alpha))
};
let base = LightBase::new(light_type, render_from_light, medium.into());
let mi = match medium {
Some(m) => {
let ptr = arena.alloc(m);
MediumInterface {
inside: ptr,
outside: ptr,
}
}
None => MediumInterface::default(),
};
let base = LightBase::new(light_type, render_from_light, mi);
if let Some(ref img) = image {
let desc = img
.get_channel_desc(&["R", "G", "B"])
@ -128,8 +138,7 @@ impl CreateLight for DiffuseAreaLight {
);
}
let is_triangle_or_bilinear =
matches!(*shape, Shape::Triangle(_) | Shape::BilinearPatch(_));
let is_triangle_or_bilinear = matches!(*shape, Shape::Triangle(_) | Shape::BilinearPatch(_));
if render_from_light.has_scale(None) && !is_triangle_or_bilinear {
println!(
"Scaling detected in rendering to light space transformation! \
@ -160,5 +169,4 @@ impl CreateLight for DiffuseAreaLight {
};
Ok(Light::DiffuseArea(specific))
}
}

View file

@ -1,4 +1,4 @@
use crate::core::light::{CreateLight, lookup_spectrum};
use crate::core::light::lookup_spectrum;
use crate::core::spectrum::spectrum_to_photometric;
use crate::core::texture::FloatTexture;
use crate::utils::{Arena, FileLoc, ParameterDictionary};
@ -36,17 +36,16 @@ impl CreateDistantLight for DistantLight {
}
}
impl CreateLight for DistantLight {
fn create(
pub fn create(
render_from_light: Transform,
_medium: Medium,
_medium: Option<Medium>,
parameters: &ParameterDictionary,
_loc: &FileLoc,
_shape: &Shape,
_alpha_text: &FloatTexture,
colorspace: Option<&RGBColorSpace>,
_arena: &Arena,
) -> Result<Light> {
) -> Result<Light> {
let l = parameters
.get_one_spectrum(
"L",
@ -90,5 +89,4 @@ impl CreateLight for DistantLight {
let specific = DistantLight::new(final_render, l, scale);
Ok(Light::Distant(specific))
}
}

View file

@ -1,7 +1,7 @@
use std::path::Path;
use crate::core::image::{Image, ImageIO};
use crate::core::light::{CreateLight, lookup_spectrum};
use crate::core::light::lookup_spectrum;
use crate::core::spectrum::spectrum_to_photometric;
use crate::core::texture::FloatTexture;
use crate::utils::sampling::PiecewiseConstant2D;
@ -9,7 +9,7 @@ use crate::utils::{Arena, FileLoc, ParameterDictionary, Upload, resolve_filename
use anyhow::{Result, anyhow};
use shared::core::geometry::Point2i;
use shared::core::light::{Light, LightBase, LightType};
use shared::core::medium::Medium;
use shared::core::medium::{Medium, MediumInterface};
use shared::core::shape::Shape;
use shared::core::spectrum::Spectrum;
use shared::core::texture::SpectrumType;
@ -18,17 +18,16 @@ use shared::spectra::RGBColorSpace;
use shared::utils::{Ptr, Transform};
use shared::{Float, PI};
impl CreateLight for GoniometricLight {
fn create(
pub fn create(
render_from_light: Transform,
medium: Medium,
medium: Option<Medium>,
params: &ParameterDictionary,
loc: &FileLoc,
_shape: &Shape,
_alpha_text: &FloatTexture,
colorspace: Option<&RGBColorSpace>,
arena: &Arena,
) -> Result<Light> {
) -> Result<Light> {
let i = params
.get_one_spectrum(
"I",
@ -76,15 +75,21 @@ impl CreateLight for GoniometricLight {
let swap_yz: [Float; 16] = [
1., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 0., 1.,
];
let t = Transform::from_flat(&swap_yz)
.expect("Could not create transform for GoniometricLight");
let t =
Transform::from_flat(&swap_yz).expect("Could not create transform for GoniometricLight");
let final_render_from_light = render_from_light * t;
let base = LightBase::new(
LightType::DeltaPosition,
final_render_from_light,
medium.into(),
);
let mi = match medium {
Some(m) => {
let ptr = arena.alloc(m);
MediumInterface {
inside: ptr,
outside: ptr,
}
}
None => MediumInterface::default(),
};
let base = LightBase::new(LightType::DeltaPosition, render_from_light, mi);
let iemit = lookup_spectrum(&i);
@ -106,7 +111,6 @@ impl CreateLight for GoniometricLight {
};
Ok(Light::Goniometric(specific))
}
}
fn convert_to_luminance_image(image: &Image, filename: &str, loc: &FileLoc) -> Result<Image> {

View file

@ -11,7 +11,7 @@ use shared::core::camera::CameraTransform;
use shared::core::geometry::{Bounds2f, Frame, Point2f, Point2i, Point3f, VectorLike, cos_theta};
use shared::core::image::{DeviceImage, WrapMode};
use shared::core::light::{Light, LightBase, LightType};
use shared::core::medium::MediumInterface;
use shared::core::medium::{Medium, MediumInterface};
use shared::core::spectrum::Spectrum;
use shared::core::texture::SpectrumType;
use shared::lights::{ImageInfiniteLight, PortalInfiniteLight, UniformInfiniteLight};
@ -124,7 +124,7 @@ impl CreateUniformInfiniteLight for UniformInfiniteLight {
pub fn create(
render_from_light: Transform,
_medium: MediumInterface,
_medium: Option<Medium>,
camera_transform: CameraTransform,
parameters: &ParameterDictionary,
colorspace: Option<&RGBColorSpace>,

View file

@ -1,4 +1,4 @@
use crate::core::light::{CreateLight, lookup_spectrum};
use crate::core::light::lookup_spectrum;
use crate::core::spectrum::spectrum_to_photometric;
use crate::core::texture::FloatTexture;
use crate::utils::{Arena, FileLoc, ParameterDictionary};
@ -42,17 +42,16 @@ impl CreatePointLight for PointLight {
}
}
impl CreateLight for PointLight {
fn create(
pub fn create(
render_from_light: Transform,
medium: Medium,
medium: Option<Medium>,
parameters: &ParameterDictionary,
_loc: &FileLoc,
_shape: &Shape,
_alpha: &FloatTexture,
colorspace: Option<&RGBColorSpace>,
_arena: &Arena,
) -> Result<Light> {
arena: &Arena,
) -> Result<Light> {
let l = parameters
.get_one_spectrum(
"L",
@ -71,7 +70,18 @@ impl CreateLight for PointLight {
let from = parameters.get_one_point3f("from", Point3f::zero())?;
let tf = Transform::translate(from.into());
let final_render = render_from_light * tf;
let specific = PointLight::new(final_render, medium.into(), l, scale);
Ok(Light::Point(specific))
let mi = match medium {
Some(m) => {
let ptr = arena.alloc(m);
MediumInterface {
inside: ptr,
outside: ptr,
}
}
None => MediumInterface::default(),
};
let specific = PointLight::new(final_render, mi, l, scale);
Ok(Light::Point(specific))
}

View file

@ -1,5 +1,4 @@
use crate::core::image::{Image, ImageIO};
use crate::core::light::CreateLight;
use crate::core::spectrum::spectrum_to_photometric;
use crate::core::texture::FloatTexture;
use crate::utils::sampling::PiecewiseConstant2D;
@ -10,7 +9,7 @@ use shared::core::geometry::{
Bounds2f, Point2f, Point2i, Point3f, Vector3f, VectorLike, cos_theta,
};
use shared::core::light::{Light, LightBase, LightType};
use shared::core::medium::Medium;
use shared::core::medium::{Medium, MediumInterface};
use shared::core::shape::Shape;
use shared::core::spectrum::Spectrum;
use shared::lights::ProjectionLight;
@ -19,17 +18,16 @@ use shared::utils::Transform;
use shared::utils::math::{radians, square};
use std::path::Path;
impl CreateLight for ProjectionLight {
fn create(
pub fn create(
render_from_light: Transform,
medium: Medium,
medium: Option<Medium>,
parameters: &ParameterDictionary,
loc: &FileLoc,
_shape: &Shape,
_alpha_text: &FloatTexture,
_colorspace: Option<&RGBColorSpace>,
arena: &Arena,
) -> Result<Light> {
) -> Result<Light> {
let mut scale = parameters.get_one_float("scale", 1.)?;
let power = parameters.get_one_float("power", -1.)?;
let fov = parameters.get_one_float("fov", 90.)?;
@ -81,7 +79,17 @@ impl CreateLight for ProjectionLight {
let flip = Transform::scale(1., -1., 1.);
let render_from_light_flip = render_from_light * flip;
let base = LightBase::new(LightType::DeltaPosition, render_from_light, medium.into());
let mi = match medium {
Some(m) => {
let ptr = arena.alloc(m);
MediumInterface {
inside: ptr,
outside: ptr,
}
}
None => MediumInterface::default(),
};
let base = LightBase::new(LightType::DeltaPosition, render_from_light, mi);
let opposite = (radians(fov) / 2.0).tan();
let res = image.resolution();
@ -102,8 +110,7 @@ impl CreateLight for ProjectionLight {
let light_from_screen = screen_from_light.inverse();
let dwda = |p: Point2f| {
let w =
Vector3f::from(light_from_screen.apply_to_point(Point3f::new(p.x(), p.y(), 0.0)));
let w = Vector3f::from(light_from_screen.apply_to_point(Point3f::new(p.x(), p.y(), 0.0)));
cos_theta(w.normalize()).powi(3)
};
@ -129,7 +136,6 @@ impl CreateLight for ProjectionLight {
};
Ok(Light::Projection(specific))
}
}
fn compute_screen_bounds(aspect: Float) -> Bounds2f {

View file

@ -1,4 +1,4 @@
use crate::core::light::{CreateLight, lookup_spectrum};
use crate::core::light::lookup_spectrum;
use crate::core::spectrum::spectrum_to_photometric;
use crate::core::texture::FloatTexture;
use crate::utils::{Arena, FileLoc, ParameterDictionary};
@ -53,17 +53,16 @@ impl CreateSpotLight for SpotLight {
}
}
impl CreateLight for SpotLight {
fn create(
pub fn create(
render_from_light: Transform,
medium: Medium,
medium: Option<Medium>,
parameters: &ParameterDictionary,
_loc: &FileLoc,
_shape: &Shape,
_alpha_tex: &FloatTexture,
colorspace: Option<&RGBColorSpace>,
arena: &Arena,
) -> Result<Light> {
) -> Result<Light> {
let i = parameters
.get_one_spectrum(
"I",
@ -85,20 +84,22 @@ impl CreateLight for SpotLight {
if phi_v > 0. {
let cos_falloff_end = radians(coneangle).cos();
let cos_falloff_start = radians(coneangle - conedelta).cos();
let k_e =
2. * PI * ((1. - cos_falloff_start) + (cos_falloff_start - cos_falloff_end) / 2.);
let k_e = 2. * PI * ((1. - cos_falloff_start) + (cos_falloff_start - cos_falloff_end) / 2.);
scale *= phi_v / k_e;
}
let specific = SpotLight::new(
final_render,
medium.into(),
i,
scale,
coneangle,
coneangle - conedelta,
);
let mi = match medium {
Some(m) => {
let ptr = arena.alloc(m);
MediumInterface {
inside: ptr,
outside: ptr,
}
}
None => MediumInterface::default(),
};
let specific = SpotLight::new(final_render, mi, i, scale, coneangle, coneangle - conedelta);
arena.alloc(specific);
Ok(Light::Spot(specific))
}
}

View file

@ -0,0 +1 @@

View file

@ -45,11 +45,7 @@ impl CreateSpectrumTexture for SpectrumBilerpTexture {
}
impl SpectrumTextureTrait for SpectrumBilerpTexture {
fn evaluate(
&self,
_ctx: &TextureEvalContext,
_lambda: &SampledWavelengths,
) -> SampledSpectrum {
fn evaluate(&self, _ctx: &TextureEvalContext, _lambda: &SampledWavelengths) -> SampledSpectrum {
todo!()
}
}

View file

@ -0,0 +1 @@

View file

@ -3,8 +3,7 @@ use crate::core::texture::{FloatTexture, SpectrumTexture};
use crate::spectra::data::get_named_spectrum;
use crate::spectra::piecewise::PiecewiseLinearSpectrumBuffer;
use crate::utils::FileLoc;
use anyhow::{Result, bail};
use shared::Float;
use anyhow::{bail, Result};
use shared::core::color::RGB;
use shared::core::geometry::{Normal3f, Point2f, Point3f, Vector2f, Vector3f};
use shared::core::spectrum::Spectrum;
@ -13,11 +12,12 @@ use shared::spectra::{
PiecewiseLinearSpectrum, RGBAlbedoSpectrum, RGBColorSpace, RGBIlluminantSpectrum,
RGBUnboundedSpectrum,
};
use shared::Float;
use std::collections::HashMap;
use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
Arc,
};
pub fn error_exit(loc: Option<&FileLoc>, message: &str) -> String {
@ -350,9 +350,9 @@ impl ParameterDictionary {
where
T: PBRTParameter,
{
let param = self.params[0].clone();
for param in &self.params {
if param.name == name && param.type_name == T::TYPE_NAME {
let values = T::get_values(&param);
let values = T::get_values(param);
if values.is_empty() {
bail!(
@ -375,6 +375,7 @@ impl ParameterDictionary {
param.looked_up.store(true, Ordering::Relaxed);
return Ok(T::convert(values));
}
}
Ok(default_val)
}

View file

@ -385,6 +385,7 @@ impl Tokenizer {
if first_char == '"' {
self.advance();
let mut val = String::new();
val.push('"');
loop {
let ch = self.advance().ok_or(ParserError::UnexpectedEof)?;
@ -406,6 +407,8 @@ impl Tokenizer {
val.push(ch);
}
}
val.push('"');
return Ok(Some(Token {
text: val,
loc: start_loc,